DamageSource.getDeathMessage doesn't work when the death id start with "death.fell"
When I use mixin to inject something in `DamageSource.getDeathMessage` to change death message, I can be success when I was killed or I died in fire
But when I fall from air and died on the floor, the code can't run successful, It will display the original death message.
There is my code:
package net.mirolls.bettertips.mixin; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.damage.DamageType; import net.minecraft.text.Text; 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 static net.mirolls.bettertips.BetterTips.LOGGER; @Mixin(DamageSource.class) public abstract class BetterTipsDied { @Inject(method = "getDeathMessage", at = @At("RETURN"), cancellable = true) private void onDeath(LivingEntity killed, CallbackInfoReturnable<Text> cir) { // Get death reason DamageSource source = (DamageSource) (Object) this; // change mixin class to DamageSource DamageType deathType = source.getType(); // get death type Entity killer = source.getAttacker(); LOGGER.info("[BetterTips]" + killed.getName().getString() + " was killed" + (killer != null ? "by " + killer : null) + deathType.msgId()); if (killer != null) { // if that has killer LOGGER.info("[BetterTips]" + killer.getType() + killer.getName() + killer.getHandItems()); // log something in console } System.out.printf(String.valueOf(deathType)); cir.setReturnValue(Text.literal(deathType.toString() + deathType)); // killed.onDeath(); } }
My speculation:
Maybe when the died id is `death.fell`, the death message isn't from `getDeathMessage` method, it's might be from other methods, but I can't find it in minecraft decompiled files, I need someone's help.
Thank for your answer.
2024-03-30, 03:07 AM
2024-04-06, 04:37 PM
2024-04-06, 04:32 PM
0
0
-