aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java
diff options
context:
space:
mode:
authorMoulberry <jjenour@student.unimelb.edu.au>2021-10-13 15:46:13 +0800
committerGitHub <noreply@github.com>2021-10-13 15:46:13 +0800
commitb11742988dec635b5c5da7c2363803cbfafb37b1 (patch)
treed161c7ab2f675dd1f82d2fe8194d7e62bbdaac0a /src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java
parent8eee6262a6e2c372240331f3c43c2279bd18539e (diff)
parent030f72bb49ab4bca0c35899090550432c5aa0bea (diff)
downloadnotenoughupdates-b11742988dec635b5c5da7c2363803cbfafb37b1.tar.gz
notenoughupdates-b11742988dec635b5c5da7c2363803cbfafb37b1.tar.bz2
notenoughupdates-b11742988dec635b5c5da7c2363803cbfafb37b1.zip
Merge pull request #231 from DoKM/master
DoKM Fork Merge
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.java94
1 files changed, 62 insertions, 32 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..b2cd7cb2 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java
@@ -11,46 +11,60 @@ 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) && treasureAllowed(pos) && mc.theWorld.
+ getBlockState(pos.add(0, 1, 0)).getBlock().getRegistryName().equals("minecraft:air")) {
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) && treasureAllowed(pos) && mc.theWorld.
+ getBlockState(pos.add(0, 1, 0)).getBlock().getRegistryName().equals("minecraft:air")) {
possibleBlocks.add(pos);
}
xOffset++;
@@ -62,31 +76,47 @@ public class CrystalMetalDetectorSolver {
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;
sendMessage();
+ } else {
+ BlockPos pos = possibleBlocks.get(0);
+ if (Math.abs(distToTreasure - (getPlayerPos().distanceTo(new Vec3(pos)))) > 5) {
+ 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 = 0xffdf00;
+
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.add(0,1,0), 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) {
for (BlockPos block : possibleBlocks) {
+ RenderUtils.renderBeaconBeam(block.add(0,1,0), beaconRGB, 1.0f, partialTicks);
RenderUtils.renderWayPoint("Possible Treasure Location", block.add(0, 2.5, 0), partialTicks);
}
}
@@ -98,23 +128,13 @@ 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 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();
+ reset(false);
} else {
mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "[NEU] Found solution."));
}
@@ -123,4 +143,14 @@ public class CrystalMetalDetectorSolver {
private static Vec3 getPlayerPos() {
return new Vec3(mc.thePlayer.posX, mc.thePlayer.posY + (mc.thePlayer.getEyeHeight() - mc.thePlayer.getDefaultEyeHeight()), mc.thePlayer.posZ);
}
+
+ 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");
+ }
}