Properly implement death messages for pegasi

This commit is contained in:
Sollace 2022-12-24 21:12:54 +01:00
parent a36c1bead3
commit f55dff6b87
4 changed files with 81 additions and 17 deletions

View file

@ -1,8 +1,10 @@
package com.minelittlepony.unicopia.mixin; 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.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.minelittlepony.unicopia.entity.Equine; import com.minelittlepony.unicopia.entity.Equine;
@ -10,16 +12,19 @@ import com.minelittlepony.unicopia.entity.player.Pony;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.damage.*;
import net.minecraft.text.Text; import net.minecraft.text.Text;
@Mixin(DamageSource.class) @Mixin(DamageSource.class)
abstract class MixinDamageSource { abstract class MixinDamageSource {
@Inject(method = "getDeathMessage", at = @At("RETURN"), cancellable = true) @Inject(method = "getDeathMessage", at = @At("RETURN"), cancellable = true)
private void onGetDeathMessage(LivingEntity entity, CallbackInfoReturnable<Text> info) { private void onGetDeathMessage(LivingEntity entity, CallbackInfoReturnable<Text> info) {
Equine.of(entity).map(Equine::getAttacker).ifPresent(attacker -> { final DamageSource self = (DamageSource)(Object)this;
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(); Entity prime = entity.getPrimeAdversary();
if (prime != null && !attacker.isOwnedBy(prime)) { if (prime != null && !attacker.isOwnedBy(prime)) {
info.setReturnValue(Text.translatable("death.attack.generic.and_also", info.getReturnValue(), attacker.asEntity().getDisplayName())); info.setReturnValue(Text.translatable("death.attack.generic.and_also", info.getReturnValue(), attacker.asEntity().getDisplayName()));
@ -29,7 +34,6 @@ abstract class MixinDamageSource {
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 -> { Pony.of(entity).filter(e -> e.getSpecies().canFly()).ifPresent(pony -> {
if (pony.getPhysics().isFlying()) { if (pony.getPhysics().isFlying()) {
@ -38,3 +42,21 @@ abstract class MixinDamageSource {
}); });
} }
} }
}
@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";
}
});
}
}

View file

@ -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<String, String> translations;
@Inject(method = "get", at = @At("HEAD"), cancellable = true)
public void onGet(String key, CallbackInfoReturnable<String> 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<Boolean> info) {
if (key != null
&& key.contains(".pegasus")
&& !info.getReturnValueZ()
&& translations.containsKey(key.replace(".pegasus", ""))) {
info.setReturnValue(true);
}
}
}

View file

@ -526,11 +526,18 @@
"death.attack.black_hole.player": "%1$s got sucked into %2$s's black hole", "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": "%1$s was kicked really hard",
"death.attack.kick.player": "%2$s kicked %1$s 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": "%1$s tried to perch on a stalagmite",
"death.attack.stalagmite.pegasus.player": "%1$s flew into a stalagmite whilst fighting %2$s", "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.flap_wings": "Wing flaps",
"unicopia.subtitle.dash": "Pony Dashes", "unicopia.subtitle.dash": "Pony Dashes",
"unicopia.subtitle.wind_rush": "Wind gusts", "unicopia.subtitle.wind_rush": "Wind gusts",

View file

@ -11,6 +11,7 @@
"MixinBoatEntity", "MixinBoatEntity",
"MixinBrain", "MixinBrain",
"MixinDamageSource", "MixinDamageSource",
"MixinDamageTracker",
"MixinEntity", "MixinEntity",
"MixinFallingBlock", "MixinFallingBlock",
"MixinFallingBlockEntity", "MixinFallingBlockEntity",
@ -55,6 +56,7 @@
"client.MixinMouse", "client.MixinMouse",
"client.MixinPlayerEntityRenderer", "client.MixinPlayerEntityRenderer",
"client.MixinTooltipComponent", "client.MixinTooltipComponent",
"client.MixinTranslationStorage",
"client.MixinWorldRenderer", "client.MixinWorldRenderer",
"client.sodium.MixinSodiumWorldRenderer", "client.sodium.MixinSodiumWorldRenderer",
"trinkets.MixinTrinketCreativeSlot" "trinkets.MixinTrinketCreativeSlot"