Unicopia/src/main/java/com/minelittlepony/unicopia/mixin/MixinEntity.java

79 lines
3 KiB
Java
Raw Normal View History

2021-08-04 15:38:03 +02:00
package com.minelittlepony.unicopia.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
2022-09-11 15:42:26 +02:00
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
2022-09-11 15:42:26 +02:00
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.minelittlepony.unicopia.entity.duck.LavaAffine;
2023-10-09 23:05:41 +02:00
import com.minelittlepony.unicopia.EquinePredicates;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.entity.Equine;
import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.duck.EntityDuck;
2022-09-11 15:42:26 +02:00
2021-08-04 15:38:03 +02:00
import net.minecraft.entity.Entity;
import net.minecraft.entity.Entity.PositionUpdater;
2021-08-04 15:38:03 +02:00
import net.minecraft.entity.Entity.RemovalReason;
@Mixin(Entity.class)
abstract class MixinEntity implements EntityDuck {
2022-09-11 15:42:26 +02:00
@Override
2021-08-04 15:38:03 +02:00
@Accessor
2022-09-11 15:42:26 +02:00
public abstract void setRemovalReason(RemovalReason reason);
@Override
@Accessor
public abstract void setVehicle(Entity vehicle);
2023-08-11 19:51:35 +02:00
@Override
@Accessor
public abstract float getNextStepSoundDistance();
@Override
public boolean isLavaAffine() {
Entity self = (Entity)(Object)this;
return self.hasVehicle() && self.getVehicle() instanceof LavaAffine affine && affine.isLavaAffine();
}
2022-09-11 15:42:26 +02:00
@Inject(method = "isFireImmune", at = @At("HEAD"), cancellable = true)
private void onIsFireImmune(CallbackInfoReturnable<Boolean> info) {
2023-10-09 23:05:41 +02:00
if (isLavaAffine() || (this instanceof Equine.Container c) && c.get().getCompositeRace().includes(Race.KIRIN)) {
info.setReturnValue(true);
}
}
@Inject(method = "isSneaky", at = @At("HEAD"), cancellable = true)
private void onIsSneaky(CallbackInfoReturnable<Boolean> info) {
if (EquinePredicates.PLAYER_KIRIN.test((Entity)(Object)this) && !EquinePredicates.RAGING.test((Entity)(Object)this)) {
2023-10-09 23:05:41 +02:00
info.setReturnValue(true);
}
}
@Inject(method = "getMaxAir", at = @At("HEAD"), cancellable = true)
private void onGetMaxAir(CallbackInfoReturnable<Integer> info) {
if (EquinePredicates.PLAYER_KIRIN.test((Entity)(Object)this)) {
info.setReturnValue(150);
}
}
@Inject(method = "doesRenderOnFire", at = @At("HEAD"), cancellable = true)
private void onDoesRenderOnFire(CallbackInfoReturnable<Boolean> info) {
if (EquinePredicates.RAGING.test((Entity)(Object)this)) {
2022-09-11 15:42:26 +02:00
info.setReturnValue(true);
}
}
@Inject(method = "updatePassengerPosition(Lnet/minecraft/entity/Entity;Lnet/minecraft/entity/Entity$PositionUpdater;)V",
at = @At("HEAD"),
cancellable = true
)
private void updatePassengerPosition(Entity passenger, PositionUpdater positionUpdater, CallbackInfo info) {
if (Living.getOrEmpty((Entity)(Object)this).filter(l -> l.onUpdatePassengerPosition(passenger, positionUpdater)).isPresent()) {
info.cancel();
}
}
2021-08-04 15:38:03 +02:00
}