diff --git a/src/client/java/com/luna/jetoverlay/JetOverlayClient.java b/src/client/java/com/luna/jetoverlay/JetOverlayClient.java index d3075f9..e24a111 100644 --- a/src/client/java/com/luna/jetoverlay/JetOverlayClient.java +++ b/src/client/java/com/luna/jetoverlay/JetOverlayClient.java @@ -22,7 +22,7 @@ public class JetOverlayClient implements ClientModInitializer { public static boolean renderOverlay = false; public static List markedEntities = new ArrayList<>(); - public static final KeyMapping toggle_outline = new KeyMapping("key.toggle-outline", + public static final KeyMapping TOGGLE_OUTLINE = new KeyMapping("key.toggle-outline", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_LEFT_CONTROL, "jetoverlay" @@ -60,7 +60,7 @@ private static void createBlockDetectorScreen(BlockPos __block, int __range, int public void onInitializeClient() { HudRenderCallback.EVENT.register(new JetOverlayHud()); HudRenderCallback.EVENT.register(new HudOverlay()); - KeyBindingHelper.registerKeyBinding(toggle_outline); + KeyBindingHelper.registerKeyBinding(TOGGLE_OUTLINE); KeyBindingHelper.registerKeyBinding(markEntityAsTarget); MenuScreens.register(JetOverlay.GOGGLES_RECEIVER_SCREEN_HANDLER, GogglesReceiverScreen::new); diff --git a/src/client/java/com/luna/jetoverlay/client/HudOverlay.java b/src/client/java/com/luna/jetoverlay/client/HudOverlay.java index e55e594..9c00fa5 100644 --- a/src/client/java/com/luna/jetoverlay/client/HudOverlay.java +++ b/src/client/java/com/luna/jetoverlay/client/HudOverlay.java @@ -1,10 +1,6 @@ package com.luna.jetoverlay.client; -import com.luna.jetoverlay.JetOverlayClient; -import com.mojang.blaze3d.platform.Window; -import com.mojang.blaze3d.systems.RenderSystem; import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.resources.ResourceLocation; diff --git a/src/client/java/com/luna/jetoverlay/client/JetOverlayHud.java b/src/client/java/com/luna/jetoverlay/client/JetOverlayHud.java index 804e09a..fe9d69f 100644 --- a/src/client/java/com/luna/jetoverlay/client/JetOverlayHud.java +++ b/src/client/java/com/luna/jetoverlay/client/JetOverlayHud.java @@ -1,16 +1,15 @@ package com.luna.jetoverlay.client; -import com.luna.jetoverlay.CameraRotationDirection; import com.luna.jetoverlay.JetOverlayClient; import com.luna.jetoverlay.ModItems; import com.luna.jetoverlay.armor.JetGoggles; -import com.luna.jetoverlay.networking.PacketSender; import net.minecraft.client.Camera; +import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.core.BlockPos; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; @@ -22,19 +21,19 @@ public class JetOverlayHud implements HudRenderCallback { - private final float _RAYCAST_RANGE = 1000f; - private final int _NEARBY_ENTITIES_RANGE = 30; + boolean _hudHidden = false; - float _originalXRot; - float _originalYRot; - - protected void drawTextAt(String text, int color, Vector3f worldPosition, GuiGraphics drawContext, LivingEntity entity) { + protected void drawTextAt(String text, int color, Vector3f worldPosition, GuiGraphics drawContext) { Minecraft mc = Minecraft.getInstance(); // Matrix math shamelessly stolen from here: // https://github.com/Klemmbaustein/Klemmgine/blob/f5454be1e95c43cbb91f0f55abf682774572defe/EngineSource/Objects/Components/CameraComponent.cpp#L36-L43 // And here: // https://github.com/Klemmbaustein/Klemmgine/blob/f5454be1e95c43cbb91f0f55abf682774572defe/EngineSource/Rendering/Camera/Camera.cpp#L41-L43 Camera cam = mc.gameRenderer.getMainCamera(); + + if (cam.getXRot() < -85 || cam.getXRot() > 85) + return; + Matrix4f projection = mc.gameRenderer.getProjectionMatrix(mc.options.fov().get()); Matrix4f view = new Matrix4f().identity(); view.setLookAt(cam.getLookVector(), new Vector3f(0, 0, 0), new Vector3f(0, 1, 0)); @@ -49,13 +48,16 @@ protected void drawTextAt(String text, int color, Vector3f worldPosition, GuiGra // Return if the depth (z coordinate) is less than 0 // So if the position is behind the camera. - if (pos.z < 0) + if (pos.z <= 0) return; float x = pos.x / pos.z, y = pos.y / pos.z; int windowWidth = drawContext.guiWidth(), windowHeight = drawContext.guiHeight(); + if (Float.isNaN(x) || Float.isNaN(y)) + return; + // Convert to UI coordinates. So from -1 - 1 to 0 - width/height int xPos = (int) (x * (windowWidth / 2.0f)) + windowWidth / 2; int yPos = (int) (y * (windowHeight / 2.0f)) + windowHeight / 2; @@ -74,6 +76,8 @@ int colorFromHealthPercentage(int __percentage) { } private void markEntityLogic(Player __player) { + final float _RAYCAST_RANGE = 1000f; + Vec3 eyePosition = __player.getEyePosition(); Vec3 viewVector = __player.getViewVector(0); Vec3 rayCastEnd = eyePosition.add(viewVector.multiply(_RAYCAST_RANGE, _RAYCAST_RANGE, _RAYCAST_RANGE)); @@ -102,6 +106,8 @@ private void renderOverlay(GuiGraphics __drawContext, float __tickDelta) { markEntityLogic(player); + final int _NEARBY_ENTITIES_RANGE = 30; + for (var entity : JetOverlayClient.markedEntities) { if (!entity.isAlive() || entity.distanceTo(player) > _NEARBY_ENTITIES_RANGE) { JetOverlayClient.markedEntities.remove(entity); @@ -112,16 +118,79 @@ private void renderOverlay(GuiGraphics __drawContext, float __tickDelta) { String entityHealthText = entityHealthPercentage + "%"; int color = colorFromHealthPercentage(entityHealthPercentage); - drawTextAt(entityHealthText, color, entity.position().toVector3f().add(0, 2.5f, 0), __drawContext, entity); + drawTextAt(entityHealthText, color, entity.position().toVector3f().add(0, 2.5f, 0), __drawContext); } - String blockPosString = "Not linked"; - var headSlot = player.getItemBySlot(EquipmentSlot.HEAD); - if (!headSlot.isEmpty() && headSlot.hasTag() && headSlot.getTag().contains(JetGoggles.GOGGLES_BLOCK_TAG_NAME)) { - blockPosString = "Linked to: " + headSlot.getTag().get(JetGoggles.GOGGLES_BLOCK_TAG_NAME).getAsString(); + if (JetOverlayClient.TOGGLE_OUTLINE.consumeClick()) { + _hudHidden = !_hudHidden; } - __drawContext.drawString(Minecraft.getInstance().font, blockPosString, 0, 2, 0x00FF00); + drawOverlayText(__drawContext, player); + } + + void drawBlockPositionText(GuiGraphics __drawContext, Player __player, BlockPos __position, String __text) { + if (__position.getCenter().distanceTo(__player.getPosition(0)) > 16) + return; + + Vec3 blockPos = __position.getCenter(); + + drawTextAt(__text, + 0xFF00A0, + new Vector3f((float) blockPos.x, (float) blockPos.y, (float) blockPos.z), + __drawContext); + } + + void drawOverlayText(GuiGraphics __drawContext, Player __player) { + var headSlot = __player.getItemBySlot(EquipmentSlot.HEAD); + + if (!headSlot.isEmpty() && headSlot.hasTag() && headSlot.getTag().contains(JetGoggles.GOGGLES_BLOCK_TAG_NAME)) { + var linkedBlocksTag = headSlot.getTag().getCompound(JetGoggles.GOGGLES_BLOCK_TAG_NAME); + + String showOverlayName = KeyMapping.createNameSupplier(JetOverlayClient.TOGGLE_OUTLINE.getName()).get().getString(); + int color = 0x00FF00; + + if (_hudHidden) { + __drawContext.drawString(Minecraft.getInstance().font, "Press " + showOverlayName + " to show overlay", 2, 2, color); + return; + } + + int receiverId = 1; + for (String key : linkedBlocksTag.getAllKeys()) { + int[] value = linkedBlocksTag.getIntArray(key); + + if (value.length != 3) + continue; + + String drawnString = "Linked receiver #" + receiverId; + + drawBlockPositionText(__drawContext, __player, new BlockPos(value[0], value[1], value[2]), drawnString); + receiverId++; + } + + int yOffset = Minecraft.getInstance().font.lineHeight + 1; + + __drawContext.fill(0, 0, 160, (linkedBlocksTag.getAllKeys().size() + 2) * yOffset + 4, + 0x88444444); + __drawContext.drawString(Minecraft.getInstance().font, "Linked to receivers:", 2, 2, color); + + int yPos = yOffset + 2; + receiverId = 1; + for (String key : linkedBlocksTag.getAllKeys()) { + int[] value = linkedBlocksTag.getIntArray(key); + + if (value.length != 3) + continue; + + String drawnString = "#" + receiverId + ": X: " + value[0] + " Y: " + value[1] + " Z: " + value[2]; + color += 0x200000; + __drawContext.drawString(Minecraft.getInstance().font, drawnString, 12, yPos, color); + yPos += yOffset; + receiverId++; + } + color += 0x200000; + __drawContext.drawString(Minecraft.getInstance().font, "Press " + showOverlayName + " to hide", 2, yPos, color); + } else + __drawContext.drawString(Minecraft.getInstance().font, "Not linked to any receivers.", 0, 2, 0xFFFF00); } @Override @@ -133,6 +202,4 @@ public void onHudRender(GuiGraphics __drawContext, float __tickDelta) { renderOverlay(__drawContext, __tickDelta); } } - - ResourceLocation _clientChannel = new ResourceLocation("jetoverlay_client", "redstone_emitter_client"); } diff --git a/src/main/resources/assets/jetoverlay/models/block/redstoneoutputter.json b/src/main/resources/assets/jetoverlay/models/block/redstoneoutputter.json index 9ee33e0..4a549ab 100644 --- a/src/main/resources/assets/jetoverlay/models/block/redstoneoutputter.json +++ b/src/main/resources/assets/jetoverlay/models/block/redstoneoutputter.json @@ -129,5 +129,39 @@ 6, 7, 8 - ] + ], + "display": { + "thirdperson_righthand": { + "rotation": [75, 135, 0], + "translation": [0, 2.5, 0], + "scale": [0.375, 0.375, 0.375] + }, + "thirdperson_lefthand": { + "rotation": [75, 135, 0], + "translation": [0, 2.5, 0], + "scale": [0.375, 0.375, 0.375] + }, + "firstperson_righthand": { + "rotation": [0, 135, 0], + "scale": [0.4, 0.4, 0.4] + }, + "firstperson_lefthand": { + "rotation": [0, 135, 0], + "scale": [0.4, 0.4, 0.4] + }, + "ground": { + "translation": [0, 3, 0], + "scale": [0.25, 0.25, 0.25] + }, + "gui": { + "rotation": [30, 225, 0], + "scale": [0.625, 0.625, 0.625] + }, + "head": { + "translation": [0, 0, -1.5] + }, + "fixed": { + "scale": [0.5, 0.5, 0.5] + } + } } \ No newline at end of file