~vpzom/falldeathfix

3caa94e96e35b19751de201169206d28cac78c6a — Colin Reeder 3 months ago 792aef1
Add fix for condition for water accident fall
A src/main/java/click/vpzom/mods/falldeathfix/EntityDuck.java => src/main/java/click/vpzom/mods/falldeathfix/EntityDuck.java +5 -0
@@ 0,0 1,5 @@
package click.vpzom.mods.falldeathfix;

public interface EntityDuck {
    boolean wasTouchingWater();
}

M src/main/java/click/vpzom/mods/falldeathfix/mixin/DamageTrackerMixin.java => src/main/java/click/vpzom/mods/falldeathfix/mixin/DamageTrackerMixin.java +6 -0
@@ 1,5 1,6 @@
package click.vpzom.mods.falldeathfix.mixin;

import click.vpzom.mods.falldeathfix.EntityDuck;
import com.google.common.collect.Lists;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;


@@ 105,4 106,9 @@ public class DamageTrackerMixin {
    public boolean isAliveButActuallyJustTrue(LivingEntity self) {
        return true;
    }

    @Redirect(method = "setFallDeathSuffix", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;isTouchingWater()Z"))
    public boolean isTouchingWaterButActuallyWas(LivingEntity self) {
        return ((EntityDuck) self).wasTouchingWater();
    }
}

A src/main/java/click/vpzom/mods/falldeathfix/mixin/EntityMixin.java => src/main/java/click/vpzom/mods/falldeathfix/mixin/EntityMixin.java +32 -0
@@ 0,0 1,32 @@
package click.vpzom.mods.falldeathfix.mixin;

import click.vpzom.mods.falldeathfix.EntityDuck;
import net.minecraft.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(Entity.class)
public class EntityMixin implements EntityDuck {
    private boolean wasTouchingWater;

    @Shadow
    private boolean touchingWater;

    @Inject(method = "checkWaterState", at = @At("TAIL"))
    private void onCheckWaterState(CallbackInfo ci) {
        if(touchingWater) wasTouchingWater = true;
    }

    @Inject(method = "setOnGround", at = @At("TAIL"))
    private void onSetOnGround(boolean onGround, CallbackInfo ci) {
        if(onGround) wasTouchingWater = false;
    }

    @Override
    public boolean wasTouchingWater() {
        return wasTouchingWater;
    }
}

M src/main/resources/falldeathfix.mixins.json => src/main/resources/falldeathfix.mixins.json +1 -1
@@ 5,5 5,5 @@
	"injectors": {
		"defaultRequire": 1
	},
	"mixins": ["DamageTrackerMixin"]
	"mixins": ["DamageTrackerMixin", "EntityMixin"]
}