aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java19
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java45
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypoint.java16
3 files changed, 56 insertions, 24 deletions
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 461cbf68..215fa33a 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
@@ -109,6 +109,9 @@ public class DungeonSecrets {
private static final Map<Vector2ic, Room> rooms = new HashMap<>();
private static final Map<String, JsonElement> roomsJson = new HashMap<>();
private static final Map<String, JsonElement> waypointsJson = new HashMap<>();
+ /**
+ * The map of dungeon room names to custom waypoints relative to the room.
+ */
private static final Multimap<String, SecretWaypoint> customWaypoints = MultimapBuilder.hashKeys().arrayListValues().build();
@Nullable
private static CompletableFuture<Void> roomsLoaded;
@@ -145,10 +148,16 @@ public class DungeonSecrets {
return waypointsJson.get(room).getAsJsonArray();
}
+ /**
+ * @see #customWaypoints
+ */
public static Collection<SecretWaypoint> getCustomWaypoints(String room) {
return customWaypoints.get(room);
}
+ /**
+ * @see #customWaypoints
+ */
@SuppressWarnings("UnusedReturnValue")
public static boolean addCustomWaypoint(String room, SecretWaypoint waypoint) {
return customWaypoints.put(room, waypoint);
@@ -285,25 +294,25 @@ public class DungeonSecrets {
.then(argument("name", StringArgumentType.greedyString()).executes(context -> {
// TODO Less hacky way with custom ClientBlockPosArgumentType
BlockPos pos = context.getArgument("pos", PosArgument.class).toAbsoluteBlockPos(new ServerCommandSource(null, context.getSource().getPosition(), context.getSource().getRotation(), null, 0, null, null, null, null));
- return relative ? addWaypointRelative(context, pos) : addWaypoint(context, pos);
+ return relative ? addCustomWaypointRelative(context, pos) : addCustomWaypoint(context, pos);
}))
)
);
}
- private static int addWaypoint(CommandContext<FabricClientCommandSource> context, BlockPos pos) {
+ private static int addCustomWaypoint(CommandContext<FabricClientCommandSource> context, BlockPos pos) {
Room room = getRoomAtPhysical(pos);
if (isRoomMatched(room)) {
- room.addWaypoint(context, room.actualToRelative(pos));
+ room.addCustomWaypoint(context, room.actualToRelative(pos));
} else {
context.getSource().sendError(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.notMatched")));
}
return Command.SINGLE_SUCCESS;
}
- private static int addWaypointRelative(CommandContext<FabricClientCommandSource> context, BlockPos pos) {
+ private static int addCustomWaypointRelative(CommandContext<FabricClientCommandSource> context, BlockPos pos) {
if (isCurrentRoomMatched()) {
- currentRoom.addWaypoint(context, pos);
+ currentRoom.addCustomWaypoint(context, pos);
} else {
context.getSource().sendError(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.notMatched")));
}
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 c5b374a9..7430fc0b 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
@@ -156,15 +156,36 @@ public class Room {
};
}
- protected void addWaypoint(CommandContext<FabricClientCommandSource> context, BlockPos pos) {
- String roomName = getName();
- SecretWaypoint secretWaypoint = new SecretWaypoint(IntegerArgumentType.getInteger(context, "secretIndex"), SecretWaypoint.Category.CategoryArgumentType.getCategory(context, "category"), StringArgumentType.getString(context, "name"), pos);
- DungeonSecrets.addCustomWaypoint(roomName, secretWaypoint);
- DungeonSecrets.getRoomsStream().filter(r -> roomName.equals(r.getName())).forEach(r -> {
- BlockPos actualPos = r.relativeToActual(pos);
- SecretWaypoint actualWaypoint = new SecretWaypoint(secretWaypoint.secretIndex, secretWaypoint.category, secretWaypoint.name, actualPos);
- r.secretWaypoints.put(secretWaypoint.secretIndex, actualPos, actualWaypoint);
- });
+ /**
+ * @see #addCustomWaypoint(int, SecretWaypoint.Category, String, BlockPos)
+ */
+ protected void addCustomWaypoint(CommandContext<FabricClientCommandSource> context, BlockPos pos) {
+ addCustomWaypoint(IntegerArgumentType.getInteger(context, "secretIndex"), SecretWaypoint.Category.CategoryArgumentType.getCategory(context, "category"), StringArgumentType.getString(context, "name"), pos);
+ }
+
+ /**
+ * Adds a custom waypoint relative to this room to {@link DungeonSecrets#customWaypoints} and all existing instances of this room.
+ *
+ * @param secretIndex the index of the secret waypoint
+ * @param category the category of the secret waypoint
+ * @param waypointName the name of the secret waypoint
+ * @param pos the position of the secret waypoint relative to this room
+ */
+ @SuppressWarnings("JavadocReference")
+ private void addCustomWaypoint(int secretIndex, SecretWaypoint.Category category, String waypointName, BlockPos pos) {
+ SecretWaypoint waypoint = new SecretWaypoint(secretIndex, category, waypointName, pos);
+ DungeonSecrets.addCustomWaypoint(name, waypoint);
+ DungeonSecrets.getRoomsStream().filter(r -> name.equals(r.getName())).forEach(r -> r.addCustomWaypoint(waypoint));
+ }
+
+ /**
+ * Adds a custom waypoint relative to this room to this room.
+ *
+ * @param relativeWaypoint the secret waypoint relative to this room to add
+ */
+ private void addCustomWaypoint(SecretWaypoint relativeWaypoint) {
+ SecretWaypoint actualWaypoint = relativeWaypoint.relativeToActual(this);
+ secretWaypoints.put(actualWaypoint.secretIndex, actualWaypoint.pos, actualWaypoint);
}
/**
@@ -321,11 +342,7 @@ public class Room {
BlockPos pos = DungeonMapUtils.relativeToActual(direction, physicalCornerPos, waypoint);
secretWaypoints.put(secretIndex, pos, new SecretWaypoint(secretIndex, waypoint, secretName, pos));
}
- for (SecretWaypoint customWaypoint : DungeonSecrets.getCustomWaypoints(name)) {
- BlockPos actualPos = relativeToActual(customWaypoint.pos);
- SecretWaypoint actualWaypoint = new SecretWaypoint(customWaypoint.secretIndex, customWaypoint.category, customWaypoint.name, actualPos);
- secretWaypoints.put(customWaypoint.secretIndex, actualPos, actualWaypoint);
- }
+ DungeonSecrets.getCustomWaypoints(name).forEach(this::addCustomWaypoint);
matched = TriState.TRUE;
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 d896bf35..cb32e638 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
@@ -17,6 +17,7 @@ import net.minecraft.util.Formatting;
import net.minecraft.util.StringIdentifiable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
+import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.function.Predicate;
@@ -25,8 +26,8 @@ import java.util.function.ToDoubleFunction;
public class SecretWaypoint extends Waypoint {
static final List<String> SECRET_ITEMS = List.of("Decoy", "Defuse Kit", "Dungeon Chest Key", "Healing VIII", "Inflatable Jerry", "Spirit Leap", "Training Weights", "Trap", "Treasure Talisman");
- private static final SkyblockerConfig.SecretWaypoints config = SkyblockerConfigManager.get().locations.dungeons.secretWaypoints;
- private static final Supplier<Type> typeSupplier = () -> config.waypointType;
+ private static final SkyblockerConfig.SecretWaypoints CONFIG = SkyblockerConfigManager.get().locations.dungeons.secretWaypoints;
+ private static final Supplier<Type> TYPE_SUPPLIER = () -> CONFIG.waypointType;
final int secretIndex;
final Category category;
final Text name;
@@ -41,7 +42,7 @@ public class SecretWaypoint extends Waypoint {
}
SecretWaypoint(int secretIndex, Category category, Text name, BlockPos pos) {
- super(pos, typeSupplier, category.colorComponents);
+ super(pos, TYPE_SUPPLIER, category.colorComponents);
this.secretIndex = secretIndex;
this.category = category;
this.name = name;
@@ -85,7 +86,7 @@ public class SecretWaypoint extends Waypoint {
//TODO In the future, shrink the box for wither essence and items so its more realistic
super.render(context);
- if (config.showSecretText) {
+ if (CONFIG.showSecretText) {
Vec3d posUp = centerPos.add(0, 1, 0);
RenderHelper.renderText(context, name, posUp, true);
double distance = context.camera().getPos().distanceTo(centerPos);
@@ -93,6 +94,11 @@ public class SecretWaypoint extends Waypoint {
}
}
+ @NotNull
+ SecretWaypoint relativeToActual(Room room) {
+ return new SecretWaypoint(secretIndex, category, name, room.relativeToActual(pos));
+ }
+
enum Category implements StringIdentifiable {
ENTRANCE("entrance", secretWaypoints -> secretWaypoints.enableEntranceWaypoints, 0, 255, 0),
SUPERBOOM("superboom", secretWaypoints -> secretWaypoints.enableSuperboomWaypoints, 255, 0, 0),
@@ -158,7 +164,7 @@ public class SecretWaypoint extends Waypoint {
return new CategoryArgumentType();
}
- public static Category getCategory(CommandContext<?> context, String name) {
+ public static <S> Category getCategory(CommandContext<S> context, String name) {
return context.getArgument(name, Category.class);
}
}