Skip to content

Commit

Permalink
refactor: rewrote mixin which was injecting at HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
Roelymole committed Jan 31, 2025
1 parent 33919bb commit 5eba684
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/main/java/dev/galacticraft/mod/mixin/LivingEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;

@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin extends Entity implements CryogenicAccessor {
Expand Down Expand Up @@ -128,16 +129,21 @@ public void setCryogenicChamberCooldown(int cryogenicChamberCooldown) {
ci.cancel();
}

@Inject(method = "calculateFallDamage", at = @At(value = "HEAD"), cancellable = true)
protected void calculateFallDamage(float f, float f2, CallbackInfoReturnable<Integer> cir) {
if (this.getType().is(EntityTypeTags.FALL_DAMAGE_IMMUNE)) {
cir.setReturnValue(0);
return;
@ModifyReturnValue(method = "getAttributeValue", at = @At(value = "RETURN"))
protected double adjustSafeFallDistance(double original, Holder<Attribute> attribute) {
if (attribute == Attributes.SAFE_FALL_DISTANCE) {
Holder<CelestialBody<?, ?>> holder = this.level().galacticraft$getCelestialBody();
if (holder != null) {
double gravity = holder.value().gravity();
return gravity > 0 ? original / gravity : original;
}
}
return original;
}

@ModifyArg(method = "calculateFallDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;ceil(D)I"), index = 0)
protected double scaleFallDamage(double original) {
Holder<CelestialBody<?, ?>> holder = this.level().galacticraft$getCelestialBody();
float gravity = (float)(holder != null ? holder.value().gravity() : 1.0d);
float f3 = (float)this.getAttributeValue(Attributes.SAFE_FALL_DISTANCE);
float f4 = f - f3 / gravity;
cir.setReturnValue(Mth.ceil((double)(f4 * f2 * gravity) * this.getAttributeValue(Attributes.FALL_DAMAGE_MULTIPLIER)));
return holder != null ? original * holder.value().gravity() : original;
}
}

0 comments on commit 5eba684

Please sign in to comment.