31 lines
1.3 KiB
Java
31 lines
1.3 KiB
Java
package io.gitlab.jfronny.combit.mixin;
|
|
|
|
import io.gitlab.jfronny.combit.events.EntityHurtEvent;
|
|
import io.gitlab.jfronny.combit.events.EntityKnockbackEvent;
|
|
import net.minecraft.entity.LivingEntity;
|
|
import net.minecraft.entity.damage.DamageSource;
|
|
import net.minecraft.util.ActionResult;
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
|
|
@Mixin(LivingEntity.class)
|
|
public class LivingEntityMixin {
|
|
@Inject(at = @At("TAIL"), method = "applyDamage", cancellable = true)
|
|
private void onEntityHurt(final DamageSource source, final float amount, CallbackInfo ci) {
|
|
ActionResult result = EntityHurtEvent.EVENT.invoker().hurtEntity((LivingEntity) (Object) this, source, amount);
|
|
if (result == ActionResult.FAIL) {
|
|
ci.cancel();
|
|
}
|
|
}
|
|
|
|
@Inject(at = @At("HEAD"), method = "takeKnockback", cancellable = true)
|
|
private void onTakingKnockback(double strength, double x, double z, CallbackInfo ci) {
|
|
ActionResult result = EntityKnockbackEvent.EVENT.invoker().takeKnockback((LivingEntity) (Object) this, strength, x, z);
|
|
if (result == ActionResult.FAIL) {
|
|
ci.cancel();
|
|
}
|
|
}
|
|
}
|