|
mixin示例:
package cn.ksmcbrigade.test2.mixin;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.text.Text;
import net.minecraft.world.World;
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;
@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin extends Entity {
public LivingEntityMixin(EntityType<?> type, World world) {
super(type, world);
}
@Inject(method = "damage",at = @At("HEAD"))
public void damage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir){
String attackerName = source.getAttacker()==null?"未知":source.getAttacker().getDisplayName()==null?"未知":source.getAttacker().getDisplayName().getString();
this.getWorld().getPlayers().forEach(p -> p.sendMessage(Text.of(this.getDisplayName()+" 因 "+ attackerName + "所致伤")));
}
}
|
|