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.
Linked issues
duplicates 1
Comments 4
By the way, for your mixin, you can use the entity's getCombatTracker method and run getDeathMessage on that, and that should give the correct death message on all cases.
This is already being tracked in MC-230719.
Thank you for your report!
We're tracking this issue in MC-230719, so this ticket is being resolved and linked as a duplicate.
If you would like to add a vote and any extra information to the main ticket it would be appreciated.
If you haven't already, you might like to make use of the search feature to see if the issue has already been mentioned.
Quick Links:
📓 Bug Tracker Guidelines – 💬 Community Support – 📧 Mojang Support (Technical Issues) – 📧 Microsoft Support (Account Issues)
📓 Project Summary – ✍️ Feedback and Suggestions – 📖 Game Wiki
-- I am a bot. This action was performed automatically! The ticket was resolved by one of our moderators, and I left this message to give more information to you.
Duplicate of MC-230719.