aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java114
1 files changed, 83 insertions, 31 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 73e2b412..5e9c59ac 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java
@@ -11,82 +11,113 @@ import java.util.List;
public class CrystalMetalDetectorSolver {
private static final Minecraft mc = Minecraft.getMinecraft();
- private static BlockPos prevPos;
- private static double prevDist = 0;
+ private static BlockPos prevPlayerPos;
+ private static double prevDistToTreasure = 0;
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 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())) {
+ double distToTreasure = Double.parseDouble(message.getUnformattedText().split("TREASURE: ")[1].split("m")[0].replaceAll("(?!\\.)\\D", ""));
+ if (NotEnoughUpdates.INSTANCE.config.mining.metalDetectorEnabled && prevDistToTreasure == distToTreasure &&
+ prevPlayerPos.getX() == mc.thePlayer.getPosition().getX() &&
+ prevPlayerPos.getY() == mc.thePlayer.getPosition().getY() &&
+ prevPlayerPos.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 zOffset = (int) Math.floor(-distToTreasure); zOffset <= Math.ceil(distToTreasure); zOffset++) {
for (int y = 65; y <= 75; y++) {
double calculatedDist = 0;
int xOffset = 0;
- while (calculatedDist < dist) {
+ while (calculatedDist < distToTreasure) {
BlockPos pos = new BlockPos(Math.floor(mc.thePlayer.posX) + xOffset,
y, Math.floor(mc.thePlayer.posZ) + zOffset);
- BlockPos above = new BlockPos(Math.floor(mc.thePlayer.posX) + xOffset,
- y + 1, Math.floor(mc.thePlayer.posZ) + zOffset);
calculatedDist = getPlayerPos().distanceTo(new Vec3(pos).addVector(0D, 1D, 0D));
- if (round(calculatedDist, 1) == dist && treasureAllowed(pos) && !possibleBlocks.contains(pos) &&
- mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:air")) {
+ if (round(calculatedDist, 1) == distToTreasure && !possibleBlocks.contains(pos)) {
possibleBlocks.add(pos);
}
xOffset++;
}
xOffset = 0;
calculatedDist = 0;
- while (calculatedDist < dist) {
+ while (calculatedDist < distToTreasure) {
BlockPos pos = new BlockPos(Math.floor(mc.thePlayer.posX) - xOffset,
y, Math.floor(mc.thePlayer.posZ) + zOffset);
- BlockPos above = new BlockPos(Math.floor(mc.thePlayer.posX) - xOffset,
- y + 1, Math.floor(mc.thePlayer.posZ) + zOffset);
calculatedDist = getPlayerPos().distanceTo(new Vec3(pos).addVector(0D, 1D, 0D));
- if (round(calculatedDist, 1) == dist && treasureAllowed(pos) && !possibleBlocks.contains(pos) &&
- mc.theWorld.getBlockState(above).getBlock().getRegistryName().equals("minecraft:air")) {
+ if (round(calculatedDist, 1) == distToTreasure && !possibleBlocks.contains(pos)) {
possibleBlocks.add(pos);
}
xOffset++;
}
}
}
+ removeDuplicates();
sendMessage();
} else if (possibleBlocks.size() != 1) {
locations.add(mc.thePlayer.getPosition());
List<BlockPos> temp = new ArrayList<>();
for (BlockPos pos : possibleBlocks) {
- if (round(getPlayerPos().distanceTo(new Vec3(pos).addVector(0D, 1D, 0D)), 1) == dist) {
+ if (round(getPlayerPos().distanceTo(new Vec3(pos).addVector(0D, 1D, 0D)), 1) == distToTreasure) {
temp.add(pos);
}
}
possibleBlocks = temp;
+ removeDuplicates();
sendMessage();
+ } else if (possibleBlocks.size() == 1) {
+ BlockPos pos = possibleBlocks.get(0);
+ if (distToTreasure > (5 + getPlayerPos().distanceTo(new Vec3(pos)))) {
+ mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[NEU] Previous solution is invalid."));
+ reset(false);
+ }
}
+
}
- prevPos = mc.thePlayer.getPosition();
- prevDist = dist;
+
+ prevPlayerPos = mc.thePlayer.getPosition();
+ prevDistToTreasure = distToTreasure;
}
}
- public static void reset() {
+ public static void reset(Boolean chestFound) {
+ chestRecentlyFound = chestFound;
possibleBlocks.clear();
locations.clear();
}
public static void render(float partialTicks) {
+ int beaconRGB = 0xa839ce;
+
if (SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("crystal_hollows") &&
SBInfo.getInstance().location.equals("Mines of Divan")) {
+
if (possibleBlocks.size() == 1) {
+ BlockPos block = possibleBlocks.get(0);
+
+ RenderUtils.renderBeaconBeam(block, beaconRGB, 1.0f, partialTicks);
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 && (locations.size() > 1 || possibleBlocks.size() < 10) &&
+ NotEnoughUpdates.INSTANCE.config.mining.metalDetectorShowPossible) {
for (BlockPos block : possibleBlocks) {
+ RenderUtils.renderBeaconBeam(block, beaconRGB, 1.0f, partialTicks);
RenderUtils.renderWayPoint("Possible Treasure Location", block.add(0, 2.5, 0), partialTicks);
}
}
@@ -98,14 +129,35 @@ public class CrystalMetalDetectorSolver {
return (double) 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 removeDuplicates() {
+ if (possibleBlocks.size() > 1 && possibleBlocks.size() < 10) {
+ 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 blockPos = possibleBlocks.get(i);
+ Vec3 blockVec = new Vec3(blockPos.getX(), 0, blockPos.getZ());
+
+ if (firstBlockVec.distanceTo(blockVec) > 3) {
+ allBlocksAreClose = false;
+ break;
+ }
+
+ if (blockPos.getY() < lowestY) {
+ lowestY = blockPos.getY();
+ lowestYIndex = i;
+ }
+ }
+
+ if (allBlocksAreClose) {
+ List<BlockPos> temp = new ArrayList<>();
+ temp.add(possibleBlocks.get(lowestYIndex));
+ possibleBlocks = temp;
+ }
+ }
}
private static void sendMessage() {
@@ -114,7 +166,7 @@ public class CrystalMetalDetectorSolver {
+ possibleBlocks.size()));
} else if (possibleBlocks.size() == 0) {
mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[NEU] Failed to find solution."));
- reset();
+ reset(false);
} else {
mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "[NEU] Found solution."));
}