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 37bceb9fc..4608cb16f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/SpyglassRangeOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/SpyglassRangeOverlay.java @@ -98,9 +98,11 @@ public class SpyglassRangeOverlay implements LayeredDraw.Layer { pos = Vec3.ZERO; } 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); + if (VectorUtil.canSee(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); + } // 火炮位置 @@ -111,10 +113,11 @@ public class SpyglassRangeOverlay implements LayeredDraw.Layer { if (entity != null) { Vec3 posF = entity.getBoundingBox().getCenter(); 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); + if (VectorUtil.canSee(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); + } } } 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 24511d616..157f97320 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleTeamOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleTeamOverlay.java @@ -105,7 +105,7 @@ public class VehicleTeamOverlay implements LayeredDraw.Layer { if (player.getVehicle() instanceof VehicleEntity) { List entities = SeekTool.getPlayer(player, player.level()); for (var e : entities) { - if (e != null && e != player && calculateAngle(e, camera) < VectorUtil.fov) { + if (e != null && e != player && VectorUtil.canSee(e.position())) { Entity team = e; if (e.getVehicle() != null) { team = e.getVehicle(); diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/VectorUtil.java b/src/main/java/com/atsuishio/superbwarfare/tools/VectorUtil.java index f3832f0e0..26cb18635 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/VectorUtil.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/VectorUtil.java @@ -1,5 +1,6 @@ package com.atsuishio.superbwarfare.tools; +import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.world.phys.Vec3; import net.neoforged.api.distmarker.Dist; @@ -48,4 +49,13 @@ public class VectorUtil { fov = event.getFOV(); } } + + public static boolean canSee(Vec3 pos) { + Minecraft mc = Minecraft.getInstance(); + Camera camera = mc.gameRenderer.getMainCamera(); + Vec3 cameraPos = camera.getPosition(); + Vec3 viewVec = new Vec3(camera.getLookVector()); + Vec3 v1 = cameraPos.vectorTo(pos); + return VectorTool.calculateAngle(v1, viewVec) < fov; + } }