diff options
Diffstat (limited to 'src')
3 files changed, 84 insertions, 0 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java index 7bd1ab28..ebb90e7f 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java @@ -305,18 +305,32 @@ public class DungeonSecrets { return null; } + /** + * Renders the secret waypoints in {@link #currentRoom} if {@link #isCurrentRoomMatched()}. + */ private static void render(WorldRenderContext context) { if (isCurrentRoomMatched()) { currentRoom.render(context); } } + /** + * Calls {@link Room#onChatMessage(String)} on {@link #currentRoom} if the message is an overlay message and {@link #isCurrentRoomMatched()}. + * Used to detect when all secrets in a room are found. + */ private static void onChatMessage(Text text, boolean overlay) { if (overlay && isCurrentRoomMatched()) { currentRoom.onChatMessage(text.getString()); } } + /** + * Calls {@link Room#onUseBlock(World, BlockHitResult)} on {@link #currentRoom} if {@link #isCurrentRoomMatched()}. + * Used to detect finding {@link SecretWaypoint.Category.CHEST} and {@link SecretWaypoint.Category.WITHER} secrets. + * + * @return {@link ActionResult#PASS} + */ + @SuppressWarnings("JavadocReference") private static ActionResult onUseBlock(World world, BlockHitResult hitResult) { if (isCurrentRoomMatched()) { currentRoom.onUseBlock(world, hitResult); @@ -324,6 +338,12 @@ public class DungeonSecrets { return ActionResult.PASS; } + /** + * Calls {@link Room#onItemPickup(ItemEntity, LivingEntity)} on the room the {@code collector} is in if that room {@link #isRoomMatched(Room)}. + * Used to detect finding {@link SecretWaypoint.Category.ITEM} and {@link SecretWaypoint.Category.BAT} secrets. + * If the collector is the player, {@link #currentRoom} is used as an optimization. + */ + @SuppressWarnings("JavadocReference") public static void onItemPickup(ItemEntity itemEntity, LivingEntity collector, boolean isPlayer) { if (isPlayer) { if (isCurrentRoomMatched()) { @@ -337,24 +357,51 @@ public class DungeonSecrets { } } + /** + * 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(Vec3d) + */ @Nullable private static Room getRoomAtPhysical(Vec3d pos) { return rooms.get(DungeonMapUtils.getPhysicalRoomPos(pos)); } + /** + * Calls {@link #isRoomMatched(Room)} on {@link #currentRoom}. + * + * @return {@code true} if {@link #currentRoom} is not null and {@link #isRoomMatched(Room)} + */ private static boolean isCurrentRoomMatched() { return isRoomMatched(currentRoom); } + /** + * Calls {@link #shouldProcess()} and {@link Room#isMatched()} on the given room. + * + * @param room the room to check + * @return {@code true} if {@link #shouldProcess()}, the given room is not null, and {@link Room#isMatched()} on the given room + */ @Contract("null -> false") private static boolean isRoomMatched(@Nullable Room room) { return shouldProcess() && room != null && room.isMatched(); } + /** + * Checks if the player is in a dungeon and {@link me.xmrvizzy.skyblocker.config.SkyblockerConfig.Dungeons#secretWaypoints Secret Waypoints} is enabled. + * + * @return whether dungeon secrets should be processed + */ private static boolean shouldProcess() { return SkyblockerConfig.get().locations.dungeons.secretWaypoints && Utils.isInDungeons(); } + /** + * Resets fields when leaving a dungeon. + */ private static void reset() { mapEntrancePos = null; mapRoomSize = 0; diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/Room.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/Room.java index 53d12d74..c2cd109e 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/Room.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/Room.java @@ -319,6 +319,9 @@ public class Room { checkedBlocks = null; } + /** + * Calls {@link SecretWaypoint#render(WorldRenderContext)} on {@link #secretWaypoints all secret waypoints}. + */ protected void render(WorldRenderContext context) { for (SecretWaypoint secretWaypoint : secretWaypoints.values()) { if (secretWaypoint.isMissing()) { @@ -327,12 +330,21 @@ public class Room { } } + /** + * Sets all secrets as found if {@link #isAllSecretsFound(String)}. + */ protected void onChatMessage(String message) { if (isAllSecretsFound(message)) { secretWaypoints.values().forEach(SecretWaypoint::setFound); } } + /** + * Checks if the number of found secrets is equals or greater than the total number of secrets in the room. + * + * @param message the message to check in + * @return whether the number of found secrets is equals or greater than the total number of secrets in the room + */ protected static boolean isAllSecretsFound(String message) { Matcher matcher = SECRETS.matcher(message); if (matcher.find()) { @@ -341,6 +353,14 @@ public class Room { return false; } + /** + * Marks the secret at the interaction position as found when the player interacts with a chest or a player head, + * if there is a secret at the interaction position. + * + * @param world the world to get the block from + * @param hitResult the block being interacted with + * @see #onSecretFound(SecretWaypoint, String, Object...) + */ protected void onUseBlock(World world, BlockHitResult hitResult) { BlockState state = world.getBlockState(hitResult.getBlockPos()); if (!state.isOf(Blocks.CHEST) && !state.isOf(Blocks.PLAYER_HEAD) && !state.isOf(Blocks.PLAYER_WALL_HEAD)) { @@ -350,6 +370,13 @@ public class Room { .ifPresent(secretWaypoint -> onSecretFound(secretWaypoint, "[Skyblocker] Detected {} interaction, setting secret #{} as found", secretWaypoint.category, secretWaypoint.secretIndex)); } + /** + * Marks the closest secret no greater than 6 blocks away as found when the player picks up a secret item. + * + * @param itemEntity the item entity being picked up + * @param collector the collector of the item + * @see #onSecretFound(SecretWaypoint, String, Object...) + */ protected void onItemPickup(ItemEntity itemEntity, LivingEntity collector) { if (SecretWaypoint.SECRET_ITEMS.stream().noneMatch(itemEntity.getStack().getName().getString()::contains)) { return; @@ -358,6 +385,13 @@ public class Room { .ifPresent(secretWaypoint -> onSecretFound(secretWaypoint, "[Skyblocker] Detected {} picked up a {} from a {} secret, setting secret #{} as found", collector.getName().getString(), itemEntity.getName().getString(), secretWaypoint.category, secretWaypoint.secretIndex)); } + /** + * Marks all secret waypoints with the same index as the given {@link SecretWaypoint} as found. + * + * @param secretWaypoint the secret waypoint to read the index from. + * @param msg the message to log + * @param args the args for the {@link org.slf4j.Logger#info(String, Object...) Logger#info(String, Object...)} call + */ private void onSecretFound(SecretWaypoint secretWaypoint, String msg, Object... args) { secretWaypoints.row(secretWaypoint.secretIndex).values().forEach(SecretWaypoint::setFound); DungeonSecrets.LOGGER.info(msg, args); diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/SecretWaypoint.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/SecretWaypoint.java index ceb38af5..96fd7374 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/SecretWaypoint.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/SecretWaypoint.java @@ -37,6 +37,9 @@ public class SecretWaypoint { this.missing = false; } + /** + * Renders the secret waypoint, including a filled cube, a beacon beam, the name, and the distance from the player. + */ void render(WorldRenderContext context) { RenderHelper.renderFilledThroughWallsWithBeaconBeam(context, pos, category.colorComponents, 0.5F); Vec3d posUp = centerPos.add(0, 1, 0); |