aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock/dwarven
diff options
context:
space:
mode:
authorAaron <51387595+AzureAaron@users.noreply.github.com>2024-04-18 02:12:29 -0400
committerAaron <51387595+AzureAaron@users.noreply.github.com>2024-04-18 02:12:29 -0400
commita7103075422e9989ac204fa84bd1f92486b72077 (patch)
tree4921fc5081da1f9a00b0425253142d29d17a6ad1 /src/main/java/de/hysky/skyblocker/skyblock/dwarven
parentb6f8394d5b08a53242e6cd06132ab2dd2f7f9186 (diff)
downloadSkyblocker-a7103075422e9989ac204fa84bd1f92486b72077.tar.gz
Skyblocker-a7103075422e9989ac204fa84bd1f92486b72077.tar.bz2
Skyblocker-a7103075422e9989ac204fa84bd1f92486b72077.zip
Refactor Metal Detector
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/dwarven')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dwarven/MetalDetector.java144
1 files changed, 68 insertions, 76 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MetalDetector.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MetalDetector.java
index e302b778..84154e12 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MetalDetector.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MetalDetector.java
@@ -11,6 +11,7 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
+import net.minecraft.util.Util;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
@@ -21,73 +22,66 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MetalDetector {
-
private static final MinecraftClient CLIENT = MinecraftClient.getInstance();
-
private static final float[] LIGHT_GRAY = { 192 / 255f, 192 / 255f, 192 / 255f };
-
private static final Pattern TREASURE_PATTERN = Pattern.compile("(§3§lTREASURE: §b)(\\d+\\.\\d)m");
-
private static final Pattern KEEPER_PATTERN = Pattern.compile("Keeper of (\\w+)");
- private static final HashMap<String, Vec3i> keeperOffsets = new HashMap<>() {{
- put("Diamond", new Vec3i(33, 0, 3));
- put("Lapis", new Vec3i(-33, 0, -3));
- put("Emerald", new Vec3i(-3, 0, 33));
- put("Gold", new Vec3i(3, 0, -33));
- }};
-
- private static final HashSet<Vec3i> knownChestOffsets = new HashSet<>(Arrays.asList(
- new Vec3i(-38, -22, 26), // -38, -22, 26
- new Vec3i(38, -22, -26), // 38, -22, -26
- new Vec3i(-40, -22, 18), // -40, -22, 18
- new Vec3i(-41, -20, 22), // -41, -20, 22
- new Vec3i(-5, -21, 16), // -5, -21, 16
- new Vec3i(40, -22, -30), // 40, -22, -30
- new Vec3i(-42, -20, -28), // -42, -20, -28
- new Vec3i(-43, -22, -40), // -43, -22, -40
- new Vec3i(42, -19, -41), // 42, -19, -41
- new Vec3i(43, -21, -16), // 43, -21, -16
- new Vec3i(-1, -22, -20), // -1, -22, -20
- new Vec3i(6, -21, 28), // 6, -21, 28
- new Vec3i(7, -21, 11), // 7, -21, 11
- new Vec3i(7, -21, 22), // 7, -21, 22
- new Vec3i(-12, -21, -44), // -12, -21, -44
- new Vec3i(12, -22, 31), // 12, -22, 31
- new Vec3i(12, -22, -22), // 12, -22, -22
- new Vec3i(12, -21, 7), // 12, -21, 7
- new Vec3i(12, -21, -43), // 12, -21, -43
- new Vec3i(-14, -21, 43), // -14, -21, 43
- new Vec3i(-14, -21, 22), // -14, -21, 22
- new Vec3i(-17, -21, 20), // -17, -21, 20
- new Vec3i(-20, -22, 0), // -20, -22, 0
- new Vec3i(1, -21, 20), // 1, -21, 20
- new Vec3i(19, -22, 29), // 19, -22, 29
- new Vec3i(20, -22, 0), // 20, -22, 0
- new Vec3i(20, -21, -26), // 20, -21, -26
- new Vec3i(-23, -22, 40), // -23, -22, 40
- new Vec3i(22, -21, -14), // 22, -21, -14
- new Vec3i(-24, -22, 12), // -24, -22, 12
- new Vec3i(23, -22, 26), // 23, -22, 26
- new Vec3i(23, -22, -39), // 23, -22, -39
- new Vec3i(24, -22, 27), // 24, -22, 27
- new Vec3i(25, -22, 17), // 25, -22, 17
- new Vec3i(29, -21, -44), // 29, -21, -44
- new Vec3i(-31, -21, -12), // -31, -21, -12
- new Vec3i(-31, -21, -40), // -31, -21, -40
- new Vec3i(30, -21, -25), // 30, -21, -25
- new Vec3i(-32, -21, -40), // -32, -21, -40
- new Vec3i(-36, -20, 42), // -36, -20, 42
- new Vec3i(-37, -21, -14), // -37, -21, -14
- new Vec3i(-37, -21, -22) // -37, -21, -22
- ));
+ private static final HashMap<String, Vec3i> keeperOffsets = Util.make(new HashMap<>(), map -> {
+ map.put("Diamond", new Vec3i(33, 0, 3));
+ map.put("Lapis", new Vec3i(-33, 0, -3));
+ map.put("Emerald", new Vec3i(-3, 0, 33));
+ map.put("Gold", new Vec3i(3, 0, -33));
+ });
+ private static final HashSet<Vec3i> knownChestOffsets = Util.make(new HashSet<>(), set -> {
+ set.add(new Vec3i(-38, -22, 26)); // -38, -22, 26
+ set.add(new Vec3i(38, -22, -26)); // 38, -22, -26
+ set.add(new Vec3i(-40, -22, 18)); // -40, -22, 18
+ set.add(new Vec3i(-41, -20, 22)); // -41, -20, 22
+ set.add(new Vec3i(-5, -21, 16)); // -5, -21, 16
+ set.add(new Vec3i(40, -22, -30)); // 40, -22, -30
+ set.add(new Vec3i(-42, -20, -28)); // -42, -20, -28
+ set.add(new Vec3i(-43, -22, -40)); // -43, -22, -40
+ set.add(new Vec3i(42, -19, -41)); // 42, -19, -41
+ set.add(new Vec3i(43, -21, -16)); // 43, -21, -16
+ set.add(new Vec3i(-1, -22, -20)); // -1, -22, -20
+ set.add(new Vec3i(6, -21, 28)); // 6, -21, 28
+ set.add(new Vec3i(7, -21, 11)); // 7, -21, 11
+ set.add(new Vec3i(7, -21, 22)); // 7, -21, 22
+ set.add(new Vec3i(-12, -21, -44)); // -12, -21, -44
+ set.add(new Vec3i(12, -22, 31)); // 12, -22, 31
+ set.add(new Vec3i(12, -22, -22)); // 12, -22, -22
+ set.add(new Vec3i(12, -21, 7)); // 12, -21, 7
+ set.add(new Vec3i(12, -21, -43)); // 12, -21, -43
+ set.add(new Vec3i(-14, -21, 43)); // -14, -21, 43
+ set.add(new Vec3i(-14, -21, 22)); // -14, -21, 22
+ set.add(new Vec3i(-17, -21, 20)); // -17, -21, 20
+ set.add(new Vec3i(-20, -22, 0)); // -20, -22, 0
+ set.add(new Vec3i(1, -21, 20)); // 1, -21, 20
+ set.add(new Vec3i(19, -22, 29)); // 19, -22, 29
+ set.add(new Vec3i(20, -22, 0)); // 20, -22, 0
+ set.add(new Vec3i(20, -21, -26)); // 20, -21, -26
+ set.add(new Vec3i(-23, -22, 40)); // -23, -22, 40
+ set.add(new Vec3i(22, -21, -14)); // 22, -21, -14
+ set.add(new Vec3i(-24, -22, 12)); // -24, -22, 12
+ set.add(new Vec3i(23, -22, 26)); // 23, -22, 26
+ set.add(new Vec3i(23, -22, -39)); // 23, -22, -39
+ set.add(new Vec3i(24, -22, 27)); // 24, -22, 27
+ set.add(new Vec3i(25, -22, 17)); // 25, -22, 17
+ set.add(new Vec3i(29, -21, -44)); // 29, -21, -44
+ set.add(new Vec3i(-31, -21, -12)); // -31, -21, -12
+ set.add(new Vec3i(-31, -21, -40)); // -31, -21, -40
+ set.add(new Vec3i(30, -21, -25)); // 30, -21, -25
+ set.add(new Vec3i(-32, -21, -40)); // -32, -21, -40
+ set.add(new Vec3i(-36, -20, 42)); // -36, -20, 42
+ set.add(new Vec3i(-37, -21, -14)); // -37, -21, -14
+ set.add(new Vec3i(-37, -21, -22)); // -37, -21, -22
+ });
protected static Vec3i minesCenter = null;
private static double previousDistance;
private static Vec3d previousPlayerPos;
protected static boolean newTreasure = true;
-
private static boolean startedLooking = false;
-
protected static List<Vec3i> possibleBlocks = new ArrayList<>();
public static void init() {
@@ -96,7 +90,7 @@ public class MetalDetector {
}
private static void getDistanceMessage(Text text, boolean overlay) {
- if (!overlay || !SkyblockerConfigManager.get().locations.dwarvenMines.MetalDetectorHelper || !Utils.isInCrystalHollows() || !(Utils.getIslandArea().substring(2).equals("Mines of Divan")) || CLIENT.player == null) {
+ if (!overlay || !SkyblockerConfigManager.get().locations.dwarvenMines.metalDetectorHelper || !Utils.isInCrystalHollows() || !(Utils.getIslandArea().substring(2).equals("Mines of Divan")) || CLIENT.player == null) {
checkChestFound(text);
return;
}
@@ -113,7 +107,7 @@ public class MetalDetector {
//send message when starting looking about how to use mod
if (!startedLooking) {
startedLooking = true;
- CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.MetalDetectorHelper.startTip")),false);
+ CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.dwarvenMines.metalDetectorHelper.startTip")), false);
}
//find the center of the mines if possible to speed up search
@@ -129,10 +123,9 @@ public class MetalDetector {
//if the amount of possible blocks has changed output that to the user
if (possibleBlocks.size() != previousPossibleBlockCount) {
if (possibleBlocks.size() == 1) {
- CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.MetalDetectorHelper.foundTreasureMessage").formatted(Formatting.GREEN)),false);
- }
- else {
- CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.MetalDetectorHelper.possibleTreasureLocationsMessage").append(Text.of(String.valueOf(possibleBlocks.size())))),false);
+ CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.dwarvenMines.metalDetectorHelper.foundTreasureMessage").formatted(Formatting.GREEN)), false);
+ } else {
+ CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.dwarvenMines.metalDetectorHelper.possibleTreasureLocationsMessage").append(Text.of(String.valueOf(possibleBlocks.size())))), false);
}
}
@@ -151,22 +144,21 @@ public class MetalDetector {
}
}
- protected static void updatePossibleBlocks(Double distance, Vec3d playerPos) {
+ protected static void updatePossibleBlocks(double distance, Vec3d playerPos) {
if (newTreasure) {
possibleBlocks = new ArrayList<>();
newTreasure = false;
- if (minesCenter != null) {//if center of the mines is known use the predefined offsets to filter the locations
+ if (minesCenter != null) { //if center of the mines is known use the predefined offsets to filter the locations
for (Vec3i knownOffset : knownChestOffsets) {
- Vec3i checkPos = minesCenter.add(knownOffset).add(0,1,0);
+ Vec3i checkPos = minesCenter.add(knownOffset).add(0, 1, 0);
if (Math.abs(playerPos.distanceTo(Vec3d.of(checkPos)) - distance) < 0.25) {
possibleBlocks.add(checkPos);
}
}
- }
- else {
- for (int x = -distance.intValue(); x <= distance; x++) {
- for (int z = -distance.intValue(); z <= distance; z++) {
- Vec3i checkPos =new Vec3i((int)(playerPos.x) + x, (int)playerPos.y, (int)playerPos.z + z);
+ } else {
+ for (int x = (int) -distance; x <= distance; x++) {
+ for (int z = (int) -distance; z <= distance; z++) {
+ Vec3i checkPos = new Vec3i((int) playerPos.x + x, (int) playerPos.y, (int) playerPos.z + z);
if (Math.abs(playerPos.distanceTo(Vec3d.of(checkPos)) - distance) < 0.25) {
possibleBlocks.add(checkPos);
}
@@ -182,7 +174,7 @@ public class MetalDetector {
if (possibleBlocks.isEmpty()) {
newTreasure = true;
if (CLIENT.player != null) {
- CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.MetalDetectorHelper.somethingWentWrongMessage").formatted(Formatting.RED)),false);
+ CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.dwarvenMines.metalDetectorHelper.somethingWentWrongMessage").formatted(Formatting.RED)), false);
}
}
}
@@ -201,7 +193,7 @@ public class MetalDetector {
if (nameMatcher.matches()) {
Vec3i offset = keeperOffsets.get(nameMatcher.group(1));
minesCenter = armorStand.getBlockPos().add(offset);
- CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.MetalDetectorHelper.foundCenter").formatted(Formatting.GREEN)),false);
+ CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.dwarvenMines.metalDetectorHelper.foundCenter").formatted(Formatting.GREEN)), false);
return;
}
}
@@ -209,20 +201,20 @@ public class MetalDetector {
private static void render(WorldRenderContext context) {
//only render enabled and if there is a few location options and in the mines of divan
- if (!SkyblockerConfigManager.get().locations.dwarvenMines.MetalDetectorHelper || possibleBlocks.isEmpty() || possibleBlocks.size() > 8 || !(Utils.getIslandArea().substring(2).equals("Mines of Divan"))) {
+ if (!SkyblockerConfigManager.get().locations.dwarvenMines.metalDetectorHelper || possibleBlocks.isEmpty() || possibleBlocks.size() > 8 || !(Utils.getIslandArea().substring(2).equals("Mines of Divan"))) {
return;
}
//only one location render just that and guiding line to it
if (possibleBlocks.size() == 1) {
Vec3i block = possibleBlocks.get(0).add(0, -1, 0); //the block you are taken to is one block above the chest
- CrystalsWaypoint waypoint = new CrystalsWaypoint(CrystalsWaypoint.Category.MINES_OF_DIVAN, Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.MetalDetectorHelper.treasure"), new BlockPos(block.getX(), block.getY(), block.getZ()));
+ CrystalsWaypoint waypoint = new CrystalsWaypoint(CrystalsWaypoint.Category.MINES_OF_DIVAN, Text.translatable("skyblocker.dwarvenMines.metalDetectorHelper.treasure"), new BlockPos(block.getX(), block.getY(), block.getZ()));
waypoint.render(context);
RenderHelper.renderLineFromCursor(context, Vec3d.ofCenter(block), LIGHT_GRAY, 1f, 5f);
return;
}
for (Vec3i block : possibleBlocks) {
- CrystalsWaypoint waypoint = new CrystalsWaypoint(CrystalsWaypoint.Category.MINES_OF_DIVAN, Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.MetalDetectorHelper.possible"), new BlockPos(block.getX(), block.getY(), block.getZ()));
+ CrystalsWaypoint waypoint = new CrystalsWaypoint(CrystalsWaypoint.Category.MINES_OF_DIVAN, Text.translatable("skyblocker.dwarvenMines.metalDetectorHelper.possible"), new BlockPos(block.getX(), block.getY(), block.getZ()));
waypoint.render(context);
}
}