Skip to content

Commit

Permalink
Move fall damage prevention to Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Jun 8, 2023
1 parent 77533b3 commit 48ecdbb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
15 changes: 15 additions & 0 deletions src/main/java/com/fusionflux/portalcubed/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.fusionflux.portalcubed.entity.EntityAttachments;
import com.fusionflux.portalcubed.entity.ExperimentalPortal;
import com.fusionflux.portalcubed.entity.GelBlobEntity;
import com.fusionflux.portalcubed.items.PortalCubedItems;
import com.fusionflux.portalcubed.listeners.WentThroughPortalListener;
import com.fusionflux.portalcubed.mechanics.CrossPortalInteraction;
import com.fusionflux.portalcubed.util.IPQuaternion;
Expand All @@ -22,9 +23,12 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -46,6 +50,7 @@
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -532,4 +537,14 @@ public void setCFG() {
// final Vec3 newPos = PortalDirectionUtils.simpleTransformPassingVector((Entity)(Object)this, getPosition(tickDelta), original);
// return newPos != null ? newPos : original;
// }

@Inject(method = "isInvulnerableTo", at = @At("HEAD"), cancellable = true)
public void portalCubed$letYouFallLonger(DamageSource damageSource, CallbackInfoReturnable<Boolean> cir) {
//noinspection ConstantValue
if (!((Object)this instanceof LivingEntity living)) return;
ItemStack stack = living.getItemBySlot(EquipmentSlot.FEET);
if (damageSource == DamageSource.FALL && (stack.is(PortalCubedItems.LONG_FALL_BOOTS))) {
cir.setReturnValue(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
Expand Down Expand Up @@ -77,13 +76,6 @@ protected PlayerMixin(EntityType<? extends LivingEntity> entityType, Level world
@Override
@Shadow public abstract float getSpeed();

@Inject(method = "isInvulnerableTo", at = @At("HEAD"), cancellable = true)
public void portalCubed$letYouFallLonger(DamageSource damageSource, CallbackInfoReturnable<Boolean> cir) {
ItemStack itemStack5 = this.getItemBySlot(EquipmentSlot.FEET);
if (damageSource == DamageSource.FALL && (itemStack5.is(PortalCubedItems.LONG_FALL_BOOTS))) {
cir.setReturnValue(true);
}
}
@ModifyVariable(method = "travel", at = @At("HEAD"), argsOnly = true)
private Vec3 portalCubed$what(Vec3 travelVectorOriginal) {
if (!this.isNoGravity()) {
Expand Down

0 comments on commit 48ecdbb

Please sign in to comment.