diff --git a/src/main/java/net/mcreator/superbwarfare/client/screens/AmmoBarOverlay.java b/src/main/java/net/mcreator/superbwarfare/client/screens/AmmoBarOverlay.java index 6d7d3715b..48988a950 100644 --- a/src/main/java/net/mcreator/superbwarfare/client/screens/AmmoBarOverlay.java +++ b/src/main/java/net/mcreator/superbwarfare/client/screens/AmmoBarOverlay.java @@ -41,7 +41,7 @@ public class AmmoBarOverlay { } @SubscribeEvent(priority = EventPriority.NORMAL) - public static void eventHandler(RenderGuiEvent.Pre event) { + public static void onRenderGui(RenderGuiEvent.Pre event) { if (!DisplayConfig.AMMO_HUD.get()) return; int w = event.getWindow().getGuiScaledWidth(); diff --git a/src/main/java/net/mcreator/superbwarfare/client/screens/ArmorPlateOverlay.java b/src/main/java/net/mcreator/superbwarfare/client/screens/ArmorPlateOverlay.java new file mode 100644 index 000000000..6c1280cfc --- /dev/null +++ b/src/main/java/net/mcreator/superbwarfare/client/screens/ArmorPlateOverlay.java @@ -0,0 +1,76 @@ +package net.mcreator.superbwarfare.client.screens; + +import net.mcreator.superbwarfare.ModUtils; +import net.mcreator.superbwarfare.init.ModTags; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.event.RenderGuiEvent; +import net.minecraftforge.eventbus.api.EventPriority; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; + +@Mod.EventBusSubscriber(value = Dist.CLIENT) +public class ArmorPlateOverlay { + + private static final ResourceLocation ICON = ModUtils.loc("textures/screens/armor_plate_icon.png"); + private static final ResourceLocation LEVEL1 = ModUtils.loc("textures/screens/armor_plate_level1.png"); + private static final ResourceLocation LEVEL2 = ModUtils.loc("textures/screens/armor_plate_level2.png"); + private static final ResourceLocation LEVEL3 = ModUtils.loc("textures/screens/armor_plate_level3.png"); + private static final ResourceLocation LEVEL1_FRAME = ModUtils.loc("textures/screens/armor_plate_level1_frame.png"); + private static final ResourceLocation LEVEL2_FRAME = ModUtils.loc("textures/screens/armor_plate_level2_frame.png"); + private static final ResourceLocation LEVEL3_FRAME = ModUtils.loc("textures/screens/armor_plate_level3_frame.png"); + + @SubscribeEvent(priority = EventPriority.NORMAL) + public static void onRenderGui(RenderGuiEvent.Pre event) { + int h = event.getWindow().getGuiScaledHeight(); + GuiGraphics guiGraphics = event.getGuiGraphics(); + + Player player = Minecraft.getInstance().player; + if (player == null) return; + if (player.isSpectator()) return; + + ItemStack stack = player.getItemBySlot(EquipmentSlot.CHEST); + if (stack == ItemStack.EMPTY) return; + if (stack.getTag() == null || !stack.getTag().contains("ArmorPlate")) return; + + double amount = stack.getTag().getDouble("ArmorPlate"); + + int armorLevel = 1; + if (stack.is(ModTags.Items.MILITARY_ARMOR)) { + armorLevel = 2; + } else if (stack.is(ModTags.Items.MILITARY_ARMOR_HEAVY)) { + armorLevel = 3; + } + + ResourceLocation texture = switch (armorLevel) { + case 2 -> LEVEL2; + case 3 -> LEVEL3; + default -> LEVEL1; + }; + ResourceLocation frame = switch (armorLevel) { + case 2 -> LEVEL2_FRAME; + case 3 -> LEVEL3_FRAME; + default -> LEVEL1_FRAME; + }; + + int length = armorLevel * 30; + + guiGraphics.pose().pushPose(); + // 渲染图标 + guiGraphics.blit(ICON, 10, h - 16, 0, 0, 8, 8, 8, 8); + + // 渲染框架 + guiGraphics.blit(frame, 20, h - 15, 0, 0, length, 6, length, 6); + + // 渲染盔甲值 + guiGraphics.blit(texture, 20, h - 15, 0, 0, (int) amount, 6, length, 6); + + guiGraphics.pose().popPose(); + + } +} diff --git a/src/main/java/net/mcreator/superbwarfare/event/LivingEventHandler.java b/src/main/java/net/mcreator/superbwarfare/event/LivingEventHandler.java index c39ac7cb3..42831edae 100644 --- a/src/main/java/net/mcreator/superbwarfare/event/LivingEventHandler.java +++ b/src/main/java/net/mcreator/superbwarfare/event/LivingEventHandler.java @@ -107,12 +107,12 @@ public class LivingEventHandler { double armorValue = 0; - if (armor.getItem() != ItemStack.EMPTY.getItem()) { + if (armor != ItemStack.EMPTY) { armorValue = armor.getOrCreateTag().getDouble("ArmorPlate"); armor.getOrCreateTag().putDouble("ArmorPlate", Math.max(armor.getOrCreateTag().getDouble("ArmorPlate") - damage, 0)); } - event.setAmount((float)(Math.max(damage - armorValue, 0))); + event.setAmount((float) (Math.max(damage - armorValue, 0))); if (entity instanceof TargetEntity && sourceEntity instanceof Player player) { player.displayClientMessage(Component.literal("Damage:" + new DecimalFormat("##.#").format(damage) + diff --git a/src/main/java/net/mcreator/superbwarfare/item/ArmorPlate.java b/src/main/java/net/mcreator/superbwarfare/item/ArmorPlate.java index 8c972dd7f..cfbdc4992 100644 --- a/src/main/java/net/mcreator/superbwarfare/item/ArmorPlate.java +++ b/src/main/java/net/mcreator/superbwarfare/item/ArmorPlate.java @@ -1,6 +1,5 @@ package net.mcreator.superbwarfare.item; - import net.mcreator.superbwarfare.init.ModTags; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvents; @@ -27,7 +26,7 @@ public class ArmorPlate extends Item { ItemStack stack = playerIn.getItemInHand(handIn); ItemStack armor = playerIn.getItemBySlot(EquipmentSlot.CHEST); - if (armor.getItem() == ItemStack.EMPTY.getItem()) return InteractionResultHolder.fail(stack); + if (armor == ItemStack.EMPTY) return InteractionResultHolder.fail(stack); int armorLevel = 1; if (armor.is(ModTags.Items.MILITARY_ARMOR)) { @@ -51,7 +50,6 @@ public class ArmorPlate extends Item { @Override public ItemStack finishUsingItem(ItemStack pStack, Level pLevel, LivingEntity pLivingEntity) { if (!pLevel.isClientSide) { - ItemStack armor = pLivingEntity.getItemBySlot(EquipmentSlot.CHEST); int armorLevel = 1;