From 1f358759f30925726756afa21405396a4ffc23d4 Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Tue, 24 Oct 2023 00:08:44 -0400 Subject: Apply custom waypoint to existing rooms --- .../skyblock/dungeon/secrets/DungeonSecrets.java | 21 +++++++++++------- .../skyblocker/skyblock/dungeon/secrets/Room.java | 25 +++++++++++++++++----- .../skyblock/dungeon/secrets/SecretWaypoint.java | 8 +++++-- 3 files changed, 39 insertions(+), 15 deletions(-) (limited to 'src/main') 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 45eed595..461cbf68 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 @@ -61,6 +61,7 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.util.*; import java.util.concurrent.CompletableFuture; +import java.util.stream.Stream; import java.util.zip.InflaterInputStream; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; @@ -131,6 +132,10 @@ public class DungeonSecrets { return roomsLoaded != null && roomsLoaded.isDone(); } + public static Stream getRoomsStream() { + return rooms.values().stream(); + } + @SuppressWarnings("unused") public static JsonObject getRoomMetadata(String room) { return roomsJson.get(room).getAsJsonObject(); @@ -144,6 +149,11 @@ public class DungeonSecrets { return customWaypoints.get(room); } + @SuppressWarnings("UnusedReturnValue") + public static boolean addCustomWaypoint(String room, SecretWaypoint waypoint) { + return customWaypoints.put(room, waypoint); + } + /** * Loads the dungeon secrets asynchronously from {@code /assets/skyblocker/dungeons}. * Use {@link #isRoomsLoaded()} to check for completion of loading. @@ -284,7 +294,7 @@ public class DungeonSecrets { private static int addWaypoint(CommandContext context, BlockPos pos) { Room room = getRoomAtPhysical(pos); if (isRoomMatched(room)) { - addWaypointRelative(context, room, room.actualToRelative(pos)); + room.addWaypoint(context, room.actualToRelative(pos)); } else { context.getSource().sendError(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.notMatched"))); } @@ -293,17 +303,13 @@ public class DungeonSecrets { private static int addWaypointRelative(CommandContext context, BlockPos pos) { if (isCurrentRoomMatched()) { - addWaypointRelative(context, currentRoom, pos); + currentRoom.addWaypoint(context, pos); } else { context.getSource().sendError(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.notMatched"))); } return Command.SINGLE_SUCCESS; } - private static void addWaypointRelative(CommandContext context, Room room, BlockPos pos) { - customWaypoints.put(room.getName(), new SecretWaypoint(IntegerArgumentType.getInteger(context, "secretIndex"), SecretWaypoint.Category.CategoryArgumentType.getCategory(context, "category"), StringArgumentType.getString(context, "name"), pos)); - } - /** * Updates the dungeon. The general idea is similar to the Dungeon Rooms Mod. *

@@ -377,8 +383,7 @@ public class DungeonSecrets { } switch (type) { case ENTRANCE, PUZZLE, TRAP, MINIBOSS, FAIRY, BLOOD -> room = newRoom(type, physicalPos); - case ROOM -> - room = newRoom(type, DungeonMapUtils.getPhysicalPosFromMap(mapEntrancePos, mapRoomSize, physicalEntrancePos, DungeonMapUtils.getRoomSegments(map, mapPos, mapRoomSize, type.color))); + case ROOM -> room = newRoom(type, DungeonMapUtils.getPhysicalPosFromMap(mapEntrancePos, mapRoomSize, physicalEntrancePos, DungeonMapUtils.getRoomSegments(map, mapPos, mapRoomSize, type.color))); } } if (room != null && currentRoom != room) { 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 0840c727..c5b374a9 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 @@ -1,14 +1,17 @@ package de.hysky.skyblocker.skyblock.dungeon.secrets; import com.google.common.collect.HashBasedTable; -import com.google.common.collect.ImmutableTable; import com.google.common.collect.Table; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; 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 net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.fabricmc.fabric.api.util.TriState; import net.minecraft.block.BlockState; @@ -153,6 +156,17 @@ public class Room { }; } + protected void addWaypoint(CommandContext 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); + }); + } + /** * Updates the room. *

@@ -299,18 +313,19 @@ public class Room { */ @SuppressWarnings("JavadocReference") private void roomMatched() { - Table secretWaypointsMutable = HashBasedTable.create(); + secretWaypoints = HashBasedTable.create(); for (JsonElement waypointElement : DungeonSecrets.getRoomWaypoints(name)) { JsonObject waypoint = waypointElement.getAsJsonObject(); String secretName = waypoint.get("secretName").getAsString(); int secretIndex = Integer.parseInt(secretName.substring(0, Character.isDigit(secretName.charAt(1)) ? 2 : 1)); BlockPos pos = DungeonMapUtils.relativeToActual(direction, physicalCornerPos, waypoint); - secretWaypointsMutable.put(secretIndex, pos, new SecretWaypoint(secretIndex, waypoint, secretName, pos)); + secretWaypoints.put(secretIndex, pos, new SecretWaypoint(secretIndex, waypoint, secretName, pos)); } for (SecretWaypoint customWaypoint : DungeonSecrets.getCustomWaypoints(name)) { - secretWaypointsMutable.put(customWaypoint.secretIndex, customWaypoint.pos, customWaypoint); + BlockPos actualPos = relativeToActual(customWaypoint.pos); + SecretWaypoint actualWaypoint = new SecretWaypoint(customWaypoint.secretIndex, customWaypoint.category, customWaypoint.name, actualPos); + secretWaypoints.put(customWaypoint.secretIndex, actualPos, actualWaypoint); } - secretWaypoints = ImmutableTable.copyOf(secretWaypointsMutable); 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 5fbce68a..d896bf35 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 @@ -29,7 +29,7 @@ public class SecretWaypoint extends Waypoint { private static final Supplier typeSupplier = () -> config.waypointType; final int secretIndex; final Category category; - private final Text name; + final Text name; private final Vec3d centerPos; SecretWaypoint(int secretIndex, JsonObject waypoint, String name, BlockPos pos) { @@ -37,10 +37,14 @@ public class SecretWaypoint extends Waypoint { } SecretWaypoint(int secretIndex, Category category, String name, BlockPos pos) { + this(secretIndex, category, Text.of(name), pos); + } + + SecretWaypoint(int secretIndex, Category category, Text name, BlockPos pos) { super(pos, typeSupplier, category.colorComponents); this.secretIndex = secretIndex; this.category = category; - this.name = Text.of(name); + this.name = name; this.centerPos = pos.toCenterPos(); } -- cgit