diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/AircraftOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/AircraftOverlay.java index af0b0c81b..d45194db2 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/AircraftOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/AircraftOverlay.java @@ -87,8 +87,8 @@ public class AircraftOverlay implements LayeredDraw.Layer { Vec3 pos = cameraPos.add(mobileVehicle.getViewVector(partialTick).scale(192)); Vec3 posCross = aircraftEntity.shootPos(partialTick).add(aircraftEntity.shootVec(partialTick).scale(192)); - Vec3 p = VectorUtil.worldToScreen(pos, cameraPos); - Vec3 pCross = VectorUtil.worldToScreen(posCross, cameraPos); + Vec3 p = VectorUtil.worldToScreen(pos); + Vec3 pCross = VectorUtil.worldToScreen(posCross); // 投弹准星 if (mobileVehicle instanceof A10Entity a10Entity && weaponVehicle.getWeaponIndex(0) == 2 && (zoomVehicle || mc.options.getCameraType() != CameraType.FIRST_PERSON)) { @@ -96,9 +96,9 @@ public class AircraftOverlay implements LayeredDraw.Layer { Vec3 p1 = a10Entity.bombLandingPos; if (p0 != null && p1 != null) { Vec3 bombCross = p0.lerp(p1, partialTick); - pCross = VectorUtil.worldToScreen(bombCross, cameraPos); + pCross = VectorUtil.worldToScreen(bombCross); - if (pCross != null && zoomVehicle) { + if (zoomVehicle) { float f = (float) Math.min(screenWidth, screenHeight); float f1 = Math.min((float) screenWidth / f, (float) screenHeight / f); int i = Mth.floor(f * f1); @@ -126,7 +126,7 @@ public class AircraftOverlay implements LayeredDraw.Layer { } - if (p != null) { + { poseStack.pushPose(); float x = (float) p.x; float y = (float) p.y; @@ -243,7 +243,7 @@ public class AircraftOverlay implements LayeredDraw.Layer { } // 准星 - if (pCross != null) { + { poseStack.pushPose(); float x = (float) pCross.x; float y = (float) pCross.y; @@ -301,30 +301,28 @@ public class AircraftOverlay implements LayeredDraw.Layer { for (var e : entities) { Vec3 pos3 = new Vec3(Mth.lerp(partialTick, e.xo, e.getX()), Mth.lerp(partialTick, e.yo + e.getEyeHeight(), e.getEyeY()), Mth.lerp(partialTick, e.zo, e.getZ())); - Vec3 point = VectorUtil.worldToScreen(pos3, cameraPos); - if (point != null) { - boolean nearest = e == targetEntity; - boolean lockOn = a10Entity.locked && nearest; + Vec3 point = VectorUtil.worldToScreen(pos3); + boolean nearest = e == targetEntity; + boolean lockOn = a10Entity.locked && nearest; - poseStack.pushPose(); - float x = (float) point.x; - float y = (float) point.y; + poseStack.pushPose(); + float x = (float) point.x; + float y = (float) point.y; - if (lockOn) { - RenderHelper.preciseBlit(guiGraphics, FRAME_LOCK, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24); - } else if (nearest) { - lerpLock = Mth.lerp(partialTick, lerpLock, 2 * a10Entity.lockTime); - float lockTime = Mth.clamp(20 - lerpLock, 0, 20); - RenderHelper.preciseBlit(guiGraphics, IND_1, x - 12, y - 12 - lockTime, 24, 24, 0, 0, 24, 24, 24, 24); - RenderHelper.preciseBlit(guiGraphics, IND_2, x - 12, y - 12 + lockTime, 24, 24, 0, 0, 24, 24, 24, 24); - RenderHelper.preciseBlit(guiGraphics, IND_3, x - 12 - lockTime, y - 12, 24, 24, 0, 0, 24, 24, 24, 24); - RenderHelper.preciseBlit(guiGraphics, IND_4, x - 12 + lockTime, y - 12, 24, 24, 0, 0, 24, 24, 24, 24); - RenderHelper.preciseBlit(guiGraphics, FRAME_TARGET, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24); - } else { - RenderHelper.preciseBlit(guiGraphics, FRAME, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24); - } - poseStack.popPose(); + if (lockOn) { + RenderHelper.preciseBlit(guiGraphics, FRAME_LOCK, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24); + } else if (nearest) { + lerpLock = Mth.lerp(partialTick, lerpLock, 2 * a10Entity.lockTime); + float lockTime = Mth.clamp(20 - lerpLock, 0, 20); + RenderHelper.preciseBlit(guiGraphics, IND_1, x - 12, y - 12 - lockTime, 24, 24, 0, 0, 24, 24, 24, 24); + RenderHelper.preciseBlit(guiGraphics, IND_2, x - 12, y - 12 + lockTime, 24, 24, 0, 0, 24, 24, 24, 24); + RenderHelper.preciseBlit(guiGraphics, IND_3, x - 12 - lockTime, y - 12, 24, 24, 0, 0, 24, 24, 24, 24); + RenderHelper.preciseBlit(guiGraphics, IND_4, x - 12 + lockTime, y - 12, 24, 24, 0, 0, 24, 24, 24, 24); + RenderHelper.preciseBlit(guiGraphics, FRAME_TARGET, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24); + } else { + RenderHelper.preciseBlit(guiGraphics, FRAME, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24); } + poseStack.popPose(); } } 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 13407618f..fe6f2e594 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/CannonHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/CannonHudOverlay.java @@ -122,9 +122,7 @@ public class CannonHudOverlay implements LayeredDraw.Layer { } if (lookAtEntity) { var component = Component.translatable("tips.superbwarfare.drone.range").append(Component.literal(FormatTool.format1D(entityRange, "m "))); - if (lookingEntity.getDisplayName() != null) { - component.append(lookingEntity.getDisplayName()); - } + component.append(lookingEntity.getDisplayName()); guiGraphics.drawString(Minecraft.getInstance().font, component, w / 2 + 14, h / 2 - 20, -1, false); } else { if (blockRange > 511) { @@ -171,45 +169,43 @@ public class CannonHudOverlay implements LayeredDraw.Layer { renderKillIndicator(guiGraphics, w, h); } else if (Minecraft.getInstance().options.getCameraType() == CameraType.THIRD_PERSON_BACK && !ClientEventHandler.zoomVehicle) { Vec3 p = VectorUtil.worldToScreen(new Vec3(Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.xo, player.getX()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.yo, player.getY()), - Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.zo, player.getZ())).add(cannon.getViewVector(deltaTracker.getGameTimeDeltaPartialTick(true)).scale(128)), cameraPos); + Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.zo, player.getZ())).add(cannon.getViewVector(deltaTracker.getGameTimeDeltaPartialTick(true)).scale(128))); // 第三人称准星 - if (p != null) { - poseStack.pushPose(); - float x = (float) p.x; - float y = (float) p.y; + poseStack.pushPose(); + float x = (float) p.x; + float y = (float) p.y; - poseStack.pushPose(); - preciseBlit(guiGraphics, Mod.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(); + preciseBlit(guiGraphics, Mod.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.pushPose(); - poseStack.translate(x, y, 0); - poseStack.scale(0.75f, 0.75f, 1); + 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 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(); } + + // 歼灭者 + 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(); } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/DroneHudOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/DroneHudOverlay.java index eb9207f84..dd3d31090 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/DroneHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/DroneHudOverlay.java @@ -163,15 +163,13 @@ public class DroneHudOverlay implements LayeredDraw.Layer { List entities = SeekTool.seekLivingEntities(entity, entity.level(), 256, 30); for (var e : entities) { Vec3 pos = new Vec3(Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), e.xo, e.getX()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), e.yo + e.getEyeHeight(), e.getEyeY()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), e.zo, e.getZ())); - Vec3 point = VectorUtil.worldToScreen(pos, cameraPos); - if (point != null) { - poseStack.pushPose(); - float x = (float) point.x; - float y = (float) point.y; + Vec3 point = VectorUtil.worldToScreen(pos); + poseStack.pushPose(); + float x = (float) point.x; + float y = (float) point.y; - RenderHelper.preciseBlit(guiGraphics, FRAME, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24); - poseStack.popPose(); - } + RenderHelper.preciseBlit(guiGraphics, FRAME, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24); + poseStack.popPose(); } } @@ -200,12 +198,10 @@ public class DroneHudOverlay implements LayeredDraw.Layer { // 标记位置 Vec3 pos = new Vec3(targetX, targetY, targetZ); - Vec3 point = VectorUtil.worldToScreen(pos, cameraPos); - if (point != null) { - float x = (float) point.x; - float y = (float) point.y; - preciseBlit(guiGraphics, INDICATOR, Mth.clamp(x - 6, 0, w - 12), Mth.clamp(y - 6, 0, h - 12), 0, 0, 12, 12, 12, 12); - } + Vec3 point = VectorUtil.worldToScreen(pos); + float x = (float) point.x; + float y = (float) point.y; + preciseBlit(guiGraphics, INDICATOR, Mth.clamp(x - 6, 0, w - 12), Mth.clamp(y - 6, 0, h - 12), 0, 0, 12, 12, 12, 12); // 火炮位置 @@ -216,13 +212,11 @@ public class DroneHudOverlay implements LayeredDraw.Layer { Entity e = EntityFindUtil.findEntity(player.level(), t.getString("UUID")); if (e != null) { Vec3 posF = e.getBoundingBox().getCenter(); - Vec3 pointF = VectorUtil.worldToScreen(posF, cameraPos); - if (pointF != null) { - float xf = (float) pointF.x; - float yf = (float) pointF.y; + Vec3 pointF = VectorUtil.worldToScreen(posF); + float xf = (float) pointF.x; + float yf = (float) pointF.y; - preciseBlit(guiGraphics, FRIENDLY_INDICATOR, Mth.clamp(xf - 6, 0, w - 12), Mth.clamp(yf - 6, 0, h - 12), 0, 0, 12, 12, 12, 12); - } + preciseBlit(guiGraphics, FRIENDLY_INDICATOR, Mth.clamp(xf - 6, 0, w - 12), Mth.clamp(yf - 6, 0, h - 12), 0, 0, 12, 12, 12, 12); } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/HandsomeFrameOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/HandsomeFrameOverlay.java index 9f320bd9b..cc52eafd5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/HandsomeFrameOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/HandsomeFrameOverlay.java @@ -47,7 +47,6 @@ public class HandsomeFrameOverlay implements LayeredDraw.Layer { Player player = Minecraft.getInstance().player; PoseStack poseStack = guiGraphics.pose(); Camera camera = Minecraft.getInstance().gameRenderer.getMainCamera(); - Vec3 cameraPos = camera.getPosition(); if (player == null) return; ItemStack stack = player.getMainHandItem(); @@ -78,8 +77,7 @@ public class HandsomeFrameOverlay implements LayeredDraw.Layer { for (var e : allEntities) { Vec3 pos = new Vec3(Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), e.xo, e.getX()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), e.yo + e.getEyeHeight(), e.getEyeY()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), e.zo, e.getZ())); - Vec3 point = VectorUtil.worldToScreen(pos, cameraPos); - if (point == null) return; + Vec3 point = VectorUtil.worldToScreen(pos); boolean lockOn = e == targetEntity; boolean isNearestEntity = e == naerestEntity; diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java index 76591fb2a..f869448de 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java @@ -14,7 +14,6 @@ import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; -import net.minecraft.client.Camera; import net.minecraft.client.CameraType; import net.minecraft.client.DeltaTracker; import net.minecraft.client.Minecraft; @@ -54,8 +53,6 @@ public class HelicopterHudOverlay implements LayeredDraw.Layer { Minecraft mc = Minecraft.getInstance(); Player player = mc.player; - Camera camera = mc.gameRenderer.getMainCamera(); - Vec3 cameraPos = camera.getPosition(); PoseStack poseStack = guiGraphics.pose(); if (player == null) return; @@ -113,7 +110,7 @@ public class HelicopterHudOverlay implements LayeredDraw.Layer { lerpVy = (float) Mth.lerp(0.021f * partialTick, lerpVy, mobileVehicle.getDeltaMovement().y()); preciseBlit(guiGraphics, Mod.loc("textures/screens/helicopter/heli_vy_move.png"), (float) w / 2 + 138, ((float) h / 2 - 3 - Math.max(lerpVy * 20, -24) * 2.5f), 0, 0, 8, 8, 8, 8); guiGraphics.drawString(Minecraft.getInstance().font, Component.literal(FormatTool.format0D(lerpVy * 20, "m/s")), - w / 2 + 146, (int) (h / 2 - 3 - Math.max(lerpVy * 20, -24) * 2.5), (lerpVy * 20 < -24 || ((lerpVy * 20 < -10 || (lerpVy * 20 < -1 && length(mobileVehicle.getDeltaMovement().x, mobileVehicle.getDeltaMovement().y, mobileVehicle.getDeltaMovement().z) * 72 > 100)) && height < 36) || (length(mobileVehicle.getDeltaMovement().x, mobileVehicle.getDeltaMovement().y, mobileVehicle.getDeltaMovement().z) * 72 > 40 && blockInWay < 72) ? -65536 : 0x66FF00), false); + w / 2 + 146, (int) (h / 2F - 3 - Math.max(lerpVy * 20, -24) * 2.5), (lerpVy * 20 < -24 || ((lerpVy * 20 < -10 || (lerpVy * 20 < -1 && length(mobileVehicle.getDeltaMovement().x, mobileVehicle.getDeltaMovement().y, mobileVehicle.getDeltaMovement().z) * 72 > 100)) && height < 36) || (length(mobileVehicle.getDeltaMovement().x, mobileVehicle.getDeltaMovement().y, mobileVehicle.getDeltaMovement().z) * 72 > 40 && blockInWay < 72) ? -65536 : 0x66FF00), false); guiGraphics.drawString(Minecraft.getInstance().font, Component.literal(FormatTool.format0D(mobileVehicle.getY())), w / 2 + 104, h / 2, 0x66FF00, false); preciseBlit(guiGraphics, Mod.loc("textures/screens/helicopter/speed_frame.png"), (float) w / 2 - 144, (float) h / 2 - 6, 0, 0, 50, 18, 50, 18); @@ -152,44 +149,42 @@ public class HelicopterHudOverlay implements LayeredDraw.Layer { } Vec3 pos = iHelicopterEntity.shootPos(partialTick).add(iHelicopterEntity.shootVec(partialTick).scale(192)); - Vec3 p = VectorUtil.worldToScreen(pos, cameraPos); + Vec3 p = VectorUtil.worldToScreen(pos); - if (p != null) { + poseStack.pushPose(); + float x = (float) p.x; + float y = (float) p.y; + + + if (Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON) { + preciseBlit(guiGraphics, Mod.loc("textures/screens/helicopter/crosshair_ind.png"), x - 8, y - 8, 0, 0, 16, 16, 16, 16); + renderKillIndicator(guiGraphics, x - 7.5f + (float) (2 * (Math.random() - 0.5f)), y - 7.5f + (float) (2 * (Math.random() - 0.5f))); + } else if (mc.options.getCameraType() != CameraType.FIRST_PERSON) { poseStack.pushPose(); - float x = (float) p.x; - float y = (float) p.y; + poseStack.rotateAround(Axis.ZP.rotationDegrees(iHelicopterEntity.getRotZ(partialTick)), x, y, 0); + preciseBlit(guiGraphics, Mod.loc("textures/screens/drone.png"), x - 8, y - 8, 0, 0, 16, 16, 16, 16); + renderKillIndicator(guiGraphics, x - 7.5f + (float) (2 * (Math.random() - 0.5f)), y - 7.5f + (float) (2 * (Math.random() - 0.5f))); + poseStack.pushPose(); - if (Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON) { - preciseBlit(guiGraphics, Mod.loc("textures/screens/helicopter/crosshair_ind.png"), x - 8, y - 8, 0, 0, 16, 16, 16, 16); - renderKillIndicator(guiGraphics, x - 7.5f + (float) (2 * (Math.random() - 0.5f)), y - 7.5f + (float) (2 * (Math.random() - 0.5f))); - } else if (mc.options.getCameraType() != CameraType.FIRST_PERSON) { - poseStack.pushPose(); - poseStack.rotateAround(Axis.ZP.rotationDegrees(iHelicopterEntity.getRotZ(partialTick)), x, y, 0); - preciseBlit(guiGraphics, Mod.loc("textures/screens/drone.png"), x - 8, y - 8, 0, 0, 16, 16, 16, 16); - renderKillIndicator(guiGraphics, x - 7.5f + (float) (2 * (Math.random() - 0.5f)), y - 7.5f + (float) (2 * (Math.random() - 0.5f))); + poseStack.translate(x, y, 0); + poseStack.scale(0.75f, 0.75f, 1); - poseStack.pushPose(); - - poseStack.translate(x, y, 0); - poseStack.scale(0.75f, 0.75f, 1); - - if (mobileVehicle instanceof Ah6Entity ah6Entity) { - if (weaponVehicle.getWeaponIndex(0) == 0) { - double heat = ah6Entity.getEntityData().get(HEAT) / 100.0F; - guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("20MM CANNON " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : iHelicopterEntity.getAmmoCount(player))), 25, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false); - } else { - guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("70MM ROCKET " + iHelicopterEntity.getAmmoCount(player)), 25, -9, -1, false); - } + if (mobileVehicle instanceof Ah6Entity ah6Entity) { + if (weaponVehicle.getWeaponIndex(0) == 0) { + double heat = ah6Entity.getEntityData().get(HEAT) / 100.0F; + guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("20MM CANNON " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : iHelicopterEntity.getAmmoCount(player))), 25, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false); + } else { + guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("70MM ROCKET " + iHelicopterEntity.getAmmoCount(player)), 25, -9, -1, false); } - - - guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("FLARE " + iHelicopterEntity.getDecoy()), 25, 1, -1, false); - poseStack.popPose(); - poseStack.popPose(); } + + + guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("FLARE " + iHelicopterEntity.getDecoy()), 25, 1, -1, false); + poseStack.popPose(); poseStack.popPose(); } + poseStack.popPose(); poseStack.popPose(); } else { diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/JavelinHudOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/JavelinHudOverlay.java index 3cc4de115..47e740008 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/JavelinHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/JavelinHudOverlay.java @@ -52,7 +52,6 @@ public class JavelinHudOverlay implements LayeredDraw.Layer { Player player = Minecraft.getInstance().player; PoseStack poseStack = guiGraphics.pose(); Camera camera = Minecraft.getInstance().gameRenderer.getMainCamera(); - Vec3 cameraPos = camera.getPosition(); if (player == null) return; ItemStack stack = player.getMainHandItem(); @@ -115,28 +114,24 @@ public class JavelinHudOverlay implements LayeredDraw.Layer { if (tag.getInt("GuideType") == 0) { for (var e : entities) { Vec3 pos = e.getBoundingBox().getCenter(); - Vec3 point = VectorUtil.worldToScreen(pos, cameraPos); - if (point != null) { - boolean lockOn = tag.getInt("SeekTime") > 20 && e == targetEntity; - boolean nearest = e == naerestEntity; + Vec3 point = VectorUtil.worldToScreen(pos); + boolean lockOn = tag.getInt("SeekTime") > 20 && e == targetEntity; + boolean nearest = e == naerestEntity; - float x = (float) point.x; - float y = (float) point.y; + float x = (float) point.x; + float y = (float) point.y; - RenderHelper.preciseBlit(guiGraphics, lockOn ? FRAME_LOCK : nearest ? FRAME_TARGET : FRAME, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24); - } + RenderHelper.preciseBlit(guiGraphics, lockOn ? FRAME_LOCK : nearest ? FRAME_TARGET : FRAME, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24); } } else { Vec3 pos = new Vec3(tag.getDouble("TargetPosX"), tag.getDouble("TargetPosY"), tag.getDouble("TargetPosZ")); boolean lockOn = tag.getInt("SeekTime") > 20; - Vec3 point = VectorUtil.worldToScreen(pos, cameraPos); - if (point != null) { - float x = (float) point.x; - float y = (float) point.y; + Vec3 point = VectorUtil.worldToScreen(pos); + float x = (float) point.x; + float y = (float) point.y; - RenderHelper.preciseBlit(guiGraphics, lockOn ? FRAME_LOCK : FRAME_TARGET, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24); - } + RenderHelper.preciseBlit(guiGraphics, lockOn ? FRAME_LOCK : FRAME_TARGET, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24); } poseStack.popPose(); } else { diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/RedTriangleOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/RedTriangleOverlay.java index 5bb87f84f..dfcb13b7b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/RedTriangleOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/RedTriangleOverlay.java @@ -51,8 +51,7 @@ public class RedTriangleOverlay implements LayeredDraw.Layer { if (idf == null) return; double distance = idf.position().distanceTo(cameraPos); Vec3 pos = new Vec3(Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), idf.xo, idf.getX()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), idf.yo + idf.getEyeHeight() + 0.5 + 0.07 * distance, idf.getEyeY() + 0.5 + 0.07 * distance), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), idf.zo, idf.getZ())); - Vec3 point = VectorUtil.worldToScreen(pos, cameraPos); - if (point == null) return; + Vec3 point = VectorUtil.worldToScreen(pos); poseStack.pushPose(); float x = (float) point.x; diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/SpyglassRangeOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/SpyglassRangeOverlay.java index 59273d34d..37bceb9fc 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/SpyglassRangeOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/SpyglassRangeOverlay.java @@ -54,7 +54,6 @@ public class SpyglassRangeOverlay implements LayeredDraw.Layer { PoseStack poseStack = guiGraphics.pose(); Player player = mc.player; Camera camera = mc.gameRenderer.getMainCamera(); - Vec3 cameraPos = camera.getPosition(); var screenWidth = guiGraphics.guiWidth(); var screenHeight = guiGraphics.guiHeight(); @@ -98,12 +97,10 @@ public class SpyglassRangeOverlay implements LayeredDraw.Layer { } else { pos = Vec3.ZERO; } - Vec3 point = VectorUtil.worldToScreen(pos, cameraPos); - if (point != null) { - float x = (float) point.x; - float y = (float) point.y; - preciseBlit(guiGraphics, INDICATOR, Mth.clamp(x - 6, 0, screenWidth - 12), Mth.clamp(y - 6, 0, screenHeight - 12), 0, 0, 12, 12, 12, 12); - } + Vec3 point = VectorUtil.worldToScreen(pos); + float x = (float) point.x; + float y = (float) point.y; + preciseBlit(guiGraphics, INDICATOR, Mth.clamp(x - 6, 0, screenWidth - 12), Mth.clamp(y - 6, 0, screenHeight - 12), 0, 0, 12, 12, 12, 12); // 火炮位置 @@ -113,13 +110,11 @@ public class SpyglassRangeOverlay implements LayeredDraw.Layer { Entity entity = EntityFindUtil.findEntity(player.level(), tag.getString("UUID")); if (entity != null) { Vec3 posF = entity.getBoundingBox().getCenter(); - Vec3 pointF = VectorUtil.worldToScreen(posF, cameraPos); - if (pointF != null) { - float xf = (float) pointF.x; - float yf = (float) pointF.y; + Vec3 pointF = VectorUtil.worldToScreen(posF); + float xf = (float) pointF.x; + float yf = (float) pointF.y; - preciseBlit(guiGraphics, FRIENDLY_INDICATOR, Mth.clamp(xf - 6, 0, screenWidth - 12), Mth.clamp(yf - 6, 0, screenHeight - 12), 0, 0, 12, 12, 12, 12); - } + preciseBlit(guiGraphics, FRIENDLY_INDICATOR, Mth.clamp(xf - 6, 0, screenWidth - 12), Mth.clamp(yf - 6, 0, screenHeight - 12), 0, 0, 12, 12, 12, 12); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/Type63InfoOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/Type63InfoOverlay.java index 941f60b2c..e28293068 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/Type63InfoOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/Type63InfoOverlay.java @@ -8,7 +8,6 @@ import com.atsuishio.superbwarfare.item.FiringParameters; import com.atsuishio.superbwarfare.tools.*; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.ChatFormatting; -import net.minecraft.client.Camera; import net.minecraft.client.DeltaTracker; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; @@ -44,8 +43,6 @@ public class Type63InfoOverlay implements LayeredDraw.Layer { public void render(GuiGraphics guiGraphics, @NotNull DeltaTracker deltaTracker) { Minecraft mc = Minecraft.getInstance(); Player player = mc.player; - Camera camera = mc.gameRenderer.getMainCamera(); - Vec3 cameraPos = camera.getPosition(); PoseStack poseStack = guiGraphics.pose(); if (player == null) return; @@ -80,8 +77,7 @@ public class Type63InfoOverlay implements LayeredDraw.Layer { }; Vec3 pos = new Vec3(type63Entity.barrel[i].center()); - Vec3 point = VectorUtil.worldToScreen(pos, cameraPos); - if (point == null) return; + Vec3 point = VectorUtil.worldToScreen(pos); poseStack.pushPose(); float x = (float) point.x; 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 d0199ae15..d6179d24f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java @@ -301,36 +301,34 @@ public class VehicleHudOverlay implements LayeredDraw.Layer { renderKillIndicator(guiGraphics, w, h); } else if (Minecraft.getInstance().options.getCameraType() == CameraType.THIRD_PERSON_BACK && !ClientEventHandler.zoomVehicle) { - Vec3 p = VectorUtil.worldToScreen(new Vec3(Mth.lerp(partialTick, player.xo, player.getX()), Mth.lerp(partialTick, player.yo + player.getEyeHeight(), player.getEyeY()), Mth.lerp(partialTick, player.zo, player.getZ())).add(iLand.getBarrelVec(partialTick).scale(192)), cameraPos); + Vec3 p = VectorUtil.worldToScreen(new Vec3(Mth.lerp(partialTick, player.xo, player.getX()), Mth.lerp(partialTick, player.yo + player.getEyeHeight(), player.getEyeY()), Mth.lerp(partialTick, player.zo, player.getZ())).add(iLand.getBarrelVec(partialTick).scale(192))); // 第三人称准星 - if (p != null) { - poseStack.pushPose(); - float x = (float) p.x; - float y = (float) p.y; + poseStack.pushPose(); + float x = (float) p.x; + float y = (float) p.y; - preciseBlit(guiGraphics, Mod.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))); + preciseBlit(guiGraphics, Mod.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.pushPose(); - poseStack.translate(x, y, 0); - poseStack.scale(0.75f, 0.75f, 1); + poseStack.translate(x, y, 0); + poseStack.scale(0.75f, 0.75f, 1); - // 载具自定义第三人称准心 - mobileVehicle.renderThirdPersonOverlay(guiGraphics, mc.font, player, w, h, scale); + // 载具自定义第三人称准心 + mobileVehicle.renderThirdPersonOverlay(guiGraphics, mc.font, player, w, h, scale); - double health = 1 - mobileVehicle.getHealth() / mobileVehicle.getMaxHealth(); + double health = 1 - mobileVehicle.getHealth() / mobileVehicle.getMaxHealth(); - guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("HP " + - FormatTool.format0D(100 * mobileVehicle.getHealth() / mobileVehicle.getMaxHealth())), 30, 1, Mth.hsvToRgb(0F, (float) health, 1.0F), false); + guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("HP " + + FormatTool.format0D(100 * mobileVehicle.getHealth() / mobileVehicle.getMaxHealth())), 30, 1, Mth.hsvToRgb(0F, (float) health, 1.0F), false); - if (mobileVehicle.hasDecoy()) { - guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("SMOKE " + mobileVehicle.getEntityData().get(DECOY_COUNT)), 30, 11, -1, false); - } - - poseStack.popPose(); - poseStack.popPose(); + if (mobileVehicle.hasDecoy()) { + guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("SMOKE " + mobileVehicle.getEntityData().get(DECOY_COUNT)), 30, 11, -1, false); } + + poseStack.popPose(); + poseStack.popPose(); } poseStack.popPose(); } else { 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 a42e9b7cc..5063fb7a5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleMgHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleMgHudOverlay.java @@ -14,7 +14,6 @@ import com.atsuishio.superbwarfare.tools.VectorUtil; 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.DeltaTracker; import net.minecraft.client.Minecraft; @@ -52,8 +51,6 @@ public class VehicleMgHudOverlay implements LayeredDraw.Layer { Minecraft mc = Minecraft.getInstance(); Player player = mc.player; PoseStack poseStack = guiGraphics.pose(); - Camera camera = mc.gameRenderer.getMainCamera(); - Vec3 cameraPos = camera.getPosition(); if (!shouldRenderCrossHair(player)) return; @@ -81,44 +78,42 @@ public class VehicleMgHudOverlay implements LayeredDraw.Layer { VehicleHudOverlay.renderKillIndicator(guiGraphics, w, h); } else if (Minecraft.getInstance().options.getCameraType() == CameraType.THIRD_PERSON_BACK && !ClientEventHandler.zoomVehicle) { Vec3 p = VectorUtil.worldToScreen(new Vec3(Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.xo, player.getX()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.yo + player.getEyeHeight(), player.getEyeY()), - Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.zo, player.getZ())).add(iLand.getGunVec(deltaTracker.getGameTimeDeltaPartialTick(true)).scale(192)), cameraPos); + Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.zo, player.getZ())).add(iLand.getGunVec(deltaTracker.getGameTimeDeltaPartialTick(true)).scale(192))); // 第三人称准星 - if (p != null) { - poseStack.pushPose(); - float x = (float) p.x; - float y = (float) p.y; + poseStack.pushPose(); + float x = (float) p.x; + float y = (float) p.y; - poseStack.pushPose(); - preciseBlit(guiGraphics, Mod.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(); + preciseBlit(guiGraphics, Mod.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.pushPose(); - poseStack.translate(x, y, 0); - poseStack.scale(0.75f, 0.75f, 1); + poseStack.translate(x, y, 0); + poseStack.scale(0.75f, 0.75f, 1); - // YX-100 - if (player.getVehicle() instanceof Yx100Entity yx100) { - double heat = yx100.getEntityData().get(HEAT) / 100.0F; - guiGraphics.drawString(mc.font, Component.literal(".50 HMG " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : yx100.getEntityData().get(MG_AMMO))), 30, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false); - } - - // 快艇 - if (player.getVehicle() instanceof SpeedboatEntity speedboat) { - double heat = speedboat.getEntityData().get(HEAT) / 100.0F; - guiGraphics.drawString(mc.font, Component.literal(".50 HMG " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : speedboat.getEntityData().get(AMMO))), 30, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false); - } - - double heal = 1 - mobileVehicle.getHealth() / mobileVehicle.getMaxHealth(); - - guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("HP " + - FormatTool.format0D(100 * mobileVehicle.getHealth() / mobileVehicle.getMaxHealth())), 30, 1, Mth.hsvToRgb(0F, (float) heal, 1.0F), false); - - poseStack.popPose(); - poseStack.popPose(); - poseStack.popPose(); + // YX-100 + if (player.getVehicle() instanceof Yx100Entity yx100) { + double heat = yx100.getEntityData().get(HEAT) / 100.0F; + guiGraphics.drawString(mc.font, Component.literal(".50 HMG " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : yx100.getEntityData().get(MG_AMMO))), 30, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false); } + + // 快艇 + if (player.getVehicle() instanceof SpeedboatEntity speedboat) { + double heat = speedboat.getEntityData().get(HEAT) / 100.0F; + guiGraphics.drawString(mc.font, Component.literal(".50 HMG " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : speedboat.getEntityData().get(AMMO))), 30, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false); + } + + double heal = 1 - mobileVehicle.getHealth() / mobileVehicle.getMaxHealth(); + + guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("HP " + + FormatTool.format0D(100 * mobileVehicle.getHealth() / mobileVehicle.getMaxHealth())), 30, 1, Mth.hsvToRgb(0F, (float) heal, 1.0F), false); + + poseStack.popPose(); + poseStack.popPose(); + poseStack.popPose(); } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleTeamOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleTeamOverlay.java index 5cb978532..d2cebbff9 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleTeamOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleTeamOverlay.java @@ -39,8 +39,6 @@ public class VehicleTeamOverlay implements LayeredDraw.Layer { public void render(GuiGraphics guiGraphics, DeltaTracker deltaTracker) { if (!DisplayConfig.VEHICLE_INFO.get()) return; - int w = guiGraphics.guiWidth(); - int h = guiGraphics.guiHeight(); Minecraft mc = Minecraft.getInstance(); Player player = mc.player; Camera camera = mc.gameRenderer.getMainCamera(); @@ -66,8 +64,7 @@ public class VehicleTeamOverlay implements LayeredDraw.Layer { if (lookAtEntity && lookingEntity instanceof VehicleEntity vehicle) { Vec3 pos = lookingEntity.getBoundingBox().getCenter().add(new Vec3(0, lookingEntity.getBbHeight() / 2 + 1, 0)); - Vec3 point = VectorUtil.worldToScreen(pos, cameraPos); - if (point == null) return; + Vec3 point = VectorUtil.worldToScreen(pos); float x = (float) point.x; float y = (float) point.y; @@ -115,13 +112,11 @@ public class VehicleTeamOverlay implements LayeredDraw.Layer { team = e.getVehicle(); } Vec3 pos = new Vec3(Mth.lerp(partialTick, team.xo, team.getX()), Mth.lerp(partialTick, team.yo + team.getBbHeight() / 2, team.getY() + team.getBbHeight() / 2), Mth.lerp(partialTick, team.zo, team.getZ())); - Vec3 point = VectorUtil.worldToScreen(pos, cameraPos); - if (point != null) { - float xf = (float) point.x; - float yf = (float) point.y; + Vec3 point = VectorUtil.worldToScreen(pos); + float xf = (float) point.x; + float yf = (float) point.y; - preciseBlit(guiGraphics, FRIENDLY_INDICATOR, Mth.clamp(xf - 6, 0, screenWidth - 12), Mth.clamp(yf - 6, 0, screenHeight - 12), 0, 0, 12, 12, 12, 12); - } + preciseBlit(guiGraphics, FRIENDLY_INDICATOR, Mth.clamp(xf - 6, 0, screenWidth - 12), Mth.clamp(yf - 6, 0, screenHeight - 12), 0, 0, 12, 12, 12, 12); } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/Yx100SwarmDroneHudOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/Yx100SwarmDroneHudOverlay.java index 04a69dea7..109b019b4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/Yx100SwarmDroneHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/Yx100SwarmDroneHudOverlay.java @@ -8,7 +8,6 @@ import com.atsuishio.superbwarfare.tools.VectorUtil; 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.DeltaTracker; import net.minecraft.client.Minecraft; @@ -41,8 +40,6 @@ public class Yx100SwarmDroneHudOverlay implements LayeredDraw.Layer { Minecraft mc = Minecraft.getInstance(); Player player = mc.player; PoseStack poseStack = guiGraphics.pose(); - Camera camera = mc.gameRenderer.getMainCamera(); - Vec3 cameraPos = camera.getPosition(); if (!shouldRenderCrossHair(player)) return; @@ -73,8 +70,7 @@ public class Yx100SwarmDroneHudOverlay implements LayeredDraw.Layer { if (naerestEntity != null) { Vec3 pos = new Vec3(Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), naerestEntity.xo, naerestEntity.getX()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), naerestEntity.yo + naerestEntity.getEyeHeight(), naerestEntity.getEyeY()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), naerestEntity.zo, naerestEntity.getZ())); - Vec3 point = VectorUtil.worldToScreen(pos, cameraPos); - if (point == null) return; + Vec3 point = VectorUtil.worldToScreen(pos); poseStack.pushPose(); float x = (float) point.x; diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/LevelRendererMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/LevelRendererMixin.java new file mode 100644 index 000000000..35e97b9d5 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/LevelRendererMixin.java @@ -0,0 +1,27 @@ +package com.atsuishio.superbwarfare.mixins; + +import com.atsuishio.superbwarfare.tools.VectorUtil; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.Camera; +import net.minecraft.client.DeltaTracker; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.client.renderer.LightTexture; +import org.joml.Matrix4f; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(LevelRenderer.class) +public class LevelRendererMixin { + + // 感谢 Minecraft-Ping-Wheel 开源 + // https://github.com/LukenSkyne/Minecraft-Ping-Wheel/blob/ede72b18f57bd9dfe55ef44afe61190421fbc084/common/src/main/java/nx/pingwheel/common/mixin/LevelRendererMixin.java + + @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;applyModelViewMatrix()V", ordinal = 0, shift = At.Shift.AFTER)) + private void onStartRenderLevel(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) { + VectorUtil.modelViewMatrix = RenderSystem.getModelViewMatrix(); + VectorUtil.projectionMatrix = RenderSystem.getProjectionMatrix(); + } +} diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/ProjectileCalculator.java b/src/main/java/com/atsuishio/superbwarfare/tools/ProjectileCalculator.java index 2ed36d3f8..4198e943f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/ProjectileCalculator.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/ProjectileCalculator.java @@ -1,6 +1,7 @@ package com.atsuishio.superbwarfare.tools; import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.world.entity.Entity; import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Level; import net.minecraft.world.phys.BlockHitResult; @@ -70,7 +71,7 @@ public class ProjectileCalculator { end, ClipContext.Block.COLLIDER, // 只检测碰撞方块 ClipContext.Fluid.NONE, // 忽略流体 - null // 无实体 + (Entity) null // 无实体 )); // 如果检测到碰撞,返回碰撞点 diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/VectorUtil.java b/src/main/java/com/atsuishio/superbwarfare/tools/VectorUtil.java index 9a275da06..51ad85b1b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/VectorUtil.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/VectorUtil.java @@ -19,39 +19,38 @@ import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.neoforge.client.event.ViewportEvent; import org.joml.Matrix4f; -import org.joml.Vector3f; +import org.joml.Vector4f; @EventBusSubscriber(Dist.CLIENT) public class VectorUtil { - /** - * Codes based on @Xjqsh - */ - private static PoseStack cachedPoseStack = new PoseStack(); public static double fov = 70; - public static Vec3 worldToScreen(Vec3 pos, Vec3 cameraPos) { - Minecraft mc = Minecraft.getInstance(); + public static Matrix4f modelViewMatrix; + public static Matrix4f projectionMatrix; - Matrix4f matrix4f = cachedPoseStack.last().pose(); - var projectionMatrix = mc.gameRenderer.getProjectionMatrix(fov); + // 感谢 Minecraft-Ping-Wheel 开源 + // https://github.com/LukenSkyne/Minecraft-Ping-Wheel/blob/ede72b18f57bd9dfe55ef44afe61190421fbc084/common/src/main/java/nx/pingwheel/common/helper/MathUtils.java#L15 + public static Vec3 worldToScreen(Vec3 pos) { + var mc = Minecraft.getInstance(); + var window = mc.getWindow(); + var camera = mc.gameRenderer.getMainCamera(); - Vector3f relativePos = pos.subtract(cameraPos).toVector3f(); + var worldPosRel = new Vector4f(camera.getPosition().reverse().add(pos).toVector3f(), 1f); + worldPosRel.mul(modelViewMatrix); + worldPosRel.mul(projectionMatrix); - Vector3f transformedPos = projectionMatrix.mul(matrix4f).transformProject( - relativePos.x, - relativePos.y, - relativePos.z, - new Vector3f() + var depth = worldPosRel.w; + + if (depth != 0) { + worldPosRel.div(depth); + } + + return new Vec3( + window.getGuiScaledWidth() * (0.5f + worldPosRel.x * 0.5f), + window.getGuiScaledHeight() * (0.5f - worldPosRel.y * 0.5f), + depth ); - - double scaleFactor = mc.getWindow().getGuiScale(); - float guiScaleMul = 0.5f / (float) scaleFactor; - - Vector3f screenPos = transformedPos.mul(1.0F, -1.0F, 1.0F).add(1.0F, 1.0F, 0.0F) - .mul(guiScaleMul * mc.getWindow().getWidth(), guiScaleMul * mc.getWindow().getHeight(), 1.0F); - - return transformedPos.z < 1.0f ? new Vec3(screenPos.x, screenPos.y, transformedPos.z) : null; } @SubscribeEvent(priority = EventPriority.LOWEST) @@ -97,6 +96,5 @@ public class VectorUtil { poseStack.mulPose(Axis.XP.rotationDegrees(event.getPitch())); poseStack.mulPose(Axis.YP.rotationDegrees(event.getYaw() + 180.0F)); - cachedPoseStack = poseStack; } } diff --git a/src/main/resources/mixins.superbwarfare.json b/src/main/resources/mixins.superbwarfare.json index 712453d31..949685602 100644 --- a/src/main/resources/mixins.superbwarfare.json +++ b/src/main/resources/mixins.superbwarfare.json @@ -24,6 +24,7 @@ "ItemInHandLayerMixin", "KeyboardInputMixin", "KeymappingMixin", + "LevelRendererMixin", "LivingEntityRendererMixin", "MinecraftMixin", "MouseHandlerMixin",