Skip to content

Commit

Permalink
fix fall damages
Browse files Browse the repository at this point in the history
  • Loading branch information
IAFEnvoy committed Jan 9, 2025
1 parent 794ddf6 commit bc5d786
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -37,4 +38,11 @@ public static void place(World world, BlockPos pos, BlockState state, int tick)
blockEntity.setState(s);
}
}

@Override
public void onLandedUpon(World world, BlockState state, BlockPos pos, Entity entity, float fallDistance) {
if (this.getJumpVelocityMultiplier() > 2)
entity.handleFallDamage(fallDistance, 0, world.getDamageSources().fall());
else super.onLandedUpon(world, state, pos, entity, fallDistance);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import com.iafenvoy.sow.power.SongPowerData;
import com.iafenvoy.sow.registry.power.MobiliumPowers;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -31,12 +31,13 @@ private void handleFallFlyingCheck(CallbackInfo ci) {
}

@SuppressWarnings("all")
@ModifyExpressionValue(method = "travel", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;hasStatusEffect(Lnet/minecraft/entity/effect/StatusEffect;)Z", ordinal = 0))
private boolean handleSlideSpeed(boolean original) {
@Inject(method = "tick", at = @At("RETURN"))
private void endTick(CallbackInfo ci) {
if (this.isRemoved() || this.hasNoGravity()) return;
if ((Object) this instanceof PlayerEntity player && SongPowerData.byPlayer(player).powerEnabled(MobiliumPowers.MOBILIGLIDE)) {
Vec3d velocity = this.getVelocity();
this.setVelocity(velocity.x, 0.01 / 4.0, velocity.z);
this.fallDistance = 0;
return true;
}
return original;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ public void removeComponent(String id) {
this.components.remove(id);
}

public boolean powerEnabled(AbstractSongPower<?> power) {
return this.powerEnabled(power.getCategory(), power);
public boolean powerEnabled(AbstractSongPower<?>... powers) {
for (AbstractSongPower<?> power : powers)
if (this.powerEnabled(power.getCategory(), power))
return true;
return false;
}

public boolean powerEnabled(PowerCategory category, AbstractSongPower<?> power) {
Expand Down

0 comments on commit bc5d786

Please sign in to comment.