-
Bug
-
Resolution: Duplicate
-
None
-
1.20.4
-
None
-
id 'fabric-loom' version '1.5.7'
-
Unconfirmed
-
(Unassigned)
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.
- duplicates
-
MC-230719 Logged villager deaths don't use "death.fell.*" death messages, while named mob deaths do
- Open