diff options
author | David Mills <85420839+Keebler408@users.noreply.github.com> | 2021-09-09 11:21:08 -0500 |
---|---|---|
committer | David Mills <85420839+Keebler408@users.noreply.github.com> | 2021-09-09 11:21:08 -0500 |
commit | 935ecebae26a2551ab330e0f0e28c8233df852e8 (patch) | |
tree | 11f47e82b04726707e3887b8947e783a74e9e14e /src/main | |
parent | fdd335dbf42c792e95cb3cafc1b91821fa2ca00f (diff) | |
download | NotEnoughUpdates-935ecebae26a2551ab330e0f0e28c8233df852e8.tar.gz NotEnoughUpdates-935ecebae26a2551ab330e0f0e28c8233df852e8.tar.bz2 NotEnoughUpdates-935ecebae26a2551ab330e0f0e28c8233df852e8.zip |
Use proximity for dupes, delay after finding chest
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java | 41 |
1 files changed, 28 insertions, 13 deletions
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 3fbff9c8..b457f274 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java @@ -16,7 +16,24 @@ public class CrystalMetalDetectorSolver { private static List<BlockPos> possibleBlocks = new ArrayList<>(); private static final List<BlockPos> locations = new ArrayList<>(); + private static Boolean chestRecentlyFound = false; + private static long chestLastFoundMillis = 0; + public static void process(IChatComponent message) { + // Delay to keep old chest location from being treated as the new chest location + if (chestRecentlyFound) { + long currentTimeMillis = System.currentTimeMillis(); + if (chestLastFoundMillis == 0) { + chestLastFoundMillis = currentTimeMillis; + return; + } else if(currentTimeMillis - chestLastFoundMillis < 1000) { + return; + } + + chestLastFoundMillis = 0; + chestRecentlyFound = false; + } + if (SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("crystal_hollows") && message.getUnformattedText().contains("TREASURE: ")) { double distToTreasure = Double.parseDouble(message.getUnformattedText().split("TREASURE: ")[1].split("m")[0].replaceAll("(?!\\.)\\D", "")); @@ -81,10 +98,7 @@ public class CrystalMetalDetectorSolver { } public static void reset(Boolean chestFound) { - if (chestFound) { - // TODO: Add a delay to keep the old chest location from being treated as the new chest location - } - + chestRecentlyFound = chestFound; possibleBlocks.clear(); locations.clear(); } @@ -124,27 +138,28 @@ public class CrystalMetalDetectorSolver { private static void removeDuplicates() { if (possibleBlocks.size() > 1 && possibleBlocks.size() < 7) { - double firstX = possibleBlocks.get(0).getX(); - double firstZ = possibleBlocks.get(0).getZ(); - Boolean yOnlyDiffers = true; + Vec3 firstBlockVec = new Vec3( possibleBlocks.get(0).getX(), 0, possibleBlocks.get(0).getZ()); + Boolean allBlocksAreClose = true; double lowestY = possibleBlocks.get(0).getY(); int lowestYIndex = 0; for (int i = 1; i < possibleBlocks.size(); i++) { - BlockPos block = possibleBlocks.get(i); - if (block.getX() != firstX || block.getZ() != firstZ) { - yOnlyDiffers = false; + BlockPos blockPos = possibleBlocks.get(i); + Vec3 blockVec = new Vec3(blockPos.getX(), 0, blockPos.getZ()); + + if (firstBlockVec.distanceTo(blockVec) > 3) { + allBlocksAreClose = false; break; } - if (block.getY() < lowestY) { - lowestY = block.getY(); + if (blockPos.getY() < lowestY) { + lowestY = blockPos.getY(); lowestYIndex = i; } } - if (yOnlyDiffers) { + if (allBlocksAreClose) { List<BlockPos> temp = new ArrayList<>(); temp.add(possibleBlocks.get(lowestYIndex)); possibleBlocks = temp; |