diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2021-08-18 23:57:30 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2021-08-18 23:57:30 +0200 |
commit | b87e2135d394ea66f0f09e5db63a1c842558d9be (patch) | |
tree | f65d01a060cb9c349418c7ad027609c87e641037 /src | |
parent | cb4d7f49fdb6d244b19b7f991a5ef606012ae1a5 (diff) | |
download | NotEnoughUpdates-b87e2135d394ea66f0f09e5db63a1c842558d9be.tar.gz NotEnoughUpdates-b87e2135d394ea66f0f09e5db63a1c842558d9be.tar.bz2 NotEnoughUpdates-b87e2135d394ea66f0f09e5db63a1c842558d9be.zip |
code
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java | 1 | ||||
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java | 164 |
2 files changed, 78 insertions, 87 deletions
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<BlockPos> possibleBlocks = new ArrayList<>(); - private static final List<Float> distances = new ArrayList<>(); + private static final List<BlockPos> 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<BlockPos> 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<BlockPos> 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.")); + } } } |