From 27893f03abf607b708c48181528f6753f58f9857 Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Fri, 3 Jan 2025 22:14:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BD=BD=E5=85=B7HUD?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/overlay/AmmoBarOverlay.java | 2 +- .../client/overlay/ArmorPlateOverlay.java | 6 +- .../client/overlay/VehicleHudOverlay.java | 56 ++++++++++--------- .../client/overlay/VehicleMgHudOverlay.java | 1 - .../entity/IHelicopterEntity.java | 4 ++ 5 files changed, 37 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/AmmoBarOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/AmmoBarOverlay.java index 7e1049da0..4a6d25405 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/AmmoBarOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/AmmoBarOverlay.java @@ -23,6 +23,7 @@ import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber(value = Dist.CLIENT) public class AmmoBarOverlay { + private static final ResourceLocation LINE = ModUtils.loc("textures/gun_icon/fire_mode/line.png"); private static final ResourceLocation SEMI = ModUtils.loc("textures/gun_icon/fire_mode/semi.png"); private static final ResourceLocation BURST = ModUtils.loc("textures/gun_icon/fire_mode/burst.png"); @@ -53,7 +54,6 @@ public class AmmoBarOverlay { Player player = Minecraft.getInstance().player; if (player == null) return; - if (player.isSpectator()) return; ItemStack stack = player.getMainHandItem(); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/ArmorPlateOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/ArmorPlateOverlay.java index 84b661d09..b942b585e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/ArmorPlateOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/ArmorPlateOverlay.java @@ -65,13 +65,13 @@ public class ArmorPlateOverlay { guiGraphics.pose().pushPose(); // 渲染图标 - guiGraphics.blit(ICON, 10, h - 16, 0, 0, 8, 8, 8, 8); + guiGraphics.blit(ICON, 10, h - 13, 0, 0, 8, 8, 8, 8); // 渲染框架 - guiGraphics.blit(frame, 20, h - 15, 0, 0, length, 6, length, 6); + guiGraphics.blit(frame, 20, h - 12, 0, 0, length, 6, length, 6); // 渲染盔甲值 - guiGraphics.blit(texture, 20, h - 15, 0, 0, (int) amount, 6, length, 6); + guiGraphics.blit(texture, 20, h - 12, 0, 0, (int) amount, 6, length, 6); guiGraphics.pose().popPose(); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java index 4dba664e7..0a48abc48 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java @@ -12,6 +12,7 @@ import net.minecraft.client.renderer.GameRenderer; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; +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; @@ -23,12 +24,6 @@ import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber(value = Dist.CLIENT) public class VehicleHudOverlay { - public static float health = 0; - public static float maxHealth = 0; - - public static float energy = 0; - public static float maxEnergy = 0; - private static final ResourceLocation ARMOR = ModUtils.loc("textures/screens/armor.png"); private static final ResourceLocation ENERGY = ModUtils.loc("textures/screens/energy.png"); private static final ResourceLocation HEALTH = ModUtils.loc("textures/screens/armor_value.png"); @@ -40,47 +35,48 @@ public class VehicleHudOverlay { int h = event.getWindow().getGuiScaledHeight(); Player player = Minecraft.getInstance().player; - if (!shouldRenderCrossHair(player)) return; + if (!shouldRenderHud(player)) return; Entity vehicle = player.getVehicle(); if (vehicle == null) return; + GuiGraphics guiGraphics = event.getGuiGraphics(); + PoseStack poseStack = guiGraphics.pose(); + + poseStack.pushPose(); + RenderSystem.disableDepthTest(); RenderSystem.depthMask(false); RenderSystem.enableBlend(); RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); RenderSystem.setShaderColor(1, 1, 1, 1); - GuiGraphics guiGraphics = event.getGuiGraphics(); - guiGraphics.pose().pushPose(); + int compatHeight = getArmorPlateCompatHeight(player); + if (vehicle instanceof EnergyVehicleEntity energyVehicleEntity) { - energy = energyVehicleEntity.getEnergy(); - maxEnergy = energyVehicleEntity.getMaxEnergy(); - guiGraphics.blit(ENERGY, w - 96, h - 28, 0, 0, 12, 12, 12, 12); - guiGraphics.blit(HEALTH_FRAME, w - 83, h - 26, 0, 0, 80, 8, 80, 8); - guiGraphics.blit(HEALTH, w - 83, h - 26, 0, 0, (int) (80 * energy / maxEnergy), 8, 80, 8); + float energy = energyVehicleEntity.getEnergy(); + float maxEnergy = energyVehicleEntity.getMaxEnergy(); + guiGraphics.blit(ENERGY, 10, h - 22 - compatHeight, 0, 0, 8, 8, 8, 8); + guiGraphics.blit(HEALTH_FRAME, 20, h - 21 - compatHeight, 0, 0, 60, 6, 60, 6); + guiGraphics.blit(HEALTH, 20, h - 21 - compatHeight, 0, 0, (int) (60 * energy / maxEnergy), 6, 60, 6); } if (vehicle instanceof VehicleEntity pVehicle) { - health = pVehicle.getHealth(); - maxHealth = pVehicle.getMaxHealth(); - guiGraphics.blit(ARMOR, w - 96, h - 14, 0, 0, 12, 12, 12, 12); - guiGraphics.blit(HEALTH_FRAME, w - 83, h - 12, 0, 0, 80, 8, 80, 8); - guiGraphics.blit(HEALTH, w - 83, h - 12, 0, 0, (int) (80 * health / maxHealth), 8, 80, 8); + float health = pVehicle.getHealth(); + float maxHealth = pVehicle.getMaxHealth(); + guiGraphics.blit(ARMOR, 10, h - 13 - compatHeight, 0, 0, 8, 8, 8, 8); + guiGraphics.blit(HEALTH_FRAME, 20, h - 12 - compatHeight, 0, 0, 60, 6, 60, 6); + guiGraphics.blit(HEALTH, 20, h - 12 - compatHeight, 0, 0, (int) (60 * health / maxHealth), 6, 60, 6); } - guiGraphics.pose().popPose(); - - PoseStack poseStack = event.getGuiGraphics().pose(); + poseStack.popPose(); if (vehicle instanceof IArmedVehicleEntity iVehicle && iVehicle.getAmmoCount(player) != -1) { - boolean iCharge = iVehicle instanceof IChargeEntity; // 渲染当前弹药量 poseStack.pushPose(); poseStack.scale(1.5f, 1.5f, 1f); - float v = h / 1.5f - (iCharge ? 42 : 29) / 1.5f; if (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) && !(iVehicle instanceof ICannonEntity)) { @@ -118,10 +114,9 @@ public class VehicleHudOverlay { } } - private static boolean shouldRenderCrossHair(Player player) { + private static boolean shouldRenderHud(Player player) { if (player == null) return false; - return !player.isSpectator() - && (player.getVehicle() != null && player.getVehicle() instanceof VehicleEntity); + return !player.isSpectator() && (player.getVehicle() != null && player.getVehicle() instanceof VehicleEntity); } private static String getVehicleAmmoType(ItemStack stack, IArmedVehicleEntity iVehicle) { @@ -136,4 +131,11 @@ public class VehicleHudOverlay { } return ""; } + + private static int getArmorPlateCompatHeight(Player player) { + ItemStack stack = player.getItemBySlot(EquipmentSlot.CHEST); + if (stack == ItemStack.EMPTY) return 0; + if (stack.getTag() == null || !stack.getTag().contains("ArmorPlate")) return 0; + return 9; + } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleMgHudOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleMgHudOverlay.java index f026e80c2..860aa5451 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleMgHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleMgHudOverlay.java @@ -26,7 +26,6 @@ import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit; @Mod.EventBusSubscriber(value = Dist.CLIENT) public class VehicleMgHudOverlay { - public static float indicatorPosH = 0; @SubscribeEvent(priority = EventPriority.NORMAL) public static void eventHandler(RenderGuiEvent.Pre event) { diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/IHelicopterEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/IHelicopterEntity.java index 5479e90a2..1457065ad 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/IHelicopterEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/IHelicopterEntity.java @@ -1,8 +1,12 @@ package com.atsuishio.superbwarfare.entity; public interface IHelicopterEntity extends IArmedVehicleEntity { + float getRotX(float tickDelta); + float getRotY(float tickDelta); + float getRotZ(float tickDelta); + float getPower(); }