Commit 5a46f890 by Jonathan Thomas

Death messages added for all named creatures (RIP)

parent 0a403a5f
......@@ -8,6 +8,7 @@ All notable changes to **CreatureChat** are documented in this file. The format
### Added
- New automated deployments for Modrinth and CurseForge (GitLab CI Pipeline)
- Death messages added for all named creatures (RIP)
### Fixed
- Parse OpenAI JSON error messages, to display a more readable error message
......
......@@ -10,9 +10,12 @@ import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
......@@ -61,6 +64,19 @@ public class MixinLivingEntity implements LivingEntityInterface {
}
}
@Inject(method = "onDeath", at = @At("HEAD"))
private void onDeath(DamageSource source, CallbackInfo info) {
LivingEntity entity = (LivingEntity) (Object) this;
World world = entity.getWorld();
if (!world.isClient() && entity.hasCustomName()) {
// Get the original death message
Text deathMessage = entity.getDamageTracker().getDeathMessage();
// Broadcast the death message to all players in the world
ServerPackets.BroadcastMessage(deathMessage);
}
}
@Override
public void setCanTargetPlayers(boolean canTarget) {
this.canTargetPlayers = canTarget;
......
......@@ -316,6 +316,13 @@ public class ServerPackets {
}
}
// Send a chat message to all players (i.e. death message)
public static void BroadcastMessage(Text message) {
for (ServerPlayerEntity serverPlayer : serverInstance.getPlayerManager().getPlayerList()) {
serverPlayer.sendMessage(message, false);
};
}
// Send a chat message to a player which is clickable (for error messages with a link for help)
public static void SendClickableError(PlayerEntity player, String message, String url) {
MutableText text = Text.literal(message)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment