From 50e174c9dc5ddd138ea3d8ed4f46d7d2752bec05 Mon Sep 17 00:00:00 2001 From: Atsuihsio <842960157@qq.com> Date: Sat, 18 Jan 2025 02:18:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=81=AB=E7=82=AEGUI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../superbwarfare/client/gui/RangeHelper.java | 4 +- .../client/overlay/CannonHudOverlay.java | 67 ++++++++++-------- .../superbwarfare/entity/MortarEntity.java | 4 +- .../textures/screens/cannon/cannon_pitch.png | Bin 0 -> 220 bytes .../screens/cannon/cannon_pitch_ind.png | Bin 0 -> 167 bytes .../textures/screens/cannon/indicator.png | Bin 1225 -> 148 bytes .../textures/screens/compass_white.png | Bin 0 -> 776 bytes .../textures/screens/roll_ind_white.png | Bin 0 -> 196 bytes 8 files changed, 41 insertions(+), 34 deletions(-) create mode 100644 src/main/resources/assets/superbwarfare/textures/screens/cannon/cannon_pitch.png create mode 100644 src/main/resources/assets/superbwarfare/textures/screens/cannon/cannon_pitch_ind.png create mode 100644 src/main/resources/assets/superbwarfare/textures/screens/compass_white.png create mode 100644 src/main/resources/assets/superbwarfare/textures/screens/roll_ind_white.png diff --git a/src/main/java/com/atsuishio/superbwarfare/client/gui/RangeHelper.java b/src/main/java/com/atsuishio/superbwarfare/client/gui/RangeHelper.java index 4b99d963a..5c0b2cb16 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/gui/RangeHelper.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/gui/RangeHelper.java @@ -4,7 +4,7 @@ import net.minecraft.core.BlockPos; public class RangeHelper { - public static final int MAX_RANGE = 512; + public static final int MAX_RANGE = 1145; /** * 计算迫击炮理论水平射程 @@ -12,7 +12,7 @@ public class RangeHelper { * @param thetaDegrees 发射角度(以度为单位),需要根据实际情况修改 */ public static double getRange(double thetaDegrees) { - double initialVelocity = 8.0; // 初始速度 8 m/s + double initialVelocity = 14.741; // 初始速度 8 m/s double thetaRadians = Math.toRadians(thetaDegrees); // 将角度转换为弧度 double gravity = 0.05; // 重力加速度 double velocityDecay = 0.99; // 速度衰减系数 diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/CannonHudOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/CannonHudOverlay.java index 48c20be01..9d5255737 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/CannonHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/CannonHudOverlay.java @@ -1,16 +1,16 @@ package com.atsuishio.superbwarfare.client.overlay; import com.atsuishio.superbwarfare.ModUtils; -import com.atsuishio.superbwarfare.client.RenderHelper; import com.atsuishio.superbwarfare.entity.vehicle.AnnihilatorEntity; import com.atsuishio.superbwarfare.entity.vehicle.ICannonEntity; -import com.atsuishio.superbwarfare.entity.vehicle.Mk42Entity; -import com.atsuishio.superbwarfare.entity.vehicle.Mle1934Entity; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.tools.TraceTool; 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.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; @@ -24,9 +24,12 @@ import net.minecraftforge.client.event.RenderGuiEvent; import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; +import org.joml.Math; import java.text.DecimalFormat; +import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit; + @Mod.EventBusSubscriber(value = Dist.CLIENT) public class CannonHudOverlay { @@ -34,13 +37,19 @@ public class CannonHudOverlay { public static void eventHandler(RenderGuiEvent.Pre event) { int w = event.getWindow().getGuiScaledWidth(); int h = event.getWindow().getGuiScaledHeight(); - Player player = Minecraft.getInstance().player; + 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 (!shouldRenderCrossHair(player)) return; Entity cannon = player.getVehicle(); if (cannon == null) return; + poseStack.pushPose(); RenderSystem.disableDepthTest(); RenderSystem.depthMask(false); RenderSystem.enableBlend(); @@ -48,29 +57,27 @@ public class CannonHudOverlay { RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); RenderSystem.setShaderColor(1, 1, 1, 1); - float indicatorPosH = 0; - if (cannon instanceof Mk42Entity) { - indicatorPosH = 1.3f; - } + preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/compass_white.png"), (float) w / 2 - 128, (float) 10, 128 + ((float) 64 / 45 * (Mth.lerp(event.getPartialTick(), cannon.yRotO, cannon.getYRot()))), 0, 256, 16, 512, 16); + preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/roll_ind_white.png"), w / 2 - 4, 27, 0, 0.0F, 8, 8, 8, 8); - if (cannon instanceof Mle1934Entity) { - indicatorPosH = 1.2f; - } + String angle = new DecimalFormat("#0.0").format(Mth.lerp(event.getPartialTick(), cannon.yRotO, cannon.getYRot())); + int width = Minecraft.getInstance().font.width(angle); + event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.literal(angle), w / 2 - width / 2, 40, -1, false); - if (cannon instanceof AnnihilatorEntity) { - indicatorPosH = cannon.getEntityData().get(AnnihilatorEntity.OFFSET_ANGLE); - } + preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/cannon/cannon_pitch.png"), w / 2 + 166, h / 2 - 64, 0, 0.0F, 8, 128, 8, 128); + + String pitch = new DecimalFormat("#0.0").format(-Mth.lerp(event.getPartialTick(), cannon.xRotO, cannon.getXRot())); + int widthP = Minecraft.getInstance().font.width(pitch); + + poseStack.pushPose(); + + event.getGuiGraphics().pose().translate(0, Mth.lerp(event.getPartialTick(), cannon.xRotO, cannon.getXRot()) * 0.7, 0); + preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/cannon/cannon_pitch_ind.png"), w / 2 + 158, h / 2 - 4, 0, 0.0F, 8, 8, 8, 8); + event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.literal(pitch), w / 2 + 157 - widthP, h / 2 - 4, -1, false); + poseStack.popPose(); - float yRotOffset = Mth.lerp(event.getPartialTick(), player.yRotO, player.getYRot()); - float xRotOffset = Mth.lerp(event.getPartialTick(), player.xRotO, player.getXRot()); - float diffY = cannon.getViewYRot(event.getPartialTick()) - yRotOffset; - float diffX = cannon.getViewXRot(event.getPartialTick()) - xRotOffset + indicatorPosH; float fovAdjust = (float) 70 / Minecraft.getInstance().options.fov().get(); - if (diffY > 180.0f) { - diffY -= 360.0f; - } else if (diffY < -180.0f) { - diffY += 360.0f; - } + float f = (float) Math.min(w, h); float f1 = Math.min((float) w / f, (float) h / f) * fovAdjust; int i = Mth.floor(f * f1); @@ -104,18 +111,18 @@ public class CannonHudOverlay { } } if (cannon instanceof AnnihilatorEntity) { - RenderHelper.preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/cannon/laser_cannon_crosshair.png"), k, l, 0, 0.0F, i, j, i, j); + preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/cannon/laser_cannon_crosshair.png"), k, l, 0, 0.0F, i, j, i, j); } else { - RenderHelper.preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/cannon/cannon_crosshair.png"), k, l, 0, 0.0F, i, j, i, j); + preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/cannon/cannon_crosshair.png"), k, l, 0, 0.0F, i, j, i, j); } - RenderHelper.preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/cannon/indicator.png"), k + (float) Math.tan(Mth.clamp(Mth.DEG_TO_RAD * diffY, -1.5, 1.5)) * 5 * i / 1.4f * (90 - Math.abs(player.getXRot())) / 90, l + (float) Math.tan(Mth.clamp(Mth.DEG_TO_RAD * diffX, -1.5, 1.5)) * 5 * j / 1.4f, 0, 0.0F, i, j, i, j); + float diffY = -Mth.wrapDegrees(Mth.lerp(event.getPartialTick(), player.yHeadRotO, player.getYHeadRot()) - Mth.lerp(event.getPartialTick(), cannon.yRotO, cannon.getYRot())); + + preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/cannon/indicator.png"), w / 2 - 4.3f + 0.45f * diffY, h / 2 - 10, 0, 0.0F, 8, 8, 8, 8); } else { - RenderHelper.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); } - event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.pitch") - .append(Component.literal(new DecimalFormat("##.#").format(-cannon.getXRot()) + "°")), - w / 2 + 14, h / 2 - 29, -1, false); + poseStack.popPose(); } private static boolean shouldRenderCrossHair(Player player) { diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/MortarEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/MortarEntity.java index fada00af8..3dff69dff 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/MortarEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/MortarEntity.java @@ -164,7 +164,7 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity { if (level instanceof ServerLevel server) { MortarShellEntity entityToSpawn = new MortarShellEntity(player, level); entityToSpawn.setPos(this.getX(), this.getEyeY(), this.getZ()); - entityToSpawn.shoot(this.getLookAngle().x, this.getLookAngle().y, this.getLookAngle().z, 8, (float) 0.3); + entityToSpawn.shoot(this.getLookAngle().x, this.getLookAngle().y, this.getLookAngle().z, 14.741f, (float) 0.3); level.addFreshEntity(entityToSpawn); server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, (this.getX() + 3 * this.getLookAngle().x), (this.getY() + 0.1 + 3 * this.getLookAngle().y), (this.getZ() + 3 * this.getLookAngle().z), 8, 0.4, 0.4, 0.4, 0.007); @@ -212,7 +212,7 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity { this.look(EntityAnchorArgument.Anchor.EYES, new Vec3(targetX, targetY, targetZ)); double[] angles = new double[2]; - boolean flag = RangeHelper.canReachTarget(8.0, 0.05, 0.99, + boolean flag = RangeHelper.canReachTarget(14.741, 0.05, 0.99, new BlockPos((int) this.getX(), (int) this.getEyeY(), (int) this.getZ()), new BlockPos(targetX, targetY, targetZ), angles); diff --git a/src/main/resources/assets/superbwarfare/textures/screens/cannon/cannon_pitch.png b/src/main/resources/assets/superbwarfare/textures/screens/cannon/cannon_pitch.png new file mode 100644 index 0000000000000000000000000000000000000000..d829e89e8ba5645fb54a1bf5a1e43c359834d64c GIT binary patch literal 220 zcmeAS@N?(olHy`uVBq!ia0vp^91IMM3><7gR-d*xNPx4zBeIx*fm;}a85w5HkpRhg zx;TbpG`_ulkgGvK!1dyr|NkqaY}#Zd2`NpuXSFVdQ&MBb@0D~%2WB>pF literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/superbwarfare/textures/screens/cannon/cannon_pitch_ind.png b/src/main/resources/assets/superbwarfare/textures/screens/cannon/cannon_pitch_ind.png new file mode 100644 index 0000000000000000000000000000000000000000..6a32e609a8d71d392d4ff66a6b9fad32b960452f GIT binary patch literal 167 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9GG!XV7ZFl&wkP%zTd z#WBR9ckd-fz6J#W=Zk%ECpEsuzgqh0lx(V%(BJ4w;vNikuVzT*tGra|wo<6H>R^dU z;jr-FPhfq?nEh1krSLqZMT|S*7_)L17Z-A+BwvmD*|}=v$NhJodntKdvf6(eXbFR- LtDnm{r-UW|aRoKE literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/superbwarfare/textures/screens/cannon/indicator.png b/src/main/resources/assets/superbwarfare/textures/screens/cannon/indicator.png index 0a0a3c56ed4573bac83aec45a9c74edc056fe499..48c8203757048ff5a37993068f0ad3c281db9d28 100644 GIT binary patch delta 134 zcmX@fIfYTNGr-TCmrII^fq{Y7)59eQNDF{42OE%-|NK93qM~>VgPW&|V~9m>a)Jb_ z2(z2YHch$G`iobL3=9nBxIUZlS6vXunz8V<(-y@WCc?QKc4t|572S;eoINh~Byw2J hde|1QsIr5Bf&IoBKfd@Q)OzJ+C#LOXFo<)BvASzL`?tDWLwV$8aR!EY>I@7E z6c`y8SUDLOG(4~b&H;tDebay2u=9NWsO|t(;@}8Oms~;&3;`1u7#f)!(T%+uA+Wt~$(69B^nOospf diff --git a/src/main/resources/assets/superbwarfare/textures/screens/compass_white.png b/src/main/resources/assets/superbwarfare/textures/screens/compass_white.png new file mode 100644 index 0000000000000000000000000000000000000000..ede46f73ba2f57150c05a685d8932f22748711d0 GIT binary patch literal 776 zcmeAS@N?(olHy`uVBq!ia0y~yU;#226gb#`WY0gYWk8Cvz$3Dlfr0M`2s2LA=96Y% zVA|#B;uumf=k48#eYXq*SOcsdaX+-49zSQ_gwQ2SXN9_=?-$42aP2W!d?LZW=Vk8V zRjamMt9rkek>PTL{bTu$H~Bx`wBEj*t-oMFROFryQMMynS5^T*4Hmo8os~Y8~@HWJ~V#2eQ!O(44=^2wYwQi7!=Md zW@Qj~yq$I5cUFcO(V?O5_hvIVsFnX{(0$LzV6b!5s-xxq7!;gCYc2mXZ<72xA$|Ad z{LHfl?I%3B$dphLci{f!^zQxN8E4!tnsLh4-ZntIj)vl)&Q{}4a(`qvuH2LcW= z?(g0C@7LT1f#*Yr9{A z8iUJ50fq*H*|Qm*{TImEX=`^^ii6?L{yAS6bHx9@Ui{PkNu*i*ZeEYM*2cIJaTHG?m-lXbn{Kag{3rYRtsD#t4L5Im;+~oFvpwdR{S%{qis7MGtJn_szvE#l zHvFeJ{UiU*o_dZa0uI2)t*W>@* z{JPwG|G!t~*X`f>f$f0XFGY=4>XE;`hTEUKw0{3D&uMjkugZHdgG^wO$zqVX>tty4 zZ^gx*tK64--tN&Vl{&?;A&Lg~g zE?n!aTF<5meo9f;Kr