2021-03-06 13:27:52 +01:00
|
|
|
package com.minelittlepony.unicopia.mixin;
|
|
|
|
|
|
|
|
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.CallbackInfoReturnable;
|
|
|
|
|
|
|
|
import com.minelittlepony.unicopia.Owned;
|
|
|
|
import com.minelittlepony.unicopia.entity.Equine;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
|
|
import net.minecraft.entity.damage.DamageSource;
|
|
|
|
import net.minecraft.text.Text;
|
|
|
|
|
|
|
|
@Mixin(DamageSource.class)
|
|
|
|
abstract class MixinDamageSource {
|
2022-01-01 21:08:50 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
2021-03-06 13:27:52 +01:00
|
|
|
@Inject(method = "getDeathMessage", at = @At("RETURN"), cancellable = true)
|
|
|
|
private void onGetDeathMessage(LivingEntity entity, CallbackInfoReturnable<Text> info) {
|
2021-03-06 22:11:17 +01:00
|
|
|
Equine.of(entity).map(Equine::getAttacker).ifPresent(attacker -> {
|
|
|
|
DamageSource self = (DamageSource)(Object)this;
|
2021-03-06 13:27:52 +01:00
|
|
|
|
|
|
|
Entity prime = entity.getPrimeAdversary();
|
2022-01-01 21:08:50 +01:00
|
|
|
if (prime != null && !(attacker instanceof Owned<?> && ((Owned<Entity>)attacker).isOwnedBy(prime))) {
|
2022-06-25 00:19:55 +02:00
|
|
|
info.setReturnValue(Text.translatable("death.attack.generic.and_also", info.getReturnValue(), attacker.getDisplayName()));
|
2021-03-06 13:27:52 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-25 00:19:55 +02:00
|
|
|
info.setReturnValue(Text.translatable("death.attack." + self.getName() + ".player", entity.getDisplayName(), attacker.getDisplayName()));
|
2021-03-06 22:11:17 +01:00
|
|
|
});
|
2021-03-06 13:27:52 +01:00
|
|
|
}
|
|
|
|
}
|