优化火炮HUD

This commit is contained in:
Atsuihsio 2025-03-11 17:16:35 +08:00
parent e58c8292df
commit 0f004b494e
6 changed files with 132 additions and 80 deletions

View file

@ -1,14 +1,21 @@
package com.atsuishio.superbwarfare.client.overlay; package com.atsuishio.superbwarfare.client.overlay;
import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.client.RenderHelper;
import com.atsuishio.superbwarfare.entity.vehicle.AnnihilatorEntity; import com.atsuishio.superbwarfare.entity.vehicle.AnnihilatorEntity;
import com.atsuishio.superbwarfare.entity.vehicle.Mk42Entity;
import com.atsuishio.superbwarfare.entity.vehicle.Mle1934Entity;
import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.FormatTool;
import com.atsuishio.superbwarfare.tools.InventoryTool;
import com.atsuishio.superbwarfare.tools.TraceTool; import com.atsuishio.superbwarfare.tools.TraceTool;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack; 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.Minecraft;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.GameRenderer;
@ -29,6 +36,7 @@ import org.joml.Math;
import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit; import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit;
import static com.atsuishio.superbwarfare.client.overlay.VehicleHudOverlay.renderKillIndicator; import static com.atsuishio.superbwarfare.client.overlay.VehicleHudOverlay.renderKillIndicator;
import static com.atsuishio.superbwarfare.client.overlay.VehicleHudOverlay.renderKillIndicator3P;
@Mod.EventBusSubscriber(value = Dist.CLIENT) @Mod.EventBusSubscriber(value = Dist.CLIENT)
public class CannonHudOverlay { public class CannonHudOverlay {
@ -41,12 +49,13 @@ public class CannonHudOverlay {
Player player = mc.player; Player player = mc.player;
GuiGraphics guiGraphics = event.getGuiGraphics(); GuiGraphics guiGraphics = event.getGuiGraphics();
PoseStack poseStack = guiGraphics.pose(); PoseStack poseStack = guiGraphics.pose();
Camera camera = mc.gameRenderer.getMainCamera();
Vec3 cameraPos = camera.getPosition();
if (!shouldRenderCrossHair(player)) return; if (!shouldRenderCrossHair(player)) return;
Entity cannon = player.getVehicle(); Entity vehicle = player.getVehicle();
if (cannon == null) return; if (vehicle instanceof CannonEntity cannonEntity && cannonEntity instanceof VehicleEntity cannon) {
poseStack.pushPose(); poseStack.pushPose();
RenderSystem.disableDepthTest(); RenderSystem.disableDepthTest();
RenderSystem.depthMask(false); RenderSystem.depthMask(false);
@ -74,6 +83,7 @@ public class CannonHudOverlay {
event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.literal(pitch), w / 2 + 157 - widthP, h / 2 - 4, -1, false); event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.literal(pitch), w / 2 + 157 - widthP, h / 2 - 4, -1, false);
poseStack.popPose(); poseStack.popPose();
if (Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON || ClientEventHandler.zoomVehicle) {
float fovAdjust = (float) 70 / Minecraft.getInstance().options.fov().get(); float fovAdjust = (float) 70 / Minecraft.getInstance().options.fov().get();
float f = (float) Math.min(w, h); float f = (float) Math.min(w, h);
@ -122,10 +132,51 @@ public class CannonHudOverlay {
} else { } else {
preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/cannon/cannon_crosshair_notzoom.png"), k, l, 0, 0.0F, i, j, i, j); preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/cannon/cannon_crosshair_notzoom.png"), k, l, 0, 0.0F, i, j, i, j);
} }
renderKillIndicator(guiGraphics, w, h); renderKillIndicator(guiGraphics, w, h);
} else if (Minecraft.getInstance().options.getCameraType() == CameraType.THIRD_PERSON_BACK && !ClientEventHandler.zoomVehicle) {
Vec3 p = RenderHelper.worldToScreen(new Vec3(Mth.lerp(event.getPartialTick(), player.xo, player.getX()), Mth.lerp(event.getPartialTick(), player.yo, player.getY()),
Mth.lerp(event.getPartialTick(), player.zo, player.getZ())).add(cannon.getViewVector(event.getPartialTick()).scale(128)), cameraPos);
// 第三人称准星
if (p != null) {
poseStack.pushPose();
float x = (float) p.x;
float y = (float) p.y;
poseStack.pushPose();
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/drone.png"), x - 12, y - 12, 0, 0, 24, 24, 24, 24);
renderKillIndicator3P(guiGraphics, x - 7.5f + (float) (2 * (Math.random() - 0.5f)), y - 7.5f + (float) (2 * (Math.random() - 0.5f)));
poseStack.pushPose();
poseStack.translate(x, y, 0);
poseStack.scale(0.75f, 0.75f, 1);
if (player.getVehicle() instanceof Mk42Entity || player.getVehicle() instanceof Mle1934Entity) {
if (cannonEntity.getWeaponIndex(0) == 0) {
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("AP SHELL " + (InventoryTool.hasCreativeAmmoBox(player) ? "" : cannonEntity.getAmmoCount(player))), 30, -9, -1, false);
} else {
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("HE SHELL " + (InventoryTool.hasCreativeAmmoBox(player) ? "" : cannonEntity.getAmmoCount(player))), 30, -9, -1, false);
}
}
// 歼灭者
if (player.getVehicle() instanceof AnnihilatorEntity annihilatorEntity) {
guiGraphics.drawString(mc.font, Component.literal("LASER " + (FormatTool.format0D((double) (100 * annihilatorEntity.getEnergy()) / annihilatorEntity.getMaxEnergy()) + "")), 30, -9, -1, false);
}
double heal = 1 - cannon.getHealth() / cannon.getMaxHealth();
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("HP " +
FormatTool.format0D(100 * cannon.getHealth() / cannon.getMaxHealth())), 30, 1, Mth.hsvToRgb(0F, (float) heal, 1.0F), false);
poseStack.popPose(); poseStack.popPose();
poseStack.popPose();
poseStack.popPose();
}
}
poseStack.popPose();
}
} }
private static boolean shouldRenderCrossHair(Player player) { private static boolean shouldRenderCrossHair(Player player) {

View file

@ -507,7 +507,7 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity,
turretTurnSound(diffX, diffY, 0.8f); turretTurnSound(diffX, diffY, 0.8f);
this.setYRot(this.getYRot() + Mth.clamp(0.5f * diffY, -0.6f, 0.6f)); this.setYRot(this.getYRot() + Mth.clamp(0.5f * diffY, -0.6f, 0.6f));
this.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(diffX, -2f, 2f), -45, 5f)); this.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(diffX, -0.8f, 0.8f), -45, 5f));
} }
public void autoAim() { public void autoAim() {

View file

@ -388,11 +388,8 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity
@Override @Override
public int getAmmoCount(Player player) { public int getAmmoCount(Player player) {
if (player.getMainHandItem().getItem() instanceof CannonShellItem) { var ammo = getWeaponIndex(0) == 0 ? ModItems.AP_5_INCHES.get() : ModItems.HE_5_INCHES.get();
return player.getMainHandItem().getCount(); return InventoryTool.countItem(player.getInventory().items, ammo);
} else {
return -1;
}
} }
@Override @Override

View file

@ -510,11 +510,8 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt
@Override @Override
public int getAmmoCount(Player player) { public int getAmmoCount(Player player) {
if (player.getMainHandItem().getItem() instanceof CannonShellItem) { var ammo = getWeaponIndex(0) == 0 ? ModItems.AP_5_INCHES.get() : ModItems.HE_5_INCHES.get();
return player.getMainHandItem().getCount(); return InventoryTool.countItem(player.getInventory().items, ammo);
} else {
return -1;
}
} }
@Override @Override

View file

@ -1,6 +1,7 @@
package com.atsuishio.superbwarfare.mixins; package com.atsuishio.superbwarfare.mixins;
import com.atsuishio.superbwarfare.entity.vehicle.*; import com.atsuishio.superbwarfare.entity.vehicle.*;
import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
@ -118,6 +119,12 @@ public abstract class CameraMixin {
} }
return; return;
} }
if (player.getVehicle() instanceof CannonEntity && (Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON || ClientEventHandler.zoomVehicle)) {
setRotation(Mth.lerp(partialTicks, player.yRotO, player.getYRot()), Mth.lerp(partialTicks, player.xRotO, player.getXRot()));
setPosition(Mth.lerp(partialTicks, player.xo, player.getX()), Mth.lerp(partialTicks, player.yo + player.getEyeHeight(), player.getEyeY()), Mth.lerp(partialTicks, player.zo, player.getZ()));
info.cancel();
}
} }
} }

View file

@ -18,9 +18,9 @@
"paoguan": { "paoguan": {
"position": { "position": {
"0.0": [0, 0, 0], "0.0": [0, 0, 0],
"0.05": [0, 0, 11], "0.0167": [0, 0, 11],
"0.4917": [0, 0, 0], "0.2917": [0, 0, 0],
"0.6667": [0, 0, 0] "0.6583": [0, 0, 0]
} }
}, },
"flare": { "flare": {