From cb4d7f49fdb6d244b19b7f991a5ef606012ae1a5 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Wed, 18 Aug 2021 20:12:41 +0200 Subject: thing --- .../notenoughupdates/NEUEventListener.java | 9 ++ .../core/util/render/RenderUtils.java | 85 ++++++++++++++ .../miscfeatures/CrystalMetalDetectorSolver.java | 128 +++++++++++++++++++++ .../miscfeatures/DwarvenMinesWaypoints.java | 88 +------------- 4 files changed, 228 insertions(+), 82 deletions(-) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java (limited to 'src') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java index 610d6931..882dd965 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java @@ -787,6 +787,7 @@ public class NEUEventListener { @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) public void onGuiChat(ClientChatReceivedEvent e) { if(e.type == 2) { + CrystalMetalDetectorSolver.process(e.message); e.message = processChatComponent(e.message); return; } @@ -834,6 +835,9 @@ public class NEUEventListener { e.message = new ChatComponentText(m2); } } + if (unformatted.startsWith("You found ") && SBInfo.getInstance().getLocation().equals("crystal_hollows")){ + CrystalMetalDetectorSolver.reset(); + } } public static boolean drawingGuiScreen = false; @@ -2446,4 +2450,9 @@ public class NEUEventListener { } } } + + @SubscribeEvent + public void onRenderLast(RenderWorldLastEvent event){ + CrystalMetalDetectorSolver.render(event.partialTicks); + } } 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 a43eb0e6..b63831ac 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 @@ -2,6 +2,7 @@ package io.github.moulberry.notenoughupdates.core.util.render; import io.github.moulberry.notenoughupdates.core.BackgroundBlur; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; @@ -9,8 +10,12 @@ import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.entity.Entity; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumChatFormatting; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL14; +import org.lwjgl.util.vector.Vector3f; public class RenderUtils { @@ -141,4 +146,84 @@ public class RenderUtils { GlStateManager.enableTexture2D(); } + public static void renderWayPoint(String str, BlockPos loc, float partialTicks) { + renderWayPoint(str, new Vector3f(loc.getX(), loc.getY(), loc.getZ()), partialTicks); + } + public static void renderWayPoint(String str, Vector3f loc, float partialTicks) { + GlStateManager.alphaFunc(516, 0.1F); + + GlStateManager.pushMatrix(); + + Entity viewer = Minecraft.getMinecraft().getRenderViewEntity(); + double viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks; + double viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks; + double viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks; + + double x = loc.x-viewerX+0.5f; + double y = loc.y-viewerY-viewer.getEyeHeight(); + double z = loc.z-viewerZ+0.5f; + + double distSq = x*x + y*y + z*z; + double dist = Math.sqrt(distSq); + if(distSq > 144) { + x *= 12/dist; + y *= 12/dist; + z *= 12/dist; + } + GlStateManager.translate(x, y, z); + GlStateManager.translate(0, viewer.getEyeHeight(), 0); + + renderNametag(str); + + GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F); + GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F); + GlStateManager.translate(0, -0.25f, 0); + GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F); + GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F); + + renderNametag(EnumChatFormatting.YELLOW.toString()+Math.round(dist)+"m"); + + GlStateManager.popMatrix(); + + GlStateManager.disableLighting(); + } + + public static void renderNametag(String str) { + FontRenderer fontrenderer = Minecraft.getMinecraft().fontRendererObj; + float f = 1.6F; + float f1 = 0.016666668F * f; + GlStateManager.pushMatrix(); + GL11.glNormal3f(0.0F, 1.0F, 0.0F); + GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F); + GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F); + GlStateManager.scale(-f1, -f1, f1); + GlStateManager.disableLighting(); + GlStateManager.depthMask(false); + GlStateManager.disableDepth(); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + int i = 0; + + int j = fontrenderer.getStringWidth(str) / 2; + GlStateManager.disableTexture2D(); + worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); + worldrenderer.pos((double)(-j - 1), (double)(-1 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); + worldrenderer.pos((double)(-j - 1), (double)(8 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); + worldrenderer.pos((double)(j + 1), (double)(8 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); + worldrenderer.pos((double)(j + 1), (double)(-1 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); + tessellator.draw(); + GlStateManager.enableTexture2D(); + fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, 553648127); + GlStateManager.depthMask(true); + + fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, -1); + + GlStateManager.enableDepth(); + GlStateManager.enableBlend(); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.popMatrix(); + } + } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java new file mode 100644 index 00000000..7ed2414a --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java @@ -0,0 +1,128 @@ +package io.github.moulberry.notenoughupdates.miscfeatures; + +import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; +import io.github.moulberry.notenoughupdates.util.SBInfo; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.entity.Entity; +import net.minecraft.util.BlockPos; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IChatComponent; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.vector.Vector3f; + +import java.util.ArrayList; +import java.util.List; + +public class CrystalMetalDetectorSolver { + private static final Minecraft mc = Minecraft.getMinecraft(); + private static float prev; + private static List possibleBlocks = new ArrayList<>(); + private static final List distances = new ArrayList<>(); + + public static void process(IChatComponent message) { + if (SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("crystal_hollows") + && message.getUnformattedText().contains("TREASURE: ")) { + float dist = Float.parseFloat(message.getUnformattedText().split("TREASURE: ")[1].split("m")[0].replaceAll("(?!\\.)\\D", "")); + if (prev == dist && dist > 5 && !distances.contains(dist) && possibleBlocks.size() != 1) { //Distance 5 minimum because distance calculation is inaccurate under 5 + distances.add(dist); + List temp = new ArrayList<>(); + for (int zOffset = Math.round(-dist); zOffset <= dist; zOffset++) { + float calculatedDist = 0; + int xOffset = 0; + int yOffset = 0; + int loops = 0; + while (calculatedDist < dist) { + loops++; + BlockPos pos = new BlockPos(Math.floor(mc.thePlayer.posX) + xOffset, + Math.floor(mc.thePlayer.posY - 1) + yOffset, Math.floor(mc.thePlayer.posZ) + zOffset); + BlockPos above = new BlockPos(Math.floor(mc.thePlayer.posX) + xOffset, + Math.floor(mc.thePlayer.posY) + yOffset, Math.floor(mc.thePlayer.posZ) + zOffset); + if (mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:air")) { + yOffset--; + System.out.println("-" + pos + " " + yOffset + " " + mc.theWorld.getBlockState(pos).getBlock().getRegistryName() + " " + + mc.theWorld.getBlockState(above).getBlock().getRegistryName()); + } else if (mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:gold_block")) { + yOffset++; + System.out.println("+" + pos + " " + yOffset + " " + mc.theWorld.getBlockState(pos).getBlock().getRegistryName() + " " + + mc.theWorld.getBlockState(above).getBlock().getRegistryName()); + } else { + System.out.println("Calculating block distance"); + xOffset++; + calculatedDist = (float) round(mc.thePlayer.getDistance(pos.getX(), pos.getY() + 1, pos.getZ()), 1); + if (calculatedDist == dist && (mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:gold_block") + || mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:chest")) && + (possibleBlocks.size() == 0 || possibleBlocks.contains(pos))) { + temp.add(pos); + } + } + if (loops > 500) break; + } + xOffset = 0; + calculatedDist = 0; + yOffset = 0; + loops = 0; + while (calculatedDist < dist) { + loops++; + BlockPos pos = new BlockPos(Math.floor(mc.thePlayer.posX) - xOffset, + Math.floor(mc.thePlayer.posY - 1) + yOffset, Math.floor(mc.thePlayer.posZ) + zOffset); + BlockPos above = new BlockPos(Math.floor(mc.thePlayer.posX) + xOffset, + Math.floor(mc.thePlayer.posY) + yOffset, Math.floor(mc.thePlayer.posZ) + zOffset); + if (mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:air")) { + yOffset--; + System.out.println("-" + pos + " " + yOffset + " " + mc.theWorld.getBlockState(pos).getBlock().getRegistryName() + " " + + mc.theWorld.getBlockState(above).getBlock().getRegistryName()); + } else if (mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:gold_block")) { + yOffset++; + System.out.println("+" + pos + " " + yOffset + " " + mc.theWorld.getBlockState(pos).getBlock().getRegistryName() + " " + + mc.theWorld.getBlockState(above).getBlock().getRegistryName()); + } else { + System.out.println("Calculating block distance"); + xOffset++; + calculatedDist = (float) round(mc.thePlayer.getDistance(pos.getX(), pos.getY() + 1, pos.getZ()), 1); + if (calculatedDist == dist && (mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:gold_block") + || mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:chest")) && + (possibleBlocks.size() == 0 || possibleBlocks.contains(pos))) { + temp.add(pos); + } + } + if (loops > 500) break; + } + } + possibleBlocks = temp; + System.out.println(possibleBlocks); + if (possibleBlocks.size() > 1) { + mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "[NEU] Need another position to find solution. Possible blocks: " + + possibleBlocks.size())); + } else if (possibleBlocks.size() == 0) { + mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[NEU] Failed to find solution.")); + } else { + mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "[NEU] Found solution.")); + } + } + prev = dist; + } + } + + public static void reset() { + possibleBlocks.clear(); + distances.clear(); + } + + public static void render(float partialTicks){ + if (SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("crystal_hollows") && possibleBlocks.size() == 1){ + RenderUtils.renderWayPoint("Treasure", possibleBlocks.get(0), partialTicks); + } + } + + private static double round(double value, int precision) { + int scale = (int) Math.pow(10, precision); + return (double) Math.round(value * scale) / scale; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DwarvenMinesWaypoints.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DwarvenMinesWaypoints.java index 96f86c36..5c4fb61d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DwarvenMinesWaypoints.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DwarvenMinesWaypoints.java @@ -1,6 +1,7 @@ package io.github.moulberry.notenoughupdates.miscfeatures; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.overlays.MiningOverlay; import io.github.moulberry.notenoughupdates.util.SBInfo; @@ -197,7 +198,7 @@ public class DwarvenMinesWaypoints { System.currentTimeMillis() - dynamicMillis < 30*1000) { for(Map.Entry entry : waypointsMap.entrySet()) { if(entry.getKey().equals(dynamicLocation)) { - renderWayPoint(dynamicName, new Vector3f(entry.getValue()).translate(0, 15, 0), event.partialTicks); + RenderUtils.renderWayPoint(dynamicName, new Vector3f(entry.getValue()).translate(0, 15, 0), event.partialTicks); break; } } @@ -206,14 +207,14 @@ public class DwarvenMinesWaypoints { if(locWaypoint >= 1) { for(Map.Entry entry : waypointsMap.entrySet()) { if(locWaypoint >= 2) { - renderWayPoint(EnumChatFormatting.AQUA+entry.getKey(), entry.getValue(), event.partialTicks); + RenderUtils.renderWayPoint(EnumChatFormatting.AQUA+entry.getKey(), entry.getValue(), event.partialTicks); } else { for(String commissionName : MiningOverlay.commissionProgress.keySet()) { if(commissionName.toLowerCase().contains(entry.getKey().toLowerCase())) { if(commissionName.contains("Titanium")) { - renderWayPoint(EnumChatFormatting.WHITE+entry.getKey(), entry.getValue(), event.partialTicks); + RenderUtils.renderWayPoint(EnumChatFormatting.WHITE+entry.getKey(), entry.getValue(), event.partialTicks); } else { - renderWayPoint(EnumChatFormatting.AQUA+entry.getKey(), entry.getValue(), event.partialTicks); + RenderUtils.renderWayPoint(EnumChatFormatting.AQUA+entry.getKey(), entry.getValue(), event.partialTicks); } } } @@ -247,7 +248,7 @@ public class DwarvenMinesWaypoints { double distSq = dX*dX + dY*dY + dZ*dZ; if(distSq >= 12*12) { - renderWayPoint(EnumChatFormatting.GOLD+emissary.name, + RenderUtils.renderWayPoint(EnumChatFormatting.GOLD+emissary.name, new Vector3f(emissary.loc).translate(0.5f, 2.488f, 0.5f), event.partialTicks); } @@ -258,81 +259,4 @@ public class DwarvenMinesWaypoints { } } - private void renderWayPoint(String str, Vector3f loc, float partialTicks) { - GlStateManager.alphaFunc(516, 0.1F); - - GlStateManager.pushMatrix(); - - Entity viewer = Minecraft.getMinecraft().getRenderViewEntity(); - double viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks; - double viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks; - double viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks; - - double x = loc.x-viewerX+0.5f; - double y = loc.y-viewerY-viewer.getEyeHeight(); - double z = loc.z-viewerZ+0.5f; - - double distSq = x*x + y*y + z*z; - double dist = Math.sqrt(distSq); - if(distSq > 144) { - x *= 12/dist; - y *= 12/dist; - z *= 12/dist; - } - GlStateManager.translate(x, y, z); - GlStateManager.translate(0, viewer.getEyeHeight(), 0); - - renderNametag(str); - - GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F); - GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F); - GlStateManager.translate(0, -0.25f, 0); - GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F); - GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F); - - renderNametag(EnumChatFormatting.YELLOW.toString()+Math.round(dist)+"m"); - - GlStateManager.popMatrix(); - - GlStateManager.disableLighting(); - } - - private void renderNametag(String str) { - FontRenderer fontrenderer = Minecraft.getMinecraft().fontRendererObj; - float f = 1.6F; - float f1 = 0.016666668F * f; - GlStateManager.pushMatrix(); - GL11.glNormal3f(0.0F, 1.0F, 0.0F); - GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F); - GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F); - GlStateManager.scale(-f1, -f1, f1); - GlStateManager.disableLighting(); - GlStateManager.depthMask(false); - GlStateManager.disableDepth(); - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldrenderer = tessellator.getWorldRenderer(); - int i = 0; - - int j = fontrenderer.getStringWidth(str) / 2; - GlStateManager.disableTexture2D(); - worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); - worldrenderer.pos((double)(-j - 1), (double)(-1 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); - worldrenderer.pos((double)(-j - 1), (double)(8 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); - worldrenderer.pos((double)(j + 1), (double)(8 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); - worldrenderer.pos((double)(j + 1), (double)(-1 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); - tessellator.draw(); - GlStateManager.enableTexture2D(); - fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, 553648127); - GlStateManager.depthMask(true); - - fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, -1); - - GlStateManager.enableDepth(); - GlStateManager.enableBlend(); - GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - GlStateManager.popMatrix(); - } - } -- cgit From b87e2135d394ea66f0f09e5db63a1c842558d9be Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Wed, 18 Aug 2021 23:57:30 +0200 Subject: code --- .../notenoughupdates/NEUEventListener.java | 1 + .../miscfeatures/CrystalMetalDetectorSolver.java | 164 ++++++++++----------- 2 files changed, 78 insertions(+), 87 deletions(-) (limited to 'src') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java index 882dd965..a8be9991 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java @@ -170,6 +170,7 @@ public class NEUEventListener { @SubscribeEvent public void onWorldLoad(WorldEvent.Unload event) { NotEnoughUpdates.INSTANCE.saveConfig(); + CrystalMetalDetectorSolver.reset(); } private static long notificationDisplayMillis = 0; 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 7ed2414a..2686272d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java @@ -2,127 +2,117 @@ package io.github.moulberry.notenoughupdates.miscfeatures; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.util.SBInfo; -import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.entity.Entity; import net.minecraft.util.BlockPos; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; -import org.lwjgl.opengl.GL11; -import org.lwjgl.util.vector.Vector3f; import java.util.ArrayList; import java.util.List; public class CrystalMetalDetectorSolver { private static final Minecraft mc = Minecraft.getMinecraft(); - private static float prev; + private static BlockPos prevPos; + private static float prevDist = 0; private static List possibleBlocks = new ArrayList<>(); - private static final List distances = new ArrayList<>(); + private static final List locations = new ArrayList<>(); public static void process(IChatComponent message) { if (SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("crystal_hollows") && message.getUnformattedText().contains("TREASURE: ")) { float dist = Float.parseFloat(message.getUnformattedText().split("TREASURE: ")[1].split("m")[0].replaceAll("(?!\\.)\\D", "")); - if (prev == dist && dist > 5 && !distances.contains(dist) && possibleBlocks.size() != 1) { //Distance 5 minimum because distance calculation is inaccurate under 5 - distances.add(dist); - List temp = new ArrayList<>(); - for (int zOffset = Math.round(-dist); zOffset <= dist; zOffset++) { - float calculatedDist = 0; - int xOffset = 0; - int yOffset = 0; - int loops = 0; - while (calculatedDist < dist) { - loops++; - BlockPos pos = new BlockPos(Math.floor(mc.thePlayer.posX) + xOffset, - Math.floor(mc.thePlayer.posY - 1) + yOffset, Math.floor(mc.thePlayer.posZ) + zOffset); - BlockPos above = new BlockPos(Math.floor(mc.thePlayer.posX) + xOffset, - Math.floor(mc.thePlayer.posY) + yOffset, Math.floor(mc.thePlayer.posZ) + zOffset); - if (mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:air")) { - yOffset--; - System.out.println("-" + pos + " " + yOffset + " " + mc.theWorld.getBlockState(pos).getBlock().getRegistryName() + " " + - mc.theWorld.getBlockState(above).getBlock().getRegistryName()); - } else if (mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:gold_block")) { - yOffset++; - System.out.println("+" + pos + " " + yOffset + " " + mc.theWorld.getBlockState(pos).getBlock().getRegistryName() + " " + - mc.theWorld.getBlockState(above).getBlock().getRegistryName()); - } else { - System.out.println("Calculating block distance"); - xOffset++; - calculatedDist = (float) round(mc.thePlayer.getDistance(pos.getX(), pos.getY() + 1, pos.getZ()), 1); - if (calculatedDist == dist && (mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:gold_block") - || mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:chest")) && - (possibleBlocks.size() == 0 || possibleBlocks.contains(pos))) { - temp.add(pos); + if (prevDist == dist && prevPos.getX() == mc.thePlayer.getPosition().getX() && prevPos.getY() == mc.thePlayer.getPosition().getY() && + prevPos.getZ() == mc.thePlayer.getPosition().getZ() && !locations.contains(mc.thePlayer.getPosition())) { + if (possibleBlocks.size() == 0) { + locations.add(mc.thePlayer.getPosition()); + for (int zOffset = Math.round(-dist); zOffset <= dist; zOffset++) { + for (int yOffset = 65; yOffset <= 70; yOffset++) { + float calculatedDist = 0; + int xOffset = 0; + while (calculatedDist < dist) { + BlockPos pos = new BlockPos(Math.floor(mc.thePlayer.posX) + xOffset, + yOffset, Math.floor(mc.thePlayer.posZ) + zOffset); + BlockPos above = new BlockPos(Math.floor(mc.thePlayer.posX) + xOffset, + yOffset + 1, Math.floor(mc.thePlayer.posZ) + zOffset); + xOffset++; + calculatedDist = round(mc.thePlayer.getDistance(pos.getX(), pos.getY() + 1, pos.getZ()), 1); + if (calculatedDist == dist && treasureAllowed(pos) && !possibleBlocks.contains(pos) && + mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:air")) { + possibleBlocks.add(pos); + } + xOffset++; + } + xOffset = 0; + calculatedDist = 0; + while (calculatedDist < dist) { + BlockPos pos = new BlockPos(Math.floor(mc.thePlayer.posX) - xOffset, + yOffset, Math.floor(mc.thePlayer.posZ) + zOffset); + BlockPos above = new BlockPos(Math.floor(mc.thePlayer.posX) - xOffset, + yOffset + 1, Math.floor(mc.thePlayer.posZ) + zOffset); + calculatedDist = round(mc.thePlayer.getDistance(pos.getX(), pos.getY() + 1, pos.getZ()), 1); + if (calculatedDist == dist && treasureAllowed(pos) && !possibleBlocks.contains(pos) && + mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:air")) { + possibleBlocks.add(pos); + } + xOffset++; } } - if (loops > 500) break; } - xOffset = 0; - calculatedDist = 0; - yOffset = 0; - loops = 0; - while (calculatedDist < dist) { - loops++; - BlockPos pos = new BlockPos(Math.floor(mc.thePlayer.posX) - xOffset, - Math.floor(mc.thePlayer.posY - 1) + yOffset, Math.floor(mc.thePlayer.posZ) + zOffset); - BlockPos above = new BlockPos(Math.floor(mc.thePlayer.posX) + xOffset, - Math.floor(mc.thePlayer.posY) + yOffset, Math.floor(mc.thePlayer.posZ) + zOffset); - if (mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:air")) { - yOffset--; - System.out.println("-" + pos + " " + yOffset + " " + mc.theWorld.getBlockState(pos).getBlock().getRegistryName() + " " + - mc.theWorld.getBlockState(above).getBlock().getRegistryName()); - } else if (mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:gold_block")) { - yOffset++; - System.out.println("+" + pos + " " + yOffset + " " + mc.theWorld.getBlockState(pos).getBlock().getRegistryName() + " " + - mc.theWorld.getBlockState(above).getBlock().getRegistryName()); - } else { - System.out.println("Calculating block distance"); - xOffset++; - calculatedDist = (float) round(mc.thePlayer.getDistance(pos.getX(), pos.getY() + 1, pos.getZ()), 1); - if (calculatedDist == dist && (mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:gold_block") - || mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:chest")) && - (possibleBlocks.size() == 0 || possibleBlocks.contains(pos))) { - temp.add(pos); - } + if (possibleBlocks.size() == 1) possibleBlocks.clear(); //protection from completely wrong things + sendMessage(); + } else if (possibleBlocks.size() != 1) { + locations.add(mc.thePlayer.getPosition()); + List temp = new ArrayList<>(); + for (BlockPos pos : possibleBlocks) { + if (round(mc.thePlayer.getDistance(pos.getX(), pos.getY() + 1, pos.getZ()), 1) == dist) { + temp.add(pos); } - if (loops > 500) break; } - } - possibleBlocks = temp; - System.out.println(possibleBlocks); - if (possibleBlocks.size() > 1) { - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "[NEU] Need another position to find solution. Possible blocks: " - + possibleBlocks.size())); - } else if (possibleBlocks.size() == 0) { - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[NEU] Failed to find solution.")); - } else { - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "[NEU] Found solution.")); + possibleBlocks = temp; + sendMessage(); } } - prev = dist; + prevPos = mc.thePlayer.getPosition(); + prevDist = dist; } } public static void reset() { possibleBlocks.clear(); - distances.clear(); + locations.clear(); } - public static void render(float partialTicks){ - if (SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("crystal_hollows") && possibleBlocks.size() == 1){ - RenderUtils.renderWayPoint("Treasure", possibleBlocks.get(0), partialTicks); + public static void render(float partialTicks) { + if (SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("crystal_hollows") && possibleBlocks.size() == 1) { + RenderUtils.renderWayPoint("Treasure", possibleBlocks.get(0).add(0, 2.5, 0), partialTicks); } } - private static double round(double value, int precision) { + private static float round(double value, int precision) { int scale = (int) Math.pow(10, precision); - return (double) Math.round(value * scale) / scale; + return (float) Math.round(value * scale) / scale; + } + + private static boolean treasureAllowed(BlockPos pos) { + return mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:gold_block") || + mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:prismarine") || + mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:chest") || + mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:stained_glass") || + mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:stained_glass_pane") || + mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:wool") || + mc.theWorld.getBlockState(pos).getBlock().getRegistryName().equals("minecraft:stained_hardened_clay"); + } + + private static void sendMessage() { + if (possibleBlocks.size() > 1) { + mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "[NEU] Need another position to find solution. Possible blocks: " + + possibleBlocks.size())); + } else if (possibleBlocks.size() == 0) { + mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[NEU] Failed to find solution.")); + reset(); + } else { + mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "[NEU] Found solution.")); + } } } -- cgit From 9c1e2163350c3a2eea843deda5c13d42594d85b0 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Thu, 19 Aug 2021 12:47:38 +0200 Subject: better math:tm: --- .../miscfeatures/CrystalMetalDetectorSolver.java | 27 ++++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'src') 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 2686272d..f30a792c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java @@ -3,10 +3,7 @@ package io.github.moulberry.notenoughupdates.miscfeatures; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.util.SBInfo; import net.minecraft.client.Minecraft; -import net.minecraft.util.BlockPos; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.IChatComponent; +import net.minecraft.util.*; import java.util.ArrayList; import java.util.List; @@ -27,7 +24,7 @@ public class CrystalMetalDetectorSolver { if (possibleBlocks.size() == 0) { locations.add(mc.thePlayer.getPosition()); for (int zOffset = Math.round(-dist); zOffset <= dist; zOffset++) { - for (int yOffset = 65; yOffset <= 70; yOffset++) { + for (int yOffset = 65; yOffset <= 69; yOffset++) { float calculatedDist = 0; int xOffset = 0; while (calculatedDist < dist) { @@ -36,7 +33,7 @@ public class CrystalMetalDetectorSolver { BlockPos above = new BlockPos(Math.floor(mc.thePlayer.posX) + xOffset, yOffset + 1, Math.floor(mc.thePlayer.posZ) + zOffset); xOffset++; - calculatedDist = round(mc.thePlayer.getDistance(pos.getX(), pos.getY() + 1, pos.getZ()), 1); + calculatedDist = round(calculateDistance(new Vec3(pos).addVector(0, 1d, 0), new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)), 1); if (calculatedDist == dist && treasureAllowed(pos) && !possibleBlocks.contains(pos) && mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:air")) { possibleBlocks.add(pos); @@ -50,7 +47,7 @@ public class CrystalMetalDetectorSolver { yOffset, Math.floor(mc.thePlayer.posZ) + zOffset); BlockPos above = new BlockPos(Math.floor(mc.thePlayer.posX) - xOffset, yOffset + 1, Math.floor(mc.thePlayer.posZ) + zOffset); - calculatedDist = round(mc.thePlayer.getDistance(pos.getX(), pos.getY() + 1, pos.getZ()), 1); + calculatedDist = round(calculateDistance(new Vec3(pos).addVector(0, 1d, 0), new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)), 1); if (calculatedDist == dist && treasureAllowed(pos) && !possibleBlocks.contains(pos) && mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:air")) { possibleBlocks.add(pos); @@ -65,7 +62,7 @@ public class CrystalMetalDetectorSolver { locations.add(mc.thePlayer.getPosition()); List temp = new ArrayList<>(); for (BlockPos pos : possibleBlocks) { - if (round(mc.thePlayer.getDistance(pos.getX(), pos.getY() + 1, pos.getZ()), 1) == dist) { + if (round(calculateDistance(new Vec3(pos).addVector(0, 1d, 0), new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)), 1) == dist) { temp.add(pos); } } @@ -84,8 +81,14 @@ public class CrystalMetalDetectorSolver { } public static void render(float partialTicks) { - if (SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("crystal_hollows") && possibleBlocks.size() == 1) { - RenderUtils.renderWayPoint("Treasure", possibleBlocks.get(0).add(0, 2.5, 0), partialTicks); + if (SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("crystal_hollows")) { + if (possibleBlocks.size() == 1) { + RenderUtils.renderWayPoint("Treasure", possibleBlocks.get(0).add(0, 2.5, 0), partialTicks); + } else { + for (BlockPos block : possibleBlocks) { + RenderUtils.renderWayPoint("Possible Treasure Location", block.add(0, 2.5, 0), partialTicks); + } + } } } @@ -115,4 +118,8 @@ public class CrystalMetalDetectorSolver { mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "[NEU] Found solution.")); } } + + private static float calculateDistance(Vec3 pos1, Vec3 pos2) { + return (float) Math.sqrt(Math.pow(pos2.xCoord - pos1.xCoord, 2) + Math.pow(pos2.yCoord - pos1.yCoord, 2) + Math.pow(pos2.zCoord - pos1.zCoord, 2)); + } } -- cgit From 3a1d5603de6e6e80adc80fa5535be1b05912d1f0 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Thu, 19 Aug 2021 12:55:35 +0200 Subject: moulBeFix --- .../notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') 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 f30a792c..ae6a2f5c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java @@ -23,7 +23,7 @@ public class CrystalMetalDetectorSolver { prevPos.getZ() == mc.thePlayer.getPosition().getZ() && !locations.contains(mc.thePlayer.getPosition())) { if (possibleBlocks.size() == 0) { locations.add(mc.thePlayer.getPosition()); - for (int zOffset = Math.round(-dist); zOffset <= dist; zOffset++) { + for (int zOffset = (int) Math.floor(-dist); zOffset <= Math.ceil(dist); zOffset++) { for (int yOffset = 65; yOffset <= 69; yOffset++) { float calculatedDist = 0; int xOffset = 0; @@ -120,6 +120,6 @@ public class CrystalMetalDetectorSolver { } private static float calculateDistance(Vec3 pos1, Vec3 pos2) { - return (float) Math.sqrt(Math.pow(pos2.xCoord - pos1.xCoord, 2) + Math.pow(pos2.yCoord - pos1.yCoord, 2) + Math.pow(pos2.zCoord - pos1.zCoord, 2)); + return (float) Math.sqrt(Math.pow(pos2.xCoord - pos1.xCoord, 2) + pos2.yCoord - pos1.yCoord + Math.pow(pos2.zCoord - pos1.zCoord, 2)); } } -- cgit From c8a767d0125dec4a1cc3d9fecddcb4aa3a45c301 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Thu, 19 Aug 2021 13:06:16 +0200 Subject: nvm --- .../notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') 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 ae6a2f5c..62f47787 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java @@ -120,6 +120,6 @@ public class CrystalMetalDetectorSolver { } private static float calculateDistance(Vec3 pos1, Vec3 pos2) { - return (float) Math.sqrt(Math.pow(pos2.xCoord - pos1.xCoord, 2) + pos2.yCoord - pos1.yCoord + Math.pow(pos2.zCoord - pos1.zCoord, 2)); + return (float) Math.sqrt(Math.pow(pos2.xCoord - pos1.xCoord, 2) + Math.pow(pos2.yCoord - pos1.yCoord, 2) + Math.pow(pos2.zCoord - pos1.zCoord, 2)); } } -- cgit From 80ef1d055cd685bf6dc643a2f51354d91f227862 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Thu, 19 Aug 2021 14:27:10 +0200 Subject: using less accurate calculations to have a higher probability of finding it even with some calculation errors --- .../miscfeatures/CrystalMetalDetectorSolver.java | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src') 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 62f47787..a21673da 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java @@ -24,7 +24,7 @@ public class CrystalMetalDetectorSolver { if (possibleBlocks.size() == 0) { locations.add(mc.thePlayer.getPosition()); for (int zOffset = (int) Math.floor(-dist); zOffset <= Math.ceil(dist); zOffset++) { - for (int yOffset = 65; yOffset <= 69; yOffset++) { + for (int yOffset = 65; yOffset <= 70; yOffset++) { float calculatedDist = 0; int xOffset = 0; while (calculatedDist < dist) { @@ -33,10 +33,11 @@ public class CrystalMetalDetectorSolver { BlockPos above = new BlockPos(Math.floor(mc.thePlayer.posX) + xOffset, yOffset + 1, Math.floor(mc.thePlayer.posZ) + zOffset); xOffset++; - calculatedDist = round(calculateDistance(new Vec3(pos).addVector(0, 1d, 0), new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)), 1); - if (calculatedDist == dist && treasureAllowed(pos) && !possibleBlocks.contains(pos) && + calculatedDist = calculateDistance(new Vec3(pos).addVector(0, 1d, 0), new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)); + if (inRange(calculatedDist, dist) && treasureAllowed(pos) && !possibleBlocks.contains(pos) && mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:air")) { possibleBlocks.add(pos); + System.out.println(calculatedDist); } xOffset++; } @@ -47,16 +48,16 @@ public class CrystalMetalDetectorSolver { yOffset, Math.floor(mc.thePlayer.posZ) + zOffset); BlockPos above = new BlockPos(Math.floor(mc.thePlayer.posX) - xOffset, yOffset + 1, Math.floor(mc.thePlayer.posZ) + zOffset); - calculatedDist = round(calculateDistance(new Vec3(pos).addVector(0, 1d, 0), new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)), 1); - if (calculatedDist == dist && treasureAllowed(pos) && !possibleBlocks.contains(pos) && + calculatedDist = calculateDistance(new Vec3(pos).addVector(0, 1d, 0), new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)); + if (inRange(calculatedDist, dist) && treasureAllowed(pos) && !possibleBlocks.contains(pos) && mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:air")) { possibleBlocks.add(pos); + System.out.println(calculatedDist); } xOffset++; } } } - if (possibleBlocks.size() == 1) possibleBlocks.clear(); //protection from completely wrong things sendMessage(); } else if (possibleBlocks.size() != 1) { locations.add(mc.thePlayer.getPosition()); @@ -66,6 +67,14 @@ public class CrystalMetalDetectorSolver { temp.add(pos); } } + if(temp.size() == 0){ + for (BlockPos pos : possibleBlocks) { + if (inRange(calculateDistance(new Vec3(pos).addVector(0, 1d, 0), new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)), dist)) { + temp.add(pos); + mc.thePlayer.addChatMessage(new ChatComponentText("Less accurate calculation")); + } + } + } possibleBlocks = temp; sendMessage(); } @@ -122,4 +131,8 @@ public class CrystalMetalDetectorSolver { private static float calculateDistance(Vec3 pos1, Vec3 pos2) { return (float) Math.sqrt(Math.pow(pos2.xCoord - pos1.xCoord, 2) + Math.pow(pos2.yCoord - pos1.yCoord, 2) + Math.pow(pos2.zCoord - pos1.zCoord, 2)); } + + private static boolean inRange(float number, float dist) { + return dist + 0.1D >= number && dist - 0.1D <= number; + } } -- cgit From 9bf3a34c63179cfa7df0272c10e1ad09268f42ab Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Thu, 19 Aug 2021 14:51:33 +0200 Subject: change --- .../miscfeatures/CrystalMetalDetectorSolver.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'src') 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 a21673da..22d8e59c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java @@ -63,18 +63,10 @@ public class CrystalMetalDetectorSolver { locations.add(mc.thePlayer.getPosition()); List temp = new ArrayList<>(); for (BlockPos pos : possibleBlocks) { - if (round(calculateDistance(new Vec3(pos).addVector(0, 1d, 0), new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)), 1) == dist) { + if (inRange(calculateDistance(new Vec3(pos).addVector(0, 1d, 0), new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)), dist)) { temp.add(pos); } } - if(temp.size() == 0){ - for (BlockPos pos : possibleBlocks) { - if (inRange(calculateDistance(new Vec3(pos).addVector(0, 1d, 0), new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)), dist)) { - temp.add(pos); - mc.thePlayer.addChatMessage(new ChatComponentText("Less accurate calculation")); - } - } - } possibleBlocks = temp; sendMessage(); } -- cgit From f26c7b84a9e2d72d4ba3e7b03283697bfe610ea8 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Thu, 19 Aug 2021 16:07:46 +0200 Subject: finalize --- .../miscfeatures/CrystalMetalDetectorSolver.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') 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 22d8e59c..24496593 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java @@ -37,7 +37,6 @@ public class CrystalMetalDetectorSolver { if (inRange(calculatedDist, dist) && treasureAllowed(pos) && !possibleBlocks.contains(pos) && mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:air")) { possibleBlocks.add(pos); - System.out.println(calculatedDist); } xOffset++; } @@ -52,7 +51,6 @@ public class CrystalMetalDetectorSolver { if (inRange(calculatedDist, dist) && treasureAllowed(pos) && !possibleBlocks.contains(pos) && mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:air")) { possibleBlocks.add(pos); - System.out.println(calculatedDist); } xOffset++; } @@ -63,10 +61,18 @@ public class CrystalMetalDetectorSolver { locations.add(mc.thePlayer.getPosition()); List temp = new ArrayList<>(); for (BlockPos pos : possibleBlocks) { - if (inRange(calculateDistance(new Vec3(pos).addVector(0, 1d, 0), new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)), dist)) { + if (round(calculateDistance(new Vec3(pos).addVector(0, 1d, 0), new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)), 1) + == dist) { temp.add(pos); } } + if(temp.size() == 0) { + for (BlockPos pos : possibleBlocks) { + if (inRange(calculateDistance(new Vec3(pos).addVector(0, 1d, 0), new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)), dist)) { + temp.add(pos); + } + } + } possibleBlocks = temp; sendMessage(); } @@ -125,6 +131,6 @@ public class CrystalMetalDetectorSolver { } private static boolean inRange(float number, float dist) { - return dist + 0.1D >= number && dist - 0.1D <= number; + return dist + 0.15D >= number && dist - 0.15D <= number; } } -- cgit From daf03820a63662b3024e1722a587c8fffd694b3b Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Thu, 19 Aug 2021 16:13:01 +0200 Subject: fix crash that might happen --- .../java/io/github/moulberry/notenoughupdates/NEUEventListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java index a8be9991..2e108d21 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java @@ -836,7 +836,7 @@ public class NEUEventListener { e.message = new ChatComponentText(m2); } } - if (unformatted.startsWith("You found ") && SBInfo.getInstance().getLocation().equals("crystal_hollows")){ + if (unformatted.startsWith("You found ") && SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("crystal_hollows")){ CrystalMetalDetectorSolver.reset(); } } -- cgit From d525edf7b6395250feefb8b930d7234574721aba Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Thu, 19 Aug 2021 18:24:35 +0200 Subject: config options --- .../miscfeatures/CrystalMetalDetectorSolver.java | 8 ++++--- .../options/seperateSections/Mining.java | 26 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) (limited to 'src') 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 24496593..b95675bc 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java @@ -1,5 +1,6 @@ package io.github.moulberry.notenoughupdates.miscfeatures; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.util.SBInfo; import net.minecraft.client.Minecraft; @@ -19,12 +20,13 @@ public class CrystalMetalDetectorSolver { if (SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("crystal_hollows") && message.getUnformattedText().contains("TREASURE: ")) { float dist = Float.parseFloat(message.getUnformattedText().split("TREASURE: ")[1].split("m")[0].replaceAll("(?!\\.)\\D", "")); - if (prevDist == dist && prevPos.getX() == mc.thePlayer.getPosition().getX() && prevPos.getY() == mc.thePlayer.getPosition().getY() && + if (NotEnoughUpdates.INSTANCE.config.mining.metalDetectorEnabled && prevDist == dist && prevPos.getX() == mc.thePlayer.getPosition().getX() && + prevPos.getY() == mc.thePlayer.getPosition().getY() && prevPos.getZ() == mc.thePlayer.getPosition().getZ() && !locations.contains(mc.thePlayer.getPosition())) { if (possibleBlocks.size() == 0) { locations.add(mc.thePlayer.getPosition()); for (int zOffset = (int) Math.floor(-dist); zOffset <= Math.ceil(dist); zOffset++) { - for (int yOffset = 65; yOffset <= 70; yOffset++) { + for (int yOffset = 65; yOffset <= 75; yOffset++) { float calculatedDist = 0; int xOffset = 0; while (calculatedDist < dist) { @@ -91,7 +93,7 @@ public class CrystalMetalDetectorSolver { if (SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("crystal_hollows")) { if (possibleBlocks.size() == 1) { RenderUtils.renderWayPoint("Treasure", possibleBlocks.get(0).add(0, 2.5, 0), partialTicks); - } else { + } else if(possibleBlocks.size() > 1 && NotEnoughUpdates.INSTANCE.config.mining.metalDetectorShowPossible) { for (BlockPos block : possibleBlocks) { RenderUtils.renderWayPoint("Possible Treasure Location", block.add(0, 2.5, 0), partialTicks); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java index 157da202..2c05b462 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java @@ -139,6 +139,32 @@ public class Mining { @ConfigAccordionId(id = 2) public int overlayStyle = 0; + @ConfigOption( + name = "Metal Detector Solver", + desc = "" + ) + @ConfigEditorAccordion(id = 3) + public boolean metalDetectorSolverAccordion = false; + + @Expose + @ConfigOption( + name = "Enabled", + desc = "Enabled the metal detector solver for Mines of Divan, to use this stand still to calculate possible blocks and then if required stand" + + " still on another block." + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 3) + public boolean metalDetectorEnabled = true; + + @Expose + @ConfigOption( + name = "Show Possible Blocks", + desc = "Show waypoints on possible locations when NEU isn't sure about what block the treasure is." + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 3) + public boolean metalDetectorShowPossible = false; + @Expose @ConfigOption( name = "Puzzler Solver", -- cgit From c518e81a6e4165c1736414c2cf45a19bb5acb355 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Fri, 20 Aug 2021 12:30:12 +0200 Subject: better --- .../miscfeatures/CrystalMetalDetectorSolver.java | 41 +++++++++++----------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'src') 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 b95675bc..c6ad2ef1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java @@ -12,30 +12,30 @@ import java.util.List; public class CrystalMetalDetectorSolver { private static final Minecraft mc = Minecraft.getMinecraft(); private static BlockPos prevPos; - private static float prevDist = 0; + private static double prevDist = 0; private static List possibleBlocks = new ArrayList<>(); private static final List locations = new ArrayList<>(); public static void process(IChatComponent message) { if (SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("crystal_hollows") && message.getUnformattedText().contains("TREASURE: ")) { - float dist = Float.parseFloat(message.getUnformattedText().split("TREASURE: ")[1].split("m")[0].replaceAll("(?!\\.)\\D", "")); + double dist = Double.parseDouble(message.getUnformattedText().split("TREASURE: ")[1].split("m")[0].replaceAll("(?!\\.)\\D", "")); if (NotEnoughUpdates.INSTANCE.config.mining.metalDetectorEnabled && prevDist == dist && prevPos.getX() == mc.thePlayer.getPosition().getX() && prevPos.getY() == mc.thePlayer.getPosition().getY() && prevPos.getZ() == mc.thePlayer.getPosition().getZ() && !locations.contains(mc.thePlayer.getPosition())) { if (possibleBlocks.size() == 0) { locations.add(mc.thePlayer.getPosition()); for (int zOffset = (int) Math.floor(-dist); zOffset <= Math.ceil(dist); zOffset++) { - for (int yOffset = 65; yOffset <= 75; yOffset++) { - float calculatedDist = 0; + for (int y = 65; y <= 75; y++) { + double calculatedDist = 0; int xOffset = 0; while (calculatedDist < dist) { BlockPos pos = new BlockPos(Math.floor(mc.thePlayer.posX) + xOffset, - yOffset, Math.floor(mc.thePlayer.posZ) + zOffset); + y, Math.floor(mc.thePlayer.posZ) + zOffset); BlockPos above = new BlockPos(Math.floor(mc.thePlayer.posX) + xOffset, - yOffset + 1, Math.floor(mc.thePlayer.posZ) + zOffset); + y + 1, Math.floor(mc.thePlayer.posZ) + zOffset); xOffset++; - calculatedDist = calculateDistance(new Vec3(pos).addVector(0, 1d, 0), new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)); + calculatedDist = getPlayerPos().distanceTo(new Vec3(pos).addVector(0D,1D,0D)); if (inRange(calculatedDist, dist) && treasureAllowed(pos) && !possibleBlocks.contains(pos) && mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:air")) { possibleBlocks.add(pos); @@ -46,10 +46,10 @@ public class CrystalMetalDetectorSolver { calculatedDist = 0; while (calculatedDist < dist) { BlockPos pos = new BlockPos(Math.floor(mc.thePlayer.posX) - xOffset, - yOffset, Math.floor(mc.thePlayer.posZ) + zOffset); + y, Math.floor(mc.thePlayer.posZ) + zOffset); BlockPos above = new BlockPos(Math.floor(mc.thePlayer.posX) - xOffset, - yOffset + 1, Math.floor(mc.thePlayer.posZ) + zOffset); - calculatedDist = calculateDistance(new Vec3(pos).addVector(0, 1d, 0), new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)); + y + 1, Math.floor(mc.thePlayer.posZ) + zOffset); + calculatedDist = getPlayerPos().distanceTo(new Vec3(pos).addVector(0D,1D,0D)); if (inRange(calculatedDist, dist) && treasureAllowed(pos) && !possibleBlocks.contains(pos) && mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:air")) { possibleBlocks.add(pos); @@ -63,14 +63,14 @@ public class CrystalMetalDetectorSolver { locations.add(mc.thePlayer.getPosition()); List temp = new ArrayList<>(); for (BlockPos pos : possibleBlocks) { - if (round(calculateDistance(new Vec3(pos).addVector(0, 1d, 0), new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)), 1) + if (round(getPlayerPos().distanceTo(new Vec3(pos).addVector(0D,1D,0D)), 1) == dist) { temp.add(pos); } } - if(temp.size() == 0) { + if (temp.size() == 0) { for (BlockPos pos : possibleBlocks) { - if (inRange(calculateDistance(new Vec3(pos).addVector(0, 1d, 0), new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)), dist)) { + if (inRange(getPlayerPos().distanceTo(new Vec3(pos).addVector(0D,1D,0D)), dist)) { temp.add(pos); } } @@ -93,7 +93,7 @@ public class CrystalMetalDetectorSolver { if (SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("crystal_hollows")) { if (possibleBlocks.size() == 1) { RenderUtils.renderWayPoint("Treasure", possibleBlocks.get(0).add(0, 2.5, 0), partialTicks); - } else if(possibleBlocks.size() > 1 && NotEnoughUpdates.INSTANCE.config.mining.metalDetectorShowPossible) { + } else if (possibleBlocks.size() > 1 && NotEnoughUpdates.INSTANCE.config.mining.metalDetectorShowPossible) { for (BlockPos block : possibleBlocks) { RenderUtils.renderWayPoint("Possible Treasure Location", block.add(0, 2.5, 0), partialTicks); } @@ -101,9 +101,9 @@ public class CrystalMetalDetectorSolver { } } - private static float round(double value, int precision) { + private static double round(double value, int precision) { int scale = (int) Math.pow(10, precision); - return (float) Math.round(value * scale) / scale; + return (double) Math.round(value * scale) / scale; } private static boolean treasureAllowed(BlockPos pos) { @@ -128,11 +128,12 @@ public class CrystalMetalDetectorSolver { } } - private static float calculateDistance(Vec3 pos1, Vec3 pos2) { - return (float) Math.sqrt(Math.pow(pos2.xCoord - pos1.xCoord, 2) + Math.pow(pos2.yCoord - pos1.yCoord, 2) + Math.pow(pos2.zCoord - pos1.zCoord, 2)); + + private static boolean inRange(double number, double dist) { + return dist + 0.1D >= number && dist - 0.1D <= number; } - private static boolean inRange(float number, float dist) { - return dist + 0.15D >= number && dist - 0.15D <= number; + private static Vec3 getPlayerPos() { + return new Vec3(mc.thePlayer.posX, mc.thePlayer.posY + (mc.thePlayer.getEyeHeight() - mc.thePlayer.getDefaultEyeHeight()), mc.thePlayer.posZ); } } -- cgit