Combit/src/main/java/io/gitlab/jfronny/combit/mixin/PlayerEntityMixin.java

57 lines
2.6 KiB
Java

package io.gitlab.jfronny.combit.mixin;
import io.gitlab.jfronny.combit.Combit;
import io.gitlab.jfronny.combit.config.AttackDelay;
import io.gitlab.jfronny.combit.config.Invulnerability;
import io.gitlab.jfronny.combit.nodami.EntityHurtCallback;
import io.gitlab.jfronny.combit.nodami.PlayerAttackCallback;
import net.minecraft.entity.Entity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
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;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(PlayerEntity.class)
public class PlayerEntityMixin {
@Inject(at = @At("TAIL"), method = "applyDamage(Lnet/minecraft/entity/damage/DamageSource;F)V", cancellable = true)
private void onEntityHurt(final DamageSource source, final float amount, CallbackInfo info) {
if (Combit.getCfg().invulnerability.enable) {
ActionResult result = EntityHurtCallback.EVENT.invoker().hurtEntity((PlayerEntity) (Object) this, source,
amount);
if (result == ActionResult.FAIL) {
info.cancel();
}
}
}
@Inject(at = @At("HEAD"), method = "attack(Lnet/minecraft/entity/Entity;)V", cancellable = true)
private void onPlayerAttack(final Entity target, CallbackInfo info) {
if (Combit.getCfg().invulnerability.enable) {
ActionResult result = PlayerAttackCallback.EVENT.invoker().attackEntity((PlayerEntity) (Object) this, target);
if (result == ActionResult.FAIL) {
info.cancel();
}
}
}
@Inject(at = @At("HEAD"), method = "getAttackCooldownProgress(F)F", cancellable = true)
public void getAttackCooldownProgress(float baseTime, CallbackInfoReturnable<Float> info) {
AttackDelay attackDelay = Combit.getCfg().attackDelay;
if (attackDelay.enable && attackDelay.cooldownProgressOverride >= 0) {
info.setReturnValue(attackDelay.cooldownProgressOverride);
}
}
@Inject(at = @At("HEAD"), method = "getAttackCooldownProgressPerTick()F", cancellable = true)
public void getAttackCooldownProgressPerTick(CallbackInfoReturnable<Float> info) {
AttackDelay attackDelay = Combit.getCfg().attackDelay;
if (attackDelay.enable && attackDelay.cooldownProgressPerTickOverride >= 0) {
info.setReturnValue(attackDelay.cooldownProgressPerTickOverride);
}
}
}