2021-03-06 13:27:52 +01:00
|
|
|
package com.minelittlepony.unicopia.mixin;
|
|
|
|
|
2022-12-24 21:12:54 +01:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import org.spongepowered.asm.mixin.*;
|
2021-03-06 13:27:52 +01:00
|
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
2022-12-24 21:12:54 +01:00
|
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
2021-03-06 13:27:52 +01:00
|
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
|
|
|
|
|
|
import com.minelittlepony.unicopia.entity.Equine;
|
2022-12-23 23:31:06 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
|
|
|
|
2021-03-06 13:27:52 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.LivingEntity;
|
2022-12-24 21:12:54 +01:00
|
|
|
import net.minecraft.entity.damage.*;
|
2021-03-06 13:27:52 +01:00
|
|
|
import net.minecraft.text.Text;
|
|
|
|
|
|
|
|
@Mixin(DamageSource.class)
|
|
|
|
abstract class MixinDamageSource {
|
|
|
|
@Inject(method = "getDeathMessage", at = @At("RETURN"), cancellable = true)
|
|
|
|
private void onGetDeathMessage(LivingEntity entity, CallbackInfoReturnable<Text> info) {
|
2022-12-24 21:12:54 +01:00
|
|
|
final DamageSource self = (DamageSource)(Object)this;
|
|
|
|
|
|
|
|
if (self.isFromFalling()) {
|
|
|
|
info.setReturnValue(new DamageSource(self.name + ".pegasus").getDeathMessage(entity));
|
|
|
|
} else {
|
|
|
|
Equine.of(entity).map(Equine::getAttacker).ifPresent(attacker -> {
|
|
|
|
Entity prime = entity.getPrimeAdversary();
|
|
|
|
if (prime != null && !attacker.isOwnedBy(prime)) {
|
|
|
|
info.setReturnValue(Text.translatable("death.attack.generic.and_also", info.getReturnValue(), attacker.asEntity().getDisplayName()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
info.setReturnValue(Text.translatable("death.attack." + self.getName() + ".player", entity.getDisplayName(), attacker.asEntity().getDisplayName()));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Pony.of(entity).filter(e -> e.getSpecies().canFly()).ifPresent(pony -> {
|
|
|
|
if (pony.getPhysics().isFlying()) {
|
|
|
|
info.setReturnValue(Text.translatable("death.attack.generic.whilst_flying", info.getReturnValue()));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-23 23:31:06 +01:00
|
|
|
|
2022-12-24 21:12:54 +01:00
|
|
|
@Mixin(DamageTracker.class)
|
|
|
|
abstract class MixinDamageTracker {
|
|
|
|
@Shadow
|
|
|
|
private @Final LivingEntity entity;
|
|
|
|
@Nullable
|
|
|
|
private String fallDeathSuffix;
|
|
|
|
|
|
|
|
@Inject(method = "setFallDeathSuffix", at = @At("RETURN"))
|
|
|
|
private void onSetFallDeathSuffix(CallbackInfo info) {
|
|
|
|
Pony.of(entity).ifPresent(pony -> {
|
|
|
|
if (pony.getSpecies().canFly()) {
|
|
|
|
fallDeathSuffix = (fallDeathSuffix == null ? "" : fallDeathSuffix + ".") + "pegasus";
|
2022-12-23 23:31:06 +01:00
|
|
|
}
|
|
|
|
});
|
2021-03-06 13:27:52 +01:00
|
|
|
}
|
|
|
|
}
|