diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinDamageSource.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinDamageSource.java index 638ca8cb..ec21071b 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinDamageSource.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinDamageSource.java @@ -1,8 +1,10 @@ package com.minelittlepony.unicopia.mixin; -import org.spongepowered.asm.mixin.Mixin; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.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; import com.minelittlepony.unicopia.entity.Equine; @@ -10,30 +12,50 @@ import com.minelittlepony.unicopia.entity.player.Pony; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.damage.DamageSource; +import net.minecraft.entity.damage.*; 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 info) { - Equine.of(entity).map(Equine::getAttacker).ifPresent(attacker -> { - DamageSource self = (DamageSource)(Object)this; + final DamageSource self = (DamageSource)(Object)this; - 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; - } + 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())); - }); + info.setReturnValue(Text.translatable("death.attack." + self.getName() + ".player", entity.getDisplayName(), attacker.asEntity().getDisplayName())); + }); - DamageSource self = (DamageSource)(Object)this; - 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())); + 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())); + } + }); + } + } +} + +@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"; } }); } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinTranslationStorage.java b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinTranslationStorage.java new file mode 100644 index 00000000..238b7149 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinTranslationStorage.java @@ -0,0 +1,33 @@ +package com.minelittlepony.unicopia.mixin.client; + +import java.util.Map; + +import org.spongepowered.asm.mixin.*; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import net.minecraft.client.resource.language.TranslationStorage; + +@Mixin(TranslationStorage.class) +abstract class MixinTranslationStorage { + @Shadow + private @Final Map translations; + + @Inject(method = "get", at = @At("HEAD"), cancellable = true) + public void onGet(String key, CallbackInfoReturnable info) { + if (key != null && key.contains(".pegasus") && !translations.containsKey(key)) { + info.setReturnValue(translations.getOrDefault(key.replace(".pegasus", ""), key)); + } + } + + @Inject(method = "hasTranslation", at = @At("RETURN"), cancellable = true) + public void onHasTranslation(String key, CallbackInfoReturnable info) { + if (key != null + && key.contains(".pegasus") + && !info.getReturnValueZ() + && translations.containsKey(key.replace(".pegasus", ""))) { + info.setReturnValue(true); + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/lang/en_us.json b/src/main/resources/assets/unicopia/lang/en_us.json index 960fd759..8a69a6bc 100644 --- a/src/main/resources/assets/unicopia/lang/en_us.json +++ b/src/main/resources/assets/unicopia/lang/en_us.json @@ -526,10 +526,17 @@ "death.attack.black_hole.player": "%1$s got sucked into %2$s's black hole", "death.attack.kick": "%1$s was kicked really hard", "death.attack.kick.player": "%2$s kicked %1$s really hard", - "death.attack.fall.pegasus": "%1$s forgot they could fly", - "death.attack.fall.pegasus.player": "%1$s forgot they could fly and hit the ground too hard whilst trying to escape %2$s", "death.attack.stalagmite.pegasus": "%1$s tried to perch on a stalagmite", "death.attack.stalagmite.pegasus.player": "%1$s flew into a stalagmite whilst fighting %2$s", + + "death.fell.accident.ladder.pegasus": "%1$s forgot they could fly and fell off a ladder", + "death.fell.accident.vines.pegasus": "%1$s forgot they could fly and fell off some vines", + "death.fell.accident.weeping_vines.pegasus": "%1$s forgot they could fly and fell off some weeping vines", + "death.fell.accident.twisting_vines.pegasus": "%1$s forgot they could fly and fell off some twisting vines", + "death.fell.accident.scaffolding.pegasus": "%1$s forgot they could fly and fell off scaffolding", + "death.fell.accident.other_climbable.pegasus": "%1$s forgot they could fly and fell while climbing", + "death.fell.accident.generic.pegasus": "%1$s forgot they could fly", + "death.fell.accident.pegasus": "%1$s forgot they could fly", "unicopia.subtitle.flap_wings": "Wing flaps", "unicopia.subtitle.dash": "Pony Dashes", diff --git a/src/main/resources/unicopia.mixin.json b/src/main/resources/unicopia.mixin.json index 4852c64c..94cd7398 100644 --- a/src/main/resources/unicopia.mixin.json +++ b/src/main/resources/unicopia.mixin.json @@ -11,6 +11,7 @@ "MixinBoatEntity", "MixinBrain", "MixinDamageSource", + "MixinDamageTracker", "MixinEntity", "MixinFallingBlock", "MixinFallingBlockEntity", @@ -55,6 +56,7 @@ "client.MixinMouse", "client.MixinPlayerEntityRenderer", "client.MixinTooltipComponent", + "client.MixinTranslationStorage", "client.MixinWorldRenderer", "client.sodium.MixinSodiumWorldRenderer", "trinkets.MixinTrinketCreativeSlot"