diff options
author | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2023-09-07 15:03:53 -0400 |
---|---|---|
committer | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2023-09-07 15:03:53 -0400 |
commit | 24a9556c94497c968127593c8bc4f259f9d037c2 (patch) | |
tree | 779972b6c163971b7adeef53f758e09e65291b91 /src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets | |
parent | 9c7bf54123f366ad90bfafe81e973b731fd6b5b3 (diff) | |
download | Skyblocker-24a9556c94497c968127593c8bc4f259f9d037c2.tar.gz Skyblocker-24a9556c94497c968127593c8bc4f259f9d037c2.tar.bz2 Skyblocker-24a9556c94497c968127593c8bc4f259f9d037c2.zip |
Add bat removed detection
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets')
3 files changed, 37 insertions, 3 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 c916a5e4..a7420bf5 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 @@ -24,6 +24,8 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.entity.ItemEntity; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.mob.AmbientEntity; +import net.minecraft.entity.passive.BatEntity; import net.minecraft.item.FilledMapItem; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; @@ -348,7 +350,7 @@ public class DungeonSecrets { /** * 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. + * Used to detect finding {@link SecretWaypoint.Category.ITEM} secrets. * If the collector is the player, {@link #currentRoom} is used as an optimization. */ @SuppressWarnings("JavadocReference") @@ -365,6 +367,18 @@ public class DungeonSecrets { } } + /** + * Calls {@link Room#onBatRemoved(BatEntity)} on the room the {@code bat} is in if that room {@link #isRoomMatched(Room)}. + * Used to detect finding {@link SecretWaypoint.Category.BAT} secrets. + */ + @SuppressWarnings("JavadocReference") + public static void onBatRemoved(AmbientEntity bat) { + Room room = getRoomAtPhysical(bat.getPos()); + if (isRoomMatched(room)) { + room.onBatRemoved(bat); + } + } + public static boolean markSecrets(int secretIndex, boolean found) { if (isCurrentRoomMatched()) { return currentRoom.markSecrets(secretIndex, found); 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 fc62150c..6825d779 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 @@ -19,6 +19,7 @@ import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.ItemEntity; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.mob.AmbientEntity; import net.minecraft.registry.Registries; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; @@ -374,7 +375,7 @@ public class Room { } /** - * Marks the closest secret no greater than 6 blocks away as found when the player picks up a secret item. + * Marks the closest secret that requires item pickup 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 @@ -389,6 +390,17 @@ public class Room { } /** + * Marks the closest bat secret as found when a bat is killed. + * + * @param bat the bat being killed + * @see #onSecretFound(SecretWaypoint, String, Object...) + */ + protected void onBatRemoved(AmbientEntity bat) { + secretWaypoints.values().stream().filter(SecretWaypoint::isBat).min(Comparator.comparingDouble(SecretWaypoint.getSquaredDistanceToFunction(bat))) + .ifPresent(secretWaypoint -> onSecretFound(secretWaypoint, "[Skyblocker] Detected {} killed for a {} secret, setting secret #{} as found", bat.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. 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 edf18f85..3fdd683c 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 @@ -57,6 +57,10 @@ public class SecretWaypoint { return category.needsItemPickup(); } + boolean isBat() { + return category.isBat(); + } + void setFound() { this.missing = false; } @@ -122,7 +126,11 @@ public class SecretWaypoint { } boolean needsItemPickup() { - return this == ITEM || this == BAT; + return this == ITEM; + } + + boolean isBat() { + return this == BAT; } boolean isEnabled() { |