优化载具HUD显示
This commit is contained in:
parent
9525d019c3
commit
27893f03ab
5 changed files with 37 additions and 32 deletions
|
@ -23,6 +23,7 @@ import net.minecraftforge.fml.common.Mod;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
||||||
public class AmmoBarOverlay {
|
public class AmmoBarOverlay {
|
||||||
|
|
||||||
private static final ResourceLocation LINE = ModUtils.loc("textures/gun_icon/fire_mode/line.png");
|
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 SEMI = ModUtils.loc("textures/gun_icon/fire_mode/semi.png");
|
||||||
private static final ResourceLocation BURST = ModUtils.loc("textures/gun_icon/fire_mode/burst.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;
|
Player player = Minecraft.getInstance().player;
|
||||||
|
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
|
||||||
if (player.isSpectator()) return;
|
if (player.isSpectator()) return;
|
||||||
|
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
|
|
@ -65,13 +65,13 @@ public class ArmorPlateOverlay {
|
||||||
|
|
||||||
guiGraphics.pose().pushPose();
|
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();
|
guiGraphics.pose().popPose();
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import net.minecraft.client.renderer.GameRenderer;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
@ -23,12 +24,6 @@ import net.minecraftforge.fml.common.Mod;
|
||||||
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
||||||
public class VehicleHudOverlay {
|
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 ARMOR = ModUtils.loc("textures/screens/armor.png");
|
||||||
private static final ResourceLocation ENERGY = ModUtils.loc("textures/screens/energy.png");
|
private static final ResourceLocation ENERGY = ModUtils.loc("textures/screens/energy.png");
|
||||||
private static final ResourceLocation HEALTH = ModUtils.loc("textures/screens/armor_value.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();
|
int h = event.getWindow().getGuiScaledHeight();
|
||||||
Player player = Minecraft.getInstance().player;
|
Player player = Minecraft.getInstance().player;
|
||||||
|
|
||||||
if (!shouldRenderCrossHair(player)) return;
|
if (!shouldRenderHud(player)) return;
|
||||||
|
|
||||||
Entity vehicle = player.getVehicle();
|
Entity vehicle = player.getVehicle();
|
||||||
if (vehicle == null) return;
|
if (vehicle == null) return;
|
||||||
|
|
||||||
|
GuiGraphics guiGraphics = event.getGuiGraphics();
|
||||||
|
PoseStack poseStack = guiGraphics.pose();
|
||||||
|
|
||||||
|
poseStack.pushPose();
|
||||||
|
|
||||||
RenderSystem.disableDepthTest();
|
RenderSystem.disableDepthTest();
|
||||||
RenderSystem.depthMask(false);
|
RenderSystem.depthMask(false);
|
||||||
RenderSystem.enableBlend();
|
RenderSystem.enableBlend();
|
||||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||||
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||||
GuiGraphics guiGraphics = event.getGuiGraphics();
|
|
||||||
|
|
||||||
guiGraphics.pose().pushPose();
|
int compatHeight = getArmorPlateCompatHeight(player);
|
||||||
|
|
||||||
if (vehicle instanceof EnergyVehicleEntity energyVehicleEntity) {
|
if (vehicle instanceof EnergyVehicleEntity energyVehicleEntity) {
|
||||||
energy = energyVehicleEntity.getEnergy();
|
float energy = energyVehicleEntity.getEnergy();
|
||||||
maxEnergy = energyVehicleEntity.getMaxEnergy();
|
float maxEnergy = energyVehicleEntity.getMaxEnergy();
|
||||||
guiGraphics.blit(ENERGY, w - 96, h - 28, 0, 0, 12, 12, 12, 12);
|
guiGraphics.blit(ENERGY, 10, h - 22 - compatHeight, 0, 0, 8, 8, 8, 8);
|
||||||
guiGraphics.blit(HEALTH_FRAME, w - 83, h - 26, 0, 0, 80, 8, 80, 8);
|
guiGraphics.blit(HEALTH_FRAME, 20, h - 21 - compatHeight, 0, 0, 60, 6, 60, 6);
|
||||||
guiGraphics.blit(HEALTH, w - 83, h - 26, 0, 0, (int) (80 * energy / maxEnergy), 8, 80, 8);
|
guiGraphics.blit(HEALTH, 20, h - 21 - compatHeight, 0, 0, (int) (60 * energy / maxEnergy), 6, 60, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vehicle instanceof VehicleEntity pVehicle) {
|
if (vehicle instanceof VehicleEntity pVehicle) {
|
||||||
health = pVehicle.getHealth();
|
float health = pVehicle.getHealth();
|
||||||
maxHealth = pVehicle.getMaxHealth();
|
float maxHealth = pVehicle.getMaxHealth();
|
||||||
guiGraphics.blit(ARMOR, w - 96, h - 14, 0, 0, 12, 12, 12, 12);
|
guiGraphics.blit(ARMOR, 10, h - 13 - compatHeight, 0, 0, 8, 8, 8, 8);
|
||||||
guiGraphics.blit(HEALTH_FRAME, w - 83, h - 12, 0, 0, 80, 8, 80, 8);
|
guiGraphics.blit(HEALTH_FRAME, 20, h - 12 - compatHeight, 0, 0, 60, 6, 60, 6);
|
||||||
guiGraphics.blit(HEALTH, w - 83, h - 12, 0, 0, (int) (80 * health / maxHealth), 8, 80, 8);
|
guiGraphics.blit(HEALTH, 20, h - 12 - compatHeight, 0, 0, (int) (60 * health / maxHealth), 6, 60, 6);
|
||||||
}
|
}
|
||||||
guiGraphics.pose().popPose();
|
poseStack.popPose();
|
||||||
|
|
||||||
PoseStack poseStack = event.getGuiGraphics().pose();
|
|
||||||
|
|
||||||
if (vehicle instanceof IArmedVehicleEntity iVehicle && iVehicle.getAmmoCount(player) != -1) {
|
if (vehicle instanceof IArmedVehicleEntity iVehicle && iVehicle.getAmmoCount(player) != -1) {
|
||||||
|
|
||||||
boolean iCharge = iVehicle instanceof IChargeEntity;
|
boolean iCharge = iVehicle instanceof IChargeEntity;
|
||||||
|
|
||||||
// 渲染当前弹药量
|
// 渲染当前弹药量
|
||||||
poseStack.pushPose();
|
poseStack.pushPose();
|
||||||
poseStack.scale(1.5f, 1.5f, 1f);
|
poseStack.scale(1.5f, 1.5f, 1f);
|
||||||
|
|
||||||
float v = h / 1.5f - (iCharge ? 42 : 29) / 1.5f;
|
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)) {
|
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;
|
if (player == null) return false;
|
||||||
return !player.isSpectator()
|
return !player.isSpectator() && (player.getVehicle() != null && player.getVehicle() instanceof VehicleEntity);
|
||||||
&& (player.getVehicle() != null && player.getVehicle() instanceof VehicleEntity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getVehicleAmmoType(ItemStack stack, IArmedVehicleEntity iVehicle) {
|
private static String getVehicleAmmoType(ItemStack stack, IArmedVehicleEntity iVehicle) {
|
||||||
|
@ -136,4 +131,11 @@ public class VehicleHudOverlay {
|
||||||
}
|
}
|
||||||
return "";
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
||||||
public class VehicleMgHudOverlay {
|
public class VehicleMgHudOverlay {
|
||||||
public static float indicatorPosH = 0;
|
|
||||||
|
|
||||||
@SubscribeEvent(priority = EventPriority.NORMAL)
|
@SubscribeEvent(priority = EventPriority.NORMAL)
|
||||||
public static void eventHandler(RenderGuiEvent.Pre event) {
|
public static void eventHandler(RenderGuiEvent.Pre event) {
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
package com.atsuishio.superbwarfare.entity;
|
package com.atsuishio.superbwarfare.entity;
|
||||||
|
|
||||||
public interface IHelicopterEntity extends IArmedVehicleEntity {
|
public interface IHelicopterEntity extends IArmedVehicleEntity {
|
||||||
|
|
||||||
float getRotX(float tickDelta);
|
float getRotX(float tickDelta);
|
||||||
|
|
||||||
float getRotY(float tickDelta);
|
float getRotY(float tickDelta);
|
||||||
|
|
||||||
float getRotZ(float tickDelta);
|
float getRotZ(float tickDelta);
|
||||||
|
|
||||||
float getPower();
|
float getPower();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue