调整渲染顺序
This commit is contained in:
parent
ea691a7d5f
commit
57653ff0a0
2 changed files with 16 additions and 28 deletions
|
@ -2,12 +2,10 @@ package com.atsuishio.superbwarfare.client.overlay;
|
|||
|
||||
import com.atsuishio.superbwarfare.ModUtils;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.Lav150Entity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.MobileVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.CameraType;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
|
@ -16,7 +14,6 @@ import net.minecraft.network.chat.Component;
|
|||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RenderGuiEvent;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
|
@ -30,26 +27,25 @@ import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit;
|
|||
|
||||
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
||||
public class LandArmorHudOverlay {
|
||||
|
||||
private static float scopeScale = 1;
|
||||
private static final ResourceLocation FRAME = ModUtils.loc("textures/screens/land/tv_frame.png");
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
public static void eventHandler(RenderGuiEvent.Pre event) {
|
||||
int w = event.getWindow().getGuiScaledWidth();
|
||||
int h = event.getWindow().getGuiScaledHeight();
|
||||
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
Player player = mc.player;
|
||||
Camera camera = mc.gameRenderer.getMainCamera();
|
||||
Vec3 cameraPos = camera.getPosition();
|
||||
GuiGraphics guiGraphics = event.getGuiGraphics();
|
||||
PoseStack poseStack = guiGraphics.pose();
|
||||
|
||||
if (player == null) return;
|
||||
if (player.getVehicle() instanceof Lav150Entity lav150 && player.getVehicle() instanceof MobileVehicleEntity mobileVehicle && lav150.isDriver(player)) {
|
||||
if (player.getVehicle() instanceof Lav150Entity lav150 && lav150.isDriver(player)) {
|
||||
poseStack.pushPose();
|
||||
|
||||
poseStack.translate(-6 * ClientEventHandler.turnRot[1],-6 * ClientEventHandler.turnRot[0],0);
|
||||
poseStack.translate(-6 * ClientEventHandler.turnRot[1], -6 * ClientEventHandler.turnRot[0], 0);
|
||||
RenderSystem.disableDepthTest();
|
||||
RenderSystem.depthMask(false);
|
||||
RenderSystem.enableBlend();
|
||||
|
@ -68,21 +64,19 @@ public class LandArmorHudOverlay {
|
|||
if (Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON) {
|
||||
int addW = (w / h) * 48;
|
||||
int addH = (w / h) * 27;
|
||||
// TODO 把黑边框移动到最底层
|
||||
preciseBlit(guiGraphics, FRAME, (float) -addW / 2, (float) -addH / 2,1, 0, 0.0F, w + addW, h + addH, w + addW, h + addH);
|
||||
preciseBlit(guiGraphics, FRAME, (float) -addW / 2, (float) -addH / 2, 10, 0, 0.0F, w + addW, h + addH, w + addW, h + addH);
|
||||
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/helicopter/heli_base.png"), k, l, 0, 0.0F, i, j, i, j);
|
||||
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/compass.png"), (float) w / 2 - 128, (float) 6, 128 + ((float) 64 / 45 * player.getYRot()), 0, 256, 16, 512, 16);
|
||||
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/helicopter/speed_frame.png"), (float) w / 2 - 144, (float) h / 2 - 6, 0, 0, 50, 18, 50, 18);
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal(new DecimalFormat("##").format(length(mobileVehicle.getDeltaMovement().x, mobileVehicle.getDeltaMovement().y, mobileVehicle.getDeltaMovement().z) * 72) + "KM/H"),
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal(new DecimalFormat("##").format(lav150.getDeltaMovement().length() * 72) + "KM/H"),
|
||||
w / 2 - 140, h / 2, 0x66FF00, false);
|
||||
if (mobileVehicle.getEnergy() < 0.02 * mobileVehicle.getMaxEnergy()) {
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal( "NO POWER!"),
|
||||
if (lav150.getEnergy() < 0.02 * lav150.getMaxEnergy()) {
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("NO POWER!"),
|
||||
w / 2 - 144, h / 2 + 14, -65536, false);
|
||||
} else if (mobileVehicle.getEnergy() < 0.2 * mobileVehicle.getMaxEnergy()) {
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal( "LOW POWER"),
|
||||
} else if (lav150.getEnergy() < 0.2 * lav150.getMaxEnergy()) {
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("LOW POWER"),
|
||||
w / 2 - 144, h / 2 + 14, 0xFF6B00, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
poseStack.popPose();
|
||||
|
@ -90,10 +84,4 @@ public class LandArmorHudOverlay {
|
|||
scopeScale = 0.7f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static double length(double x, double y, double z) {
|
||||
return Math.sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,17 +60,17 @@ public class VehicleHudOverlay {
|
|||
if (vehicle instanceof EnergyVehicleEntity energyVehicleEntity) {
|
||||
float energy = energyVehicleEntity.getEnergy();
|
||||
float maxEnergy = energyVehicleEntity.getMaxEnergy();
|
||||
guiGraphics.blit(ENERGY, 10, h - 22 - compatHeight,100, 0, 0, 8, 8, 8, 8);
|
||||
guiGraphics.blit(HEALTH_FRAME, 20, h - 21 - compatHeight,100, 0, 0, 60, 6, 60, 6);
|
||||
guiGraphics.blit(HEALTH, 20, h - 21 - compatHeight,100, 0, 0, (int) (60 * energy / maxEnergy), 6, 60, 6);
|
||||
guiGraphics.blit(ENERGY, 10, h - 22 - compatHeight, 100, 0, 0, 8, 8, 8, 8);
|
||||
guiGraphics.blit(HEALTH_FRAME, 20, h - 21 - compatHeight, 100, 0, 0, 60, 6, 60, 6);
|
||||
guiGraphics.blit(HEALTH, 20, h - 21 - compatHeight, 100, 0, 0, (int) (60 * energy / maxEnergy), 6, 60, 6);
|
||||
}
|
||||
|
||||
if (vehicle instanceof VehicleEntity pVehicle) {
|
||||
float health = pVehicle.getHealth();
|
||||
float maxHealth = pVehicle.getMaxHealth();
|
||||
guiGraphics.blit(ARMOR, 10, h - 13 - compatHeight,100, 0, 0, 8, 8, 8, 8);
|
||||
guiGraphics.blit(HEALTH_FRAME, 20, h - 12 - compatHeight,100, 0, 0, 60, 6, 60, 6);
|
||||
guiGraphics.blit(HEALTH, 20, h - 12 - compatHeight,100, 0, 0, (int) (60 * health / maxHealth), 6, 60, 6);
|
||||
guiGraphics.blit(ARMOR, 10, h - 13 - compatHeight, 100, 0, 0, 8, 8, 8, 8);
|
||||
guiGraphics.blit(HEALTH_FRAME, 20, h - 12 - compatHeight, 100, 0, 0, 60, 6, 60, 6);
|
||||
guiGraphics.blit(HEALTH, 20, h - 12 - compatHeight, 100, 0, 0, (int) (60 * health / maxHealth), 6, 60, 6);
|
||||
}
|
||||
poseStack.popPose();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue