From 2ec1c01ce943b66b2a51b9a53667bde4b653a88a Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Mon, 20 May 2024 23:13:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E7=9A=84=E5=9B=BE?= =?UTF-8?q?=E6=A0=87=EF=BC=8C=E4=BF=AE=E6=94=B9=E6=B8=B2=E6=9F=93=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/screens/KillMessageOverlay.java | 75 +++++++++++------- .../screens/{ => damage_types}/claymore.png | Bin .../screens/{ => damage_types}/explosion.png | Bin .../textures/screens/damage_types/generic.png | Bin 0 -> 147 bytes .../screens/{ => damage_types}/headshot.png | Bin .../screens/{ => damage_types}/knife.png | Bin 6 files changed, 48 insertions(+), 27 deletions(-) rename src/main/resources/assets/target/textures/screens/{ => damage_types}/claymore.png (100%) rename src/main/resources/assets/target/textures/screens/{ => damage_types}/explosion.png (100%) create mode 100644 src/main/resources/assets/target/textures/screens/damage_types/generic.png rename src/main/resources/assets/target/textures/screens/{ => damage_types}/headshot.png (100%) rename src/main/resources/assets/target/textures/screens/{ => damage_types}/knife.png (100%) diff --git a/src/main/java/net/mcreator/target/client/screens/KillMessageOverlay.java b/src/main/java/net/mcreator/target/client/screens/KillMessageOverlay.java index ee673c679..5e2fd06b3 100644 --- a/src/main/java/net/mcreator/target/client/screens/KillMessageOverlay.java +++ b/src/main/java/net/mcreator/target/client/screens/KillMessageOverlay.java @@ -2,6 +2,7 @@ package net.mcreator.target.client.screens; import net.mcreator.target.TargetMod; import net.mcreator.target.event.KillMessageHandler; +import net.mcreator.target.init.TargetModDamageTypes; import net.mcreator.target.item.gun.GunItem; import net.mcreator.target.tools.PlayerKillRecord; import net.minecraft.client.Minecraft; @@ -14,14 +15,16 @@ import net.minecraftforge.client.event.RenderGuiEvent; import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; +import org.jetbrains.annotations.Nullable; @Mod.EventBusSubscriber(value = Dist.CLIENT) public class KillMessageOverlay { - private static final ResourceLocation HEADSHOT = new ResourceLocation(TargetMod.MODID, "textures/screens/headshot.png"); + private static final ResourceLocation HEADSHOT = new ResourceLocation(TargetMod.MODID, "textures/screens/damage_types/headshot.png"); - private static final ResourceLocation KNIFE = new ResourceLocation(TargetMod.MODID, "textures/screens/knife.png"); - private static final ResourceLocation EXPLOSION = new ResourceLocation(TargetMod.MODID, "textures/screens/explosion.png"); - private static final ResourceLocation CLAYMORE = new ResourceLocation(TargetMod.MODID, "textures/screens/claymore.png"); + private static final ResourceLocation KNIFE = new ResourceLocation(TargetMod.MODID, "textures/screens/damage_types/knife.png"); + private static final ResourceLocation EXPLOSION = new ResourceLocation(TargetMod.MODID, "textures/screens/damage_types/explosion.png"); + private static final ResourceLocation CLAYMORE = new ResourceLocation(TargetMod.MODID, "textures/screens/damage_types/claymore.png"); + private static final ResourceLocation GENERIC = new ResourceLocation(TargetMod.MODID, "textures/screens/damage_types/generic.png"); @SubscribeEvent(priority = EventPriority.NORMAL) public static void eventHandler(RenderGuiEvent.Pre event) { @@ -64,27 +67,14 @@ public class KillMessageOverlay { false ); - // 渲染爆头图标 - if (record.headshot) { - event.getGuiGraphics().blit(HEADSHOT, - w - targetNameWidth - 28, - h - 2, - 0, - 0, - 12, - 12, - 12, - 12 - ); - } - - // 如果是爆炸伤害,则渲染爆炸图标 - boolean explosion = false; - if (record.damageType == DamageTypes.EXPLOSION || record.damageType == DamageTypes.PLAYER_EXPLOSION) { - explosion = true; - int explosionW = w - targetNameWidth - 26; - event.getGuiGraphics().blit(EXPLOSION, - explosionW, + // 第一个图标:爆头/爆炸/近战等图标 + int icon1W = w - targetNameWidth - 28; + + ResourceLocation icon1 = getIcon1(record); + + if (icon1 != null) { + event.getGuiGraphics().blit(icon1, + icon1W, h - 2, 0, 0, @@ -95,10 +85,11 @@ public class KillMessageOverlay { ); } + boolean isGun = record.stack.getItem() instanceof GunItem; // 如果是枪械击杀,则渲染枪械图标 if (record.stack.getItem() instanceof GunItem gunItem) { ResourceLocation resourceLocation = gunItem.getGunIcon(); - int gunIconW = (record.headshot || explosion) ? w - targetNameWidth - 64 : w - targetNameWidth - 46; + int gunIconW = icon1 != null ? w - targetNameWidth - 64 : w - targetNameWidth - 46; event.getGuiGraphics().blit(resourceLocation, gunIconW, h, @@ -114,7 +105,13 @@ public class KillMessageOverlay { // 渲染击杀者名称 String attackerName = record.attacker.getDisplayName().getString(); int attackerNameWidth = font.width(attackerName); - int nameW = (record.headshot || explosion) ? w - targetNameWidth - 68 - attackerNameWidth : w - targetNameWidth - 50 - attackerNameWidth; + int nameW = w - targetNameWidth - 16 - attackerNameWidth; + if (isGun) { + nameW -= 32; + } + if (icon1 != null) { + nameW -= 18; + } event.getGuiGraphics().drawString( Minecraft.getInstance().font, @@ -126,4 +123,28 @@ public class KillMessageOverlay { ); } + + @Nullable + private static ResourceLocation getIcon1(PlayerKillRecord record) { + ResourceLocation icon1; + // 渲染爆头图标 + if (record.headshot) { + icon1 = HEADSHOT; + } else { + if (record.damageType == TargetModDamageTypes.GUN_FIRE || record.damageType == TargetModDamageTypes.GUN_FIRE_HEADSHOT + || record.damageType == TargetModDamageTypes.ARROW_IN_KNEE || record.damageType == TargetModDamageTypes.ARROW_IN_BRAIN) { + icon1 = null; + } else { + // 如果是其他伤害,则渲染对应图标 + if (record.damageType == DamageTypes.EXPLOSION || record.damageType == DamageTypes.PLAYER_EXPLOSION) { + icon1 = EXPLOSION; + } else if (record.damageType == DamageTypes.PLAYER_ATTACK) { + icon1 = KNIFE; + } else { + icon1 = GENERIC; + } + } + } + return icon1; + } } diff --git a/src/main/resources/assets/target/textures/screens/claymore.png b/src/main/resources/assets/target/textures/screens/damage_types/claymore.png similarity index 100% rename from src/main/resources/assets/target/textures/screens/claymore.png rename to src/main/resources/assets/target/textures/screens/damage_types/claymore.png diff --git a/src/main/resources/assets/target/textures/screens/explosion.png b/src/main/resources/assets/target/textures/screens/damage_types/explosion.png similarity index 100% rename from src/main/resources/assets/target/textures/screens/explosion.png rename to src/main/resources/assets/target/textures/screens/damage_types/explosion.png diff --git a/src/main/resources/assets/target/textures/screens/damage_types/generic.png b/src/main/resources/assets/target/textures/screens/damage_types/generic.png new file mode 100644 index 0000000000000000000000000000000000000000..81bffdda24cb2432a5393ebeacc93949d99f2ec2 GIT binary patch literal 147 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9F3${@^GvDCf{DCp|x z;uvDlo17qF`QSegZ0s}+%;NB5OE7K`oPM%}K^X`l^&HAMZ?YX=0OCCdJl3#1DQL=6 lJI#7xmM7DbBUc0%8S1CXFjrqo5Ca;>;OXk;vd$@?2>{V(EC~Pr literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/target/textures/screens/headshot.png b/src/main/resources/assets/target/textures/screens/damage_types/headshot.png similarity index 100% rename from src/main/resources/assets/target/textures/screens/headshot.png rename to src/main/resources/assets/target/textures/screens/damage_types/headshot.png diff --git a/src/main/resources/assets/target/textures/screens/knife.png b/src/main/resources/assets/target/textures/screens/damage_types/knife.png similarity index 100% rename from src/main/resources/assets/target/textures/screens/knife.png rename to src/main/resources/assets/target/textures/screens/damage_types/knife.png