From 2fd4ca4e9042329a9af4e7cce76c72a3225d656d Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Sat, 21 Oct 2023 05:20:11 -0400 Subject: Room Position Command --- .../skyblock/dungeon/secrets/DungeonSecrets.java | 36 +++++++++++++++++++++- .../skyblocker/skyblock/dungeon/secrets/Room.java | 14 +++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java index cb9615fb..d143a3c2 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java @@ -7,6 +7,10 @@ import com.mojang.brigadier.Command; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; + +import it.unimi.dsi.fastutil.ints.IntRBTreeSet; +import it.unimi.dsi.fastutil.ints.IntSortedSet; +import it.unimi.dsi.fastutil.ints.IntSortedSets; import it.unimi.dsi.fastutil.objects.Object2ByteMap; import it.unimi.dsi.fastutil.objects.Object2ByteOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectIntPair; @@ -37,6 +41,8 @@ import net.minecraft.text.Text; import net.minecraft.util.ActionResult; import net.minecraft.util.Identifier; import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.hit.HitResult; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import org.jetbrains.annotations.Contract; @@ -149,7 +155,9 @@ public class DungeonSecrets { UseBlockCallback.EVENT.register((player, world, hand, hitResult) -> onUseBlock(world, hitResult)); ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(literal(SkyblockerMod.NAMESPACE).then(literal("dungeons").then(literal("secrets") .then(literal("markAsFound").then(markSecretsCommand(true))) - .then(literal("markAsMissing").then(markSecretsCommand(false))))))); + .then(literal("markAsMissing").then(markSecretsCommand(false))) + .then(literal("getPos").executes(context -> registerPosCommand(context.getSource(), false))) + .then(literal("getFacingPos").executes(context -> registerPosCommand(context.getSource(), true))))))); ClientPlayConnectionEvents.JOIN.register(((handler, sender, client) -> reset())); } @@ -222,6 +230,32 @@ public class DungeonSecrets { return Command.SINGLE_SUCCESS; }); } + + //TODO This logic can be split into a separate method for when we want to allow for adding custom waypoints + private static int registerPosCommand(FabricClientCommandSource source, boolean facing) { + if (currentRoom != null && currentRoom.getDirection() != null) { + MinecraftClient client = MinecraftClient.getInstance(); + + if (facing && (client.crosshairTarget == null || client.crosshairTarget.getType() != HitResult.Type.BLOCK)) { + source.sendError(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.unableToFindPos"))); + + return Command.SINGLE_SUCCESS; + } + + BlockPos blockToCheck = facing && client.crosshairTarget instanceof BlockHitResult blockHitResult ? blockHitResult.getBlockPos() : client.player.getBlockPos(); + IntSortedSet segmentsX = IntSortedSets.unmodifiable(new IntRBTreeSet(currentRoom.getSegments().stream().mapToInt(Vector2ic::x).toArray())); + IntSortedSet segmentsY = IntSortedSets.unmodifiable(new IntRBTreeSet(currentRoom.getSegments().stream().mapToInt(Vector2ic::y).toArray())); + Vector2ic physicalCornerPos = DungeonMapUtils.getPhysicalCornerPos(currentRoom.getDirection(), segmentsX, segmentsY); + + BlockPos relativePos = DungeonMapUtils.actualToRelative(currentRoom.getDirection(), physicalCornerPos, blockToCheck); + + source.sendFeedback(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.posMessage", relativePos.getX(), relativePos.getY(), relativePos.getZ()))); + } else { + source.sendError(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.unableToFindPos"))); + } + + return Command.SINGLE_SUCCESS; + } /** * Updates the dungeon. The general idea is similar to the Dungeon Rooms Mod. diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java index dd7dc91e..6e7ee953 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java @@ -28,6 +28,7 @@ import net.minecraft.world.World; import org.apache.commons.lang3.tuple.MutableTriple; import org.apache.commons.lang3.tuple.Triple; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.joml.Vector2i; import org.joml.Vector2ic; @@ -72,6 +73,7 @@ public class Room { */ private TriState matched = TriState.DEFAULT; private Table secretWaypoints; + private Direction direction = null; public Room(@NotNull Type type, @NotNull Vector2ic... physicalPositions) { this.type = type; @@ -91,6 +93,16 @@ public class Room { public boolean isMatched() { return matched == TriState.TRUE; } + + @Nullable + public Direction getDirection() { + return direction; + } + + @NotNull + public Set getSegments() { + return segments; + } @Override public String toString() { @@ -297,6 +309,8 @@ public class Room { } secretWaypoints = ImmutableTable.copyOf(secretWaypointsMutable); matched = TriState.TRUE; + this.direction = direction; + DungeonSecrets.LOGGER.info("[Skyblocker] Room {} matched after checking {} block(s)", name, checkedBlocks.size()); } -- cgit From 9cc09de788ce6f1003a92d1bdedabe8f0fd20c4e Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Sun, 22 Oct 2023 04:01:26 -0400 Subject: Add AOTV & Pearl Secret Waypoints --- .../hysky/skyblocker/config/SkyblockerConfig.java | 6 ++ .../config/categories/DungeonsCategory.java | 15 +++++ .../skyblock/dungeon/secrets/DungeonSecrets.java | 2 +- .../skyblocker/skyblock/dungeon/secrets/Room.java | 13 ++++- .../skyblock/dungeon/secrets/SecretWaypoint.java | 4 ++ .../skyblocker/dungeons/secretlocations.json | 65 +++++++++++++++++++++- .../resources/assets/skyblocker/lang/en_us.json | 5 +- 7 files changed, 104 insertions(+), 6 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java index d7279bc8..3f39c933 100644 --- a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java @@ -605,6 +605,12 @@ public class SkyblockerConfig { @SerialEntry public boolean enableStonkWaypoints = true; + + @SerialEntry + public boolean enableAotvWaypoints = true; + + @SerialEntry + public boolean enablePearlWaypoints = true; @SerialEntry public boolean enableDefaultWaypoints = true; diff --git a/src/main/java/de/hysky/skyblocker/config/categories/DungeonsCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/DungeonsCategory.java index 7b32cb78..0101eccf 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/DungeonsCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/DungeonsCategory.java @@ -122,6 +122,21 @@ public class DungeonsCategory { newValue -> config.locations.dungeons.secretWaypoints.enableStonkWaypoints = newValue) .controller(ConfigUtils::createBooleanController) .build()) + .option(Option.createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints.enableAotvWaypoints")) + .binding(defaults.locations.dungeons.secretWaypoints.enableAotvWaypoints, + () -> config.locations.dungeons.secretWaypoints.enableAotvWaypoints, + newValue -> config.locations.dungeons.secretWaypoints.enableAotvWaypoints = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) + .option(Option.createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints.enablePearlWaypoints")) + .description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints.enablePearlWaypoints.@Tooltip"))) + .binding(defaults.locations.dungeons.secretWaypoints.enablePearlWaypoints, + () -> config.locations.dungeons.secretWaypoints.enablePearlWaypoints, + newValue -> config.locations.dungeons.secretWaypoints.enablePearlWaypoints = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) .option(Option.createBuilder() .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints.enableDefaultWaypoints")) .description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints.enableDefaultWaypoints.@Tooltip"))) diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java index d143a3c2..d01305f9 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java @@ -249,7 +249,7 @@ public class DungeonSecrets { BlockPos relativePos = DungeonMapUtils.actualToRelative(currentRoom.getDirection(), physicalCornerPos, blockToCheck); - source.sendFeedback(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.posMessage", relativePos.getX(), relativePos.getY(), relativePos.getZ()))); + source.sendFeedback(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.posMessage", currentRoom.getName(), relativePos.getX(), relativePos.getY(), relativePos.getZ()))); } else { source.sendError(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.unableToFindPos"))); } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java index 6e7ee953..79b13d3b 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java @@ -74,6 +74,7 @@ public class Room { private TriState matched = TriState.DEFAULT; private Table secretWaypoints; private Direction direction = null; + private String name = null; public Room(@NotNull Type type, @NotNull Vector2ic... physicalPositions) { this.type = type; @@ -90,6 +91,11 @@ public class Room { return type; } + @NotNull + public Set getSegments() { + return segments; + } + public boolean isMatched() { return matched == TriState.TRUE; } @@ -99,9 +105,9 @@ public class Room { return direction; } - @NotNull - public Set getSegments() { - return segments; + @Nullable + public String getName() { + return name; } @Override @@ -310,6 +316,7 @@ public class Room { secretWaypoints = ImmutableTable.copyOf(secretWaypointsMutable); matched = TriState.TRUE; this.direction = direction; + this.name = name; DungeonSecrets.LOGGER.info("[Skyblocker] Room {} matched after checking {} block(s)", name, checkedBlocks.size()); } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypoint.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypoint.java index 0d9bdff1..a520c73f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypoint.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypoint.java @@ -112,6 +112,8 @@ public class SecretWaypoint { LEVER(secretWaypoints -> secretWaypoints.enableLeverWaypoints, 250, 217, 2), FAIRYSOUL(secretWaypoints -> secretWaypoints.enableFairySoulWaypoints, 255, 85, 255), STONK(secretWaypoints -> secretWaypoints.enableStonkWaypoints, 146, 52, 235), + AOTV(secretWaypoints -> secretWaypoints.enableAotvWaypoints, 252, 98, 3), + PEARL(secretWaypoints -> secretWaypoints.enablePearlWaypoints, 57, 117, 125), DEFAULT(secretWaypoints -> secretWaypoints.enableDefaultWaypoints, 190, 255, 252); private final Predicate enabledPredicate; private final float[] colorComponents; @@ -135,6 +137,8 @@ public class SecretWaypoint { case "lever" -> Category.LEVER; case "fairysoul" -> Category.FAIRYSOUL; case "stonk" -> Category.STONK; + case "aotv" -> Category.AOTV; + case "pearl" -> Category.PEARL; default -> Category.DEFAULT; }; } diff --git a/src/main/resources/assets/skyblocker/dungeons/secretlocations.json b/src/main/resources/assets/skyblocker/dungeons/secretlocations.json index d5e38345..5972659f 100644 --- a/src/main/resources/assets/skyblocker/dungeons/secretlocations.json +++ b/src/main/resources/assets/skyblocker/dungeons/secretlocations.json @@ -834,6 +834,13 @@ "y":75, "z":21 }, + { + "secretName":"2 - AOTV", + "category":"aotv", + "x":25, + "y":76, + "z":22 + }, { "secretName":"2 - Stonk", "category":"stonk", @@ -2947,7 +2954,7 @@ "category":"stonk", "x":17, "y":70, - "z":15 + "z":14 }, { "secretName":"6 - Pressure Plate 2", @@ -3058,6 +3065,13 @@ "y":70, "z":5 }, + { + "secretName":"2 - AOTV", + "category":"aotv", + "x":77, + "y":82, + "z":16 + }, { "secretName":"2 - Wither Essence", "category":"wither", @@ -3109,6 +3123,13 @@ "y":50, "z":9 }, + { + "secretName":"3 - AOTV", + "category":"aotv", + "x":7, + "y":80, + "z":15 + }, { "secretName":"3 - Superboom", "category":"superboom", @@ -3225,6 +3246,13 @@ "y":89, "z":24 }, + { + "secretName":"1/2 - AOTV", + "category":"aotv", + "x":84, + "y":91, + "z":26 + }, { "secretName":"1 - Bat", "category":"bat", @@ -4071,6 +4099,13 @@ "y":109, "z":30 }, + { + "secretName":"5 - AOTV", + "category":"aotv", + "x":52, + "y":78, + "z":9 + }, { "secretName":"5 - Crypt", "category":"superboom", @@ -5080,6 +5115,13 @@ "y":86, "z":61 }, + { + "secretName": "7 - AOTV", + "category":"aotv", + "x":39, + "y":84, + "z":58 + }, { "secretName":"7 - Chest", "category":"chest", @@ -5331,6 +5373,13 @@ "y":85, "z":43 }, + { + "secretName":"3/4 - AOTV", + "category":"aotv", + "x":49, + "y":83, + "z":36 + }, { "secretName":"3 - Chest", "category":"chest", @@ -5552,6 +5601,13 @@ "y":45, "z":15 }, + { + "secretName":"5 - Pearl", + "category":"pearl", + "x":8, + "y":59, + "z":14 + }, { "secretName":"5 - Entrance", "category":"entrance", @@ -5835,6 +5891,13 @@ } ], "Double-Stair-3":[ + { + "secretName":"1 - Pearl", + "category":"pearl", + "x":24, + "y":72, + "z":11 + }, { "secretName":"1 - Wither Essence", "category":"wither", diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index b42ab1e3..a6bf6b49 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -164,6 +164,9 @@ "text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints.enableLeverWaypoints" : "Enable Lever Waypoints", "text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints.enableFairySoulWaypoints" : "Enable Fairy Soul Waypoints", "text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints.enableStonkWaypoints" : "Enable Stonk Waypoints", + "text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints.enableAotvWaypoints" : "Enable AOTV Waypoints", + "text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints.enablePearlWaypoints": "Enable Pearl Waypoints", + "text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints.enablePearlWaypoints.@Tooltip": "With these waypoints, you throw a pearl towards the block and at the same time AOTV up.", "text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints.enableDefaultWaypoints" : "Enable Default Waypoints", "text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints.enableDefaultWaypoints.@Tooltip" : "This includes all waypoints that do not belong to a category.", "text.autoconfig.skyblocker.option.locations.dungeons.dungeonChestProfit": "Dungeon Chest Profit Calculator", @@ -272,7 +275,7 @@ "skyblocker.dungeons.secrets.markSecretMissing": "§rMarked secret #%d as missing.", "skyblocker.dungeons.secrets.markSecretFoundUnable": "§cUnable to mark secret #%d as found.", "skyblocker.dungeons.secrets.markSecretMissingUnable": "§cUnable to mark secret #%d as missing.", - "skyblocker.dungeons.secrets.posMessage": "§rRoom Pos: X: %d, Y: %d, Z: %d", + "skyblocker.dungeons.secrets.posMessage": "§rRoom: %s, X: %d, Y: %d, Z: %d", "skyblocker.dungeons.secrets.unableToFindPos": "§cUnable to find room position! (Are you in a dungeon room, are you facing a block?)", "skyblocker.fishing.reelNow": "Reel in now!", -- cgit From 69eb16bb751e0717444189e15efdc2be6cf90f44 Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Sun, 22 Oct 2023 16:15:37 -0400 Subject: Fix waypoints not disappearing in boss --- .../skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java index d01305f9..96b4a7c9 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java @@ -377,6 +377,13 @@ public class DungeonSecrets { if (overlay && isCurrentRoomMatched()) { currentRoom.onChatMessage(text.getString()); } + + String message = text.getString(); + + if (message.equals("[BOSS] Bonzo: Gratz for making it this far, but I'm basically unbeatable.") || message.equals("[BOSS] Scarf: This is where the journey ends for you, Adventurers.") + || message.equals("[BOSS] The Professor: I was burdened with terrible news recently...") || message.equals("[BOSS] Thorn: Welcome Adventurers! I am Thorn, the Spirit! And host of the Vegan Trials!") + || message.equals("[BOSS] Livid: Welcome, you've arrived right on time. I am Livid, the Master of Shadows.") || message.equals("[BOSS] Sadan: So you made it all the way here... Now you wish to defy me? Sadan?!") + || message.equals("[BOSS] Maxor: WELL! WELL! WELL! LOOK WHO'S HERE!")) reset(); } /** @@ -474,7 +481,7 @@ public class DungeonSecrets { } /** - * Resets fields when leaving a dungeon. + * Resets fields when leaving a dungeon or entering boss. */ private static void reset() { mapEntrancePos = null; -- cgit From 12d3086e9506e6e120c492ea99dcc6e84738ce3b Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Sun, 22 Oct 2023 22:02:05 -0400 Subject: Refactor DungeonSecrets --- .../skyblock/dungeon/secrets/DungeonSecrets.java | 66 ++++++++++------------ .../skyblocker/skyblock/dungeon/secrets/Room.java | 48 +++++++++------- .../resources/assets/skyblocker/lang/en_us.json | 3 +- 3 files changed, 60 insertions(+), 57 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java index 96b4a7c9..07cb0395 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java @@ -7,18 +7,14 @@ import com.mojang.brigadier.Command; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; - -import it.unimi.dsi.fastutil.ints.IntRBTreeSet; -import it.unimi.dsi.fastutil.ints.IntSortedSet; -import it.unimi.dsi.fastutil.ints.IntSortedSets; -import it.unimi.dsi.fastutil.objects.Object2ByteMap; -import it.unimi.dsi.fastutil.objects.Object2ByteOpenHashMap; -import it.unimi.dsi.fastutil.objects.ObjectIntPair; import de.hysky.skyblocker.SkyblockerMod; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.utils.Constants; import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.scheduler.Scheduler; +import it.unimi.dsi.fastutil.objects.Object2ByteMap; +import it.unimi.dsi.fastutil.objects.Object2ByteOpenHashMap; +import it.unimi.dsi.fastutil.objects.ObjectIntPair; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; @@ -156,8 +152,8 @@ public class DungeonSecrets { ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(literal(SkyblockerMod.NAMESPACE).then(literal("dungeons").then(literal("secrets") .then(literal("markAsFound").then(markSecretsCommand(true))) .then(literal("markAsMissing").then(markSecretsCommand(false))) - .then(literal("getPos").executes(context -> registerPosCommand(context.getSource(), false))) - .then(literal("getFacingPos").executes(context -> registerPosCommand(context.getSource(), true))))))); + .then(literal("getRelativePos").executes(context -> getRelativePos(context.getSource()))) + .then(literal("getRelativeTargetPos").executes(context -> getRelativeTargetPos(context.getSource()))))))); ClientPlayConnectionEvents.JOIN.register(((handler, sender, client) -> reset())); } @@ -212,8 +208,9 @@ public class DungeonSecrets { /** * Loads the json from the given {@link BufferedReader} into the given {@link Map}. + * * @param reader the reader to read the json from - * @param map the map to load into + * @param map the map to load into */ private static void loadJson(BufferedReader reader, Map map) { SkyblockerMod.GSON.fromJson(reader, JsonObject.class).asMap().forEach((room, jsonElement) -> map.put(room.toLowerCase().replaceAll(" ", "-"), jsonElement)); @@ -230,30 +227,27 @@ public class DungeonSecrets { return Command.SINGLE_SUCCESS; }); } - - //TODO This logic can be split into a separate method for when we want to allow for adding custom waypoints - private static int registerPosCommand(FabricClientCommandSource source, boolean facing) { - if (currentRoom != null && currentRoom.getDirection() != null) { - MinecraftClient client = MinecraftClient.getInstance(); - - if (facing && (client.crosshairTarget == null || client.crosshairTarget.getType() != HitResult.Type.BLOCK)) { - source.sendError(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.unableToFindPos"))); - - return Command.SINGLE_SUCCESS; - } - BlockPos blockToCheck = facing && client.crosshairTarget instanceof BlockHitResult blockHitResult ? blockHitResult.getBlockPos() : client.player.getBlockPos(); - IntSortedSet segmentsX = IntSortedSets.unmodifiable(new IntRBTreeSet(currentRoom.getSegments().stream().mapToInt(Vector2ic::x).toArray())); - IntSortedSet segmentsY = IntSortedSets.unmodifiable(new IntRBTreeSet(currentRoom.getSegments().stream().mapToInt(Vector2ic::y).toArray())); - Vector2ic physicalCornerPos = DungeonMapUtils.getPhysicalCornerPos(currentRoom.getDirection(), segmentsX, segmentsY); + private static int getRelativePos(FabricClientCommandSource source) { + return getRelativePos(source, source.getPlayer().getBlockPos()); + } - BlockPos relativePos = DungeonMapUtils.actualToRelative(currentRoom.getDirection(), physicalCornerPos, blockToCheck); + private static int getRelativeTargetPos(FabricClientCommandSource source) { + if (MinecraftClient.getInstance().crosshairTarget instanceof BlockHitResult blockHitResult && blockHitResult.getType() == HitResult.Type.BLOCK) { + return getRelativePos(source, blockHitResult.getBlockPos()); + } else { + source.sendError(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.noTarget"))); + } + return Command.SINGLE_SUCCESS; + } + private static int getRelativePos(FabricClientCommandSource source, BlockPos pos) { + if (isCurrentRoomMatched()) { + BlockPos relativePos = DungeonMapUtils.actualToRelative(currentRoom.getDirection(), currentRoom.getPhysicalCornerPos(), pos); source.sendFeedback(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.posMessage", currentRoom.getName(), relativePos.getX(), relativePos.getY(), relativePos.getZ()))); - } else { - source.sendError(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.unableToFindPos"))); - } - + } else { + source.sendError(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.notMatched"))); + } return Command.SINGLE_SUCCESS; } @@ -374,16 +368,16 @@ public class DungeonSecrets { * Used to detect when all secrets in a room are found. */ private static void onChatMessage(Text text, boolean overlay) { + String message = text.getString(); + if (overlay && isCurrentRoomMatched()) { - currentRoom.onChatMessage(text.getString()); + currentRoom.onChatMessage(message); } - String message = text.getString(); - if (message.equals("[BOSS] Bonzo: Gratz for making it this far, but I'm basically unbeatable.") || message.equals("[BOSS] Scarf: This is where the journey ends for you, Adventurers.") - || message.equals("[BOSS] The Professor: I was burdened with terrible news recently...") || message.equals("[BOSS] Thorn: Welcome Adventurers! I am Thorn, the Spirit! And host of the Vegan Trials!") - || message.equals("[BOSS] Livid: Welcome, you've arrived right on time. I am Livid, the Master of Shadows.") || message.equals("[BOSS] Sadan: So you made it all the way here... Now you wish to defy me? Sadan?!") - || message.equals("[BOSS] Maxor: WELL! WELL! WELL! LOOK WHO'S HERE!")) reset(); + || message.equals("[BOSS] The Professor: I was burdened with terrible news recently...") || message.equals("[BOSS] Thorn: Welcome Adventurers! I am Thorn, the Spirit! And host of the Vegan Trials!") + || message.equals("[BOSS] Livid: Welcome, you've arrived right on time. I am Livid, the Master of Shadows.") || message.equals("[BOSS] Sadan: So you made it all the way here... Now you wish to defy me? Sadan?!") + || message.equals("[BOSS] Maxor: WELL! WELL! WELL! LOOK WHO'S HERE!")) reset(); } /** diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java index 79b13d3b..8d8d0757 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java @@ -5,10 +5,10 @@ import com.google.common.collect.ImmutableTable; import com.google.common.collect.Table; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import de.hysky.skyblocker.utils.scheduler.Scheduler; import it.unimi.dsi.fastutil.ints.IntRBTreeSet; import it.unimi.dsi.fastutil.ints.IntSortedSet; import it.unimi.dsi.fastutil.ints.IntSortedSets; -import de.hysky.skyblocker.utils.scheduler.Scheduler; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.fabricmc.fabric.api.util.TriState; import net.minecraft.block.BlockState; @@ -28,7 +28,6 @@ import net.minecraft.world.World; import org.apache.commons.lang3.tuple.MutableTriple; import org.apache.commons.lang3.tuple.Triple; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.joml.Vector2i; import org.joml.Vector2ic; @@ -73,8 +72,10 @@ public class Room { */ private TriState matched = TriState.DEFAULT; private Table secretWaypoints; - private Direction direction = null; - private String name = null; + private String name; + private Direction direction; + + private Vector2ic physicalCornerPos; public Room(@NotNull Type type, @NotNull Vector2ic... physicalPositions) { this.type = type; @@ -91,23 +92,29 @@ public class Room { return type; } - @NotNull - public Set getSegments() { - return segments; - } - public boolean isMatched() { return matched == TriState.TRUE; } - - @Nullable + + /** + * Not null if {@link #isMatched()}. + */ + public String getName() { + return name; + } + + /** + * Not null if {@link #isMatched()}. + */ public Direction getDirection() { return direction; } - - @Nullable - public String getName() { - return name; + + /** + * Not null if {@link #isMatched()}. + */ + public Vector2ic getPhysicalCornerPos() { + return physicalCornerPos; } @Override @@ -235,7 +242,7 @@ public class Room { * *
  • If there are exactly one room matching:
  • *
      - *
    • Call {@link #roomMatched(String, Direction, Vector2ic)}.
    • + *
    • Call {@link #roomMatched()}.
    • *
    • Discard the no longer needed fields to save memory.
    • *
    • Return {@code true}
    • *
    @@ -274,7 +281,10 @@ public class Room { // If one room matches, load the secrets for that room and discard the no longer needed fields. for (Triple> directionRooms : possibleRooms) { if (directionRooms.getRight().size() == 1) { - roomMatched(directionRooms.getRight().get(0), directionRooms.getLeft(), directionRooms.getMiddle()); + name = directionRooms.getRight().get(0); + direction = directionRooms.getLeft(); + physicalCornerPos = directionRooms.getMiddle(); + roomMatched(); discard(); return true; } @@ -304,7 +314,7 @@ public class Room { * @param directionRooms the direction, position, and name of the room */ @SuppressWarnings("JavadocReference") - private void roomMatched(String name, Direction direction, Vector2ic physicalCornerPos) { + private void roomMatched() { Table secretWaypointsMutable = HashBasedTable.create(); for (JsonElement waypointElement : DungeonSecrets.getRoomWaypoints(name)) { JsonObject waypoint = waypointElement.getAsJsonObject(); @@ -315,8 +325,6 @@ public class Room { } secretWaypoints = ImmutableTable.copyOf(secretWaypointsMutable); matched = TriState.TRUE; - this.direction = direction; - this.name = name; DungeonSecrets.LOGGER.info("[Skyblocker] Room {} matched after checking {} block(s)", name, checkedBlocks.size()); } diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index a6bf6b49..b6edb5f8 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -276,7 +276,8 @@ "skyblocker.dungeons.secrets.markSecretFoundUnable": "§cUnable to mark secret #%d as found.", "skyblocker.dungeons.secrets.markSecretMissingUnable": "§cUnable to mark secret #%d as missing.", "skyblocker.dungeons.secrets.posMessage": "§rRoom: %s, X: %d, Y: %d, Z: %d", - "skyblocker.dungeons.secrets.unableToFindPos": "§cUnable to find room position! (Are you in a dungeon room, are you facing a block?)", + "skyblocker.dungeons.secrets.noTarget": "§cNo target block found! (Are you pointing at a block in range?)", + "skyblocker.dungeons.secrets.notMatched": "§cThe current room is not matched! (Are you in a dungeon room?)", "skyblocker.fishing.reelNow": "Reel in now!", "skyblocker.rift.healNow": "Heal now!", -- cgit From 54bf37cc7860ce0d8467a058d81cbcf07af2bd7d Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Sun, 22 Oct 2023 22:02:05 -0400 Subject: Refactor DungeonSecrets --- .../skyblock/dungeon/secrets/DungeonMapUtils.java | 3 +- .../skyblock/dungeon/secrets/DungeonSecrets.java | 19 ++++++++++-- .../skyblocker/skyblock/dungeon/secrets/Room.java | 34 ++++++++++------------ 3 files changed, 34 insertions(+), 22 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java index 259cc3f3..73d4a452 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java @@ -7,7 +7,6 @@ import net.minecraft.block.MapColor; import net.minecraft.item.map.MapIcon; import net.minecraft.item.map.MapState; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; import org.jetbrains.annotations.NotNull; @@ -173,7 +172,7 @@ public class DungeonMapUtils { @NotNull public static Vector2ic getPhysicalRoomPos(double x, double z) { Vector2i physicalPos = new Vector2i(x + 8.5, z + 8.5, RoundingMode.TRUNCATE); - return physicalPos.sub(MathHelper.floorMod(physicalPos.x(), 32), MathHelper.floorMod(physicalPos.y(), 32)).sub(8, 8); + return physicalPos.sub(Math.floorMod(physicalPos.x(), 32), Math.floorMod(physicalPos.y(), 32)).sub(8, 8); } public static Vector2ic[] getPhysicalPosFromMap(Vector2ic mapEntrancePos, int mapRoomSize, Vector2ic physicalEntrancePos, Vector2ic... mapPositions) { diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java index 07cb0395..08b84852 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java @@ -40,6 +40,7 @@ import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.Vec3i; import net.minecraft.world.World; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -242,8 +243,9 @@ public class DungeonSecrets { } private static int getRelativePos(FabricClientCommandSource source, BlockPos pos) { - if (isCurrentRoomMatched()) { - BlockPos relativePos = DungeonMapUtils.actualToRelative(currentRoom.getDirection(), currentRoom.getPhysicalCornerPos(), pos); + Room room = getRoomAtPhysical(pos); + if (isRoomMatched(room)) { + BlockPos relativePos = currentRoom.actualToRelative(pos); source.sendFeedback(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.posMessage", currentRoom.getName(), relativePos.getX(), relativePos.getY(), relativePos.getZ()))); } else { source.sendError(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.notMatched"))); @@ -445,6 +447,19 @@ public class DungeonSecrets { return rooms.get(DungeonMapUtils.getPhysicalRoomPos(pos)); } + /** + * Gets the room at the given physical position. + * + * @param pos the physical position + * @return the room at the given physical position, or null if there is no room at the given physical position + * @see #rooms + * @see DungeonMapUtils#getPhysicalRoomPos(Vec3i) + */ + @Nullable + private static Room getRoomAtPhysical(Vec3i pos) { + return rooms.get(DungeonMapUtils.getPhysicalRoomPos(pos)); + } + /** * Calls {@link #isRoomMatched(Room)} on {@link #currentRoom}. * diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java index 8d8d0757..0d7a444f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java @@ -23,7 +23,6 @@ import net.minecraft.entity.mob.AmbientEntity; import net.minecraft.registry.Registries; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; import org.apache.commons.lang3.tuple.MutableTriple; import org.apache.commons.lang3.tuple.Triple; @@ -74,7 +73,6 @@ public class Room { private Table secretWaypoints; private String name; private Direction direction; - private Vector2ic physicalCornerPos; public Room(@NotNull Type type, @NotNull Vector2ic... physicalPositions) { @@ -103,20 +101,6 @@ public class Room { return name; } - /** - * Not null if {@link #isMatched()}. - */ - public Direction getDirection() { - return direction; - } - - /** - * Not null if {@link #isMatched()}. - */ - public Vector2ic getPhysicalCornerPos() { - return physicalCornerPos; - } - @Override public String toString() { return "Room{type=" + type + ", shape=" + shape + ", matched=" + matched + ", segments=" + Arrays.toString(segments.toArray()) + "}"; @@ -211,8 +195,8 @@ public class Room { if (pos.getY() < 66 || pos.getY() > 73) { return true; } - int x = MathHelper.floorMod(pos.getX() - 8, 32); - int z = MathHelper.floorMod(pos.getZ() - 8, 32); + int x = Math.floorMod(pos.getX() - 8, 32); + int z = Math.floorMod(pos.getZ() - 8, 32); return (x < 13 || x > 17 || z > 2 && z < 28) && (z < 13 || z > 17 || x > 2 && x < 28); } @@ -351,6 +335,20 @@ public class Room { doubleCheckBlocks = 0; } + /** + * Fails if !{@link #isMatched()} + */ + protected BlockPos actualToRelative(BlockPos pos) { + return DungeonMapUtils.actualToRelative(direction, physicalCornerPos, pos); + } + + /** + * Fails if !{@link #isMatched()} + */ + protected BlockPos relativeToActual(BlockPos pos) { + return DungeonMapUtils.relativeToActual(direction, physicalCornerPos, pos); + } + /** * Calls {@link SecretWaypoint#render(WorldRenderContext)} on {@link #secretWaypoints all secret waypoints}. */ -- cgit