From a2193642bab3a35a7147fff6cc8d5c6924e1c6dd Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Thu, 2 May 2024 19:15:50 +0200 Subject: Add Line to Metal Detector Solution (#1131) --- .../core/util/render/RenderUtils.java | 57 ++++++++++++++++++++-- .../miscfeatures/CrystalMetalDetectorSolver.java | 3 ++ .../options/separatesections/Mining.java | 9 ++++ 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java index 5f501115..6f32136b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java @@ -417,7 +417,14 @@ public class RenderUtils { renderWayPoint(Arrays.asList(""), new Vector3f(loc.getX(), loc.getY(), loc.getZ()), partialTicks, true); } - public static void drawFilledQuadWithTexture(Vec3 p1, Vec3 p2, Vec3 p3, Vec3 p4, float alpha, ResourceLocation texture) { + public static void drawFilledQuadWithTexture( + Vec3 p1, + Vec3 p2, + Vec3 p3, + Vec3 p4, + float alpha, + ResourceLocation texture + ) { GlStateManager.pushMatrix(); Entity v = Minecraft.getMinecraft().getRenderViewEntity(); double vX = v.lastTickPosX + (v.posX - v.lastTickPosX); @@ -433,10 +440,10 @@ public class RenderUtils { GlStateManager.color(1.0f, 1.0f, 1.0f, alpha); Minecraft.getMinecraft().getTextureManager().bindTexture(texture); worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); - worldrenderer.pos(p1.xCoord-vX, p1.yCoord-vY, p1.zCoord-vZ).tex(0, 0).endVertex(); //Top Left - worldrenderer.pos(p2.xCoord-vX, p2.yCoord-vY, p2.zCoord-vZ).tex(1, 0).endVertex(); //Top Right - worldrenderer.pos(p3.xCoord-vX, p3.yCoord-vY, p3.zCoord-vZ).tex(1, 1).endVertex(); //Bottom Right - worldrenderer.pos(p4.xCoord-vX, p4.yCoord-vY, p4.zCoord-vZ).tex(0, 1).endVertex(); //Bottom Left + worldrenderer.pos(p1.xCoord - vX, p1.yCoord - vY, p1.zCoord - vZ).tex(0, 0).endVertex(); //Top Left + worldrenderer.pos(p2.xCoord - vX, p2.yCoord - vY, p2.zCoord - vZ).tex(1, 0).endVertex(); //Top Right + worldrenderer.pos(p3.xCoord - vX, p3.yCoord - vY, p3.zCoord - vZ).tex(1, 1).endVertex(); //Bottom Right + worldrenderer.pos(p4.xCoord - vX, p4.yCoord - vY, p4.zCoord - vZ).tex(0, 1).endVertex(); //Bottom Left tessellator.draw(); GlStateManager.enableCull(); GlStateManager.popMatrix(); @@ -539,4 +546,44 @@ public class RenderUtils { if (lightingState) GlStateManager.enableLighting(); } + + public static void renderLineToBlock(BlockPos block, int rgb, float partialTicks) { + Minecraft mc = Minecraft.getMinecraft(); + Entity renderViewEntity = mc.getRenderViewEntity(); + + double cameraX = renderViewEntity.lastTickPosX + (renderViewEntity.posX - renderViewEntity.lastTickPosX); + double cameraY = renderViewEntity.lastTickPosY + (renderViewEntity.posY - renderViewEntity.lastTickPosY); + double cameraZ = renderViewEntity.lastTickPosZ + (renderViewEntity.posZ - renderViewEntity.lastTickPosZ); + + GlStateManager.disableTexture2D(); + GlStateManager.disableDepth(); + GlStateManager.disableLighting(); + GlStateManager.disableCull(); + GlStateManager.enableBlend(); + GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glEnable(GL11.GL_LINE_SMOOTH); + GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST); + GL11.glLineWidth(3.0F); + + GlStateManager.color( + ((rgb >> 16) & 0xFF) / 255.0f, + ((rgb >> 8) & 0xFF) / 255.0f, + (rgb & 0xFF) / 255.0f, + 1.0f + ); + + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + worldRenderer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION); + worldRenderer.pos(0, renderViewEntity.getEyeHeight(), 0).endVertex(); + worldRenderer.pos(block.getX() + 0.5 - cameraX, block.getY() - cameraY, block.getZ() + 0.5 - cameraZ).endVertex(); + tessellator.draw(); + + GlStateManager.enableTexture2D(); + GlStateManager.enableDepth(); + GlStateManager.enableCull(); + GlStateManager.disableBlend(); + GlStateManager.enableLighting(); + } + } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java index a78a28f4..0624d9fa 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java @@ -369,6 +369,9 @@ public class CrystalMetalDetectorSolver { RenderUtils.renderBeaconBeam(block.add(0, 1, 0), beaconRGB, 1.0f, partialTicks); RenderUtils.renderWayPoint("Treasure", possibleBlocks.iterator().next().add(0, 2.5, 0), partialTicks); + if (NotEnoughUpdates.INSTANCE.config.mining.metalDetectorLineToSolution) { + RenderUtils.renderLineToBlock(block.add(0, 1, 0), 0x1fd8f1, partialTicks); + } } else if (possibleBlocks.size() > 1 && NotEnoughUpdates.INSTANCE.config.mining.metalDetectorShowPossible) { for (BlockPos block : possibleBlocks) { RenderUtils.renderBeaconBeam(block.add(0, 1, 0), beaconRGB, 1.0f, partialTicks); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/Mining.java b/src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/Mining.java index e065bf3a..4ccd2a06 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/Mining.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/Mining.java @@ -334,6 +334,15 @@ public class Mining { @ConfigAccordionId(id = 3) public boolean metalDetectorEnabled = true; + @Expose + @ConfigOption( + name = "Line to Solution", + desc = "Draw a line to the solution block." + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 3) + public boolean metalDetectorLineToSolution = true; + @Expose @ConfigOption( name = "Show Possible Blocks", -- cgit