From 93cb7f648fb99f2113cc08508cf2b2d30d92069e Mon Sep 17 00:00:00 2001 From: LucinaFailurePart2 <101990369+LucinaFailurePart2@users.noreply.github.com> Date: Tue, 31 Dec 2024 14:49:03 -0500 Subject: [PATCH 1/2] Added not condition. Need help for applying this to Biome,biome tags, and NEARBY_MOBS --- .../circuitlord/reactivemusic/SongPicker.java | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/main/java/circuitlord/reactivemusic/SongPicker.java b/src/main/java/circuitlord/reactivemusic/SongPicker.java index 12b7544..b274395 100644 --- a/src/main/java/circuitlord/reactivemusic/SongPicker.java +++ b/src/main/java/circuitlord/reactivemusic/SongPicker.java @@ -1,5 +1,6 @@ package circuitlord.reactivemusic; +// LF - Not a fabric modder, I might make obvious syntax mistakes. import circuitlord.reactivemusic.config.ModConfig; import circuitlord.reactivemusic.mixin.BossBarHudAccessor; @@ -140,40 +141,62 @@ public static void tickEventMap() { } else { songpackEventMap.put(SongpackEventType.HOME, false); - } + songpackEventMap.put(SongpackEventType.NOTHOME, true); + } + // LF - Ok I admit this might not have much use but I think having the option anyway is good, right? // Time - songpackEventMap.put(SongpackEventType.DAY, !night); + songpackEventMap.put(SongpackEventType.DAY, day); + songpackEventMap.put(SongpackEventType.NOT_DAY, !day); songpackEventMap.put(SongpackEventType.NIGHT, night); + songpackEventMap.put(SongpackEventType.NOT_NIGHT, !night); songpackEventMap.put(SongpackEventType.SUNSET, sunset); + songpackEventMap.put(SongpackEventType.NOT_SUNSET, !sunset); songpackEventMap.put(SongpackEventType.SUNRISE, sunrise); + songpackEventMap.put(SongpackEventType.NOT_SUNRISE, !sunrise); // Actions - + // LF - Ok I admit this might not have much use but I think having the option anyway is good, right? songpackEventMap.put(SongpackEventType.DYING, player.getHealth() / player.getMaxHealth() < 0.35); + songpackEventMap.put(SongpackEventType.NOT_DYING, player.getHealth() / player.getMaxHealth() >= 0.35); songpackEventMap.put(SongpackEventType.FISHING, player.fishHook != null); + songpackEventMap.put(SongpackEventType.NOT_FISHING, player.fishHook = null); + + // LF - Ok I admit this might not have much use but I think having the option anyway is good, right? songpackEventMap.put(SongpackEventType.MINECART, riding instanceof MinecartEntity); + songpackEventMap.put(SongpackEventType.NOT_MINECART, !riding instanceof MinecartEntity); songpackEventMap.put(SongpackEventType.BOAT, riding instanceof BoatEntity); + songpackEventMap.put(SongpackEventType.NOT_BOAT, !riding instanceof BoatEntity); songpackEventMap.put(SongpackEventType.HORSE, riding instanceof HorseEntity); + songpackEventMap.put(SongpackEventType.NOT_HORSE, !riding instanceof HorseEntity); songpackEventMap.put(SongpackEventType.PIG, riding instanceof PigEntity); + songpackEventMap.put(SongpackEventType.NOT_PIG, !riding instanceof PigEntity); songpackEventMap.put(SongpackEventType.OVERWORLD, indimension == World.OVERWORLD); + songpackEventMap.put(SongpackEventType.NOT_OVERWORLD, indimension == !World.OVERWORLD); songpackEventMap.put(SongpackEventType.NETHER, indimension == World.NETHER); + songpackEventMap.put(SongpackEventType.NOT_NETHER, indimension == !World.NETHER); songpackEventMap.put(SongpackEventType.END, indimension == World.END); + songpackEventMap.put(SongpackEventType.NOT_END, indimension == !World.END); + // LF - Why limit these to overworld? also, perhaps for the not version, I/we should remove the 'underground' check entirely? + songpackEventMap.put(SongpackEventType.UNDERGROUND, underground && pos.getY() < 55); + songpackEventMap.put(SongpackEventType.NOT_UNDERGROUND, pos.getY() >= 55); + songpackEventMap.put(SongpackEventType.DEEP_UNDERGROUND, underground && pos.getY() < 15); + songpackEventMap.put(SongpackEventType.NOT_DEEP_UNDERGROUND, underground && pos.getY() >= 15); + songpackEventMap.put(SongpackEventType.HIGH_UP, !underground && pos.getY() > 128); + songpackEventMap.put(SongpackEventType.NOT_HIGH_UP, !underground && pos.getY() > 128); - songpackEventMap.put(SongpackEventType.UNDERGROUND, indimension == World.OVERWORLD && underground && pos.getY() < 55); - songpackEventMap.put(SongpackEventType.DEEP_UNDERGROUND, indimension == World.OVERWORLD && underground && pos.getY() < 15); - songpackEventMap.put(SongpackEventType.HIGH_UP, indimension == World.OVERWORLD && !underground && pos.getY() > 128); - - songpackEventMap.put(SongpackEventType.UNDERWATER, player.isSubmergedInWater()); + songpackEventMap.put(SongpackEventType.UNDERWATER, player.isSubmergedInWater()) + songpackEventMap.put(SongpackEventType.NOT_UNDERWATER, !player.isSubmergedInWater());; // Weather + // LF - I actually don't know how to approach this one in a useful way. songpackEventMap.put(SongpackEventType.RAIN, world.isRaining() && biome.value().getPrecipitation(pos, world.getSeaLevel()) == Biome.Precipitation.RAIN); songpackEventMap.put(SongpackEventType.SNOW, world.isRaining() && biome.value().getPrecipitation(pos, world.getSeaLevel()) == Biome.Precipitation.SNOW); @@ -193,7 +216,8 @@ public static void tickEventMap() { break; } } - + // Update all ConventionalBiomeTags + biomeTagEventMap.put(tag, found); } @@ -231,6 +255,7 @@ public static void tickEventMap() { } songpackEventMap.put(SongpackEventType.VILLAGE, villagerCount > 0); + songpackEventMap.put(SongpackEventType.NOT_VILLAGE, villagerCount = 0); } @@ -265,6 +290,7 @@ public static void tickEventMap() { } songpackEventMap.put(SongpackEventType.BOSS, bossBarActive); + songpackEventMap.put(SongpackEventType.NOT_BOSS, !bossBarActive); songpackEventMap.put(SongpackEventType.GENERIC, true); From dd2fce5bd2158bf2fe0c06decc1226e36c1ee7ba Mon Sep 17 00:00:00 2001 From: LucinaFailurePart2 <101990369+LucinaFailurePart2@users.noreply.github.com> Date: Wed, 1 Jan 2025 13:19:53 -0500 Subject: [PATCH 2/2] Update SongPicker.java reverted not condition, but still kept changes to broaden song pack events --- .../circuitlord/reactivemusic/SongPicker.java | 571 +++++++++--------- 1 file changed, 276 insertions(+), 295 deletions(-) diff --git a/src/main/java/circuitlord/reactivemusic/SongPicker.java b/src/main/java/circuitlord/reactivemusic/SongPicker.java index b274395..d6f5298 100644 --- a/src/main/java/circuitlord/reactivemusic/SongPicker.java +++ b/src/main/java/circuitlord/reactivemusic/SongPicker.java @@ -1,6 +1,6 @@ package circuitlord.reactivemusic; -// LF - Not a fabric modder, I might make obvious syntax mistakes. +// LF - Not a fabric modder, I might make obvious mistakes. import circuitlord.reactivemusic.config.ModConfig; import circuitlord.reactivemusic.mixin.BossBarHudAccessor; @@ -33,443 +33,422 @@ public final class SongPicker { - public static Map songpackEventMap = new EnumMap<>(SongpackEventType.class); +    public static Map songpackEventMap = new EnumMap<>(SongpackEventType.class); - public static Map, Boolean> biomeTagEventMap = new HashMap<>(); +    public static Map, Boolean> biomeTagEventMap = new HashMap<>(); - public static Map recentEntityDamageSources = new HashMap<>(); +    public static Map recentEntityDamageSources = new HashMap<>(); - public static String currentBiomeName = ""; - public static String currentDimName = ""; +    public static String currentBiomeName = ""; +    public static String currentDimName = ""; - private static final Random rand = new Random(); +    private static final Random rand = new Random(); - private static List recentlyPickedSongs = new ArrayList<>(); +    private static List recentlyPickedSongs = new ArrayList<>(); - public static final Field[] BIOME_TAG_FIELDS = ConventionalBiomeTags.class.getDeclaredFields(); - public static final List> BIOME_TAGS = new ArrayList<>(); +    public static final Field[] BIOME_TAG_FIELDS = ConventionalBiomeTags.class.getDeclaredFields(); +    public static final List> BIOME_TAGS = new ArrayList<>(); - public static Long TIME_FOR_FORGET_DAMAGE_SOURCE = 200L; +    public static Long TIME_FOR_FORGET_DAMAGE_SOURCE = 200L; - public static boolean wasSleeping = false; +    public static boolean wasSleeping = false; - static { +    static { - for (Field field : BIOME_TAG_FIELDS) { - TagKey biomeTag = getBiomeTagFromField(field); +        for (Field field : BIOME_TAG_FIELDS) { +            TagKey biomeTag = getBiomeTagFromField(field); - BIOME_TAGS.add(biomeTag); - biomeTagEventMap.put(biomeTag, false); - } - } +            BIOME_TAGS.add(biomeTag); +            biomeTagEventMap.put(biomeTag, false); +        } +    } - public static TagKey getBiomeTagFromField(Field field) { - if (field.getType() == TagKey.class) { - try { - @SuppressWarnings("unchecked") - TagKey tag = (TagKey) field.get(null); - return tag; - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - return null; - } +    public static TagKey getBiomeTagFromField(Field field) { +        if (field.getType() == TagKey.class) { +            try { +                @SuppressWarnings("unchecked") +                TagKey tag = (TagKey) field.get(null); +                return tag; +            } catch (IllegalAccessException e) { +                e.printStackTrace(); +            } +        } +        return null; +    } - public static void tickEventMap() { +    public static void tickEventMap() { - currentBiomeName = ""; - currentDimName = ""; +        currentBiomeName = ""; +        currentDimName = ""; - MinecraftClient mc = MinecraftClient.getInstance(); - if (mc == null) - return; +        MinecraftClient mc = MinecraftClient.getInstance(); +        if (mc == null) +            return; - ClientPlayerEntity player = mc.player; - World world = mc.world; +        ClientPlayerEntity player = mc.player; +        World world = mc.world; - songpackEventMap.put(SongpackEventType.MAIN_MENU, player == null || world == null); - songpackEventMap.put(SongpackEventType.CREDITS, mc.currentScreen instanceof CreditsScreen); +        songpackEventMap.put(SongpackEventType.MAIN_MENU, player == null || world == null); +        songpackEventMap.put(SongpackEventType.CREDITS, mc.currentScreen instanceof CreditsScreen); - // Early out if not in-game - if (player == null || world == null) return; +        // Early out if not in-game +        if (player == null || world == null) return; - // World processing - BlockPos pos = new BlockPos(player.getBlockPos()); - var biome = world.getBiome(pos); +        // World processing +        BlockPos pos = new BlockPos(player.getBlockPos()); +        var biome = world.getBiome(pos); - // Copied logic out from getIdAsString - currentBiomeName = (String)biome.getKey().map((key) -> { - return key.getValue().toString(); - }).orElse("[unregistered]"); +        // Copied logic out from getIdAsString +        currentBiomeName = (String)biome.getKey().map((key) -> { +            return key.getValue().toString(); +        }).orElse("[unregistered]"); - boolean underground = !world.isSkyVisible(pos); - var indimension = world.getRegistryKey(); +        boolean underground = !world.isSkyVisible(pos); +        var indimension = world.getRegistryKey(); - currentDimName = indimension.getValue().toString(); +        currentDimName = indimension.getValue().toString(); - Entity riding = VersionHelper.GetRidingEntity(player); +        Entity riding = VersionHelper.GetRidingEntity(player); - long time = world.getTimeOfDay() % 24000; - boolean night = time > 13300 && time < 23200; - boolean sunset = time > 12000 && time < 13000; - boolean sunrise = time > 23000; +        // LF - added day :) +        long time = world.getTimeOfDay() % 24000; +        boolean day = time < 13000; +        boolean night = time > 13300 && time < 23200; +        boolean sunset = time > 12000 && time < 13000; +        boolean sunrise = time > 23000; - // TODO: someone help me I have no idea how to get the name of the world/server but if you know how then put it instead of "saved" - if (!wasSleeping && player.isSleeping()) { - ReactiveMusic.config.savedHomePositions.put("saved", player.getPos()); +        // TODO: someone help me I have no idea how to get the name of the world/server but if you know how then put it instead of "saved" +        if (!wasSleeping && player.isSleeping()) { +            ReactiveMusic.config.savedHomePositions.put("saved", player.getPos()); - ModConfig.saveConfig(); - } +            ModConfig.saveConfig(); +        } - wasSleeping = player.isSleeping(); +        wasSleeping = player.isSleeping(); - // special +        // special - if (ReactiveMusic.config.savedHomePositions.containsKey("saved")) { +        if (ReactiveMusic.config.savedHomePositions.containsKey("saved")) { - Vec3d dist = player.getPos().subtract(ReactiveMusic.config.savedHomePositions.get("saved")); +            Vec3d dist = player.getPos().subtract(ReactiveMusic.config.savedHomePositions.get("saved")); - songpackEventMap.put(SongpackEventType.HOME, dist.length() < 45.0f); - } - else { - songpackEventMap.put(SongpackEventType.HOME, false); +            songpackEventMap.put(SongpackEventType.HOME, dist.length() < 45.0f); +        } +        else { +            songpackEventMap.put(SongpackEventType.HOME, false); +        } - songpackEventMap.put(SongpackEventType.NOTHOME, true); - } - // LF - Ok I admit this might not have much use but I think having the option anyway is good, right? - // Time - songpackEventMap.put(SongpackEventType.DAY, day); - songpackEventMap.put(SongpackEventType.NOT_DAY, !day); - songpackEventMap.put(SongpackEventType.NIGHT, night); - songpackEventMap.put(SongpackEventType.NOT_NIGHT, !night); - songpackEventMap.put(SongpackEventType.SUNSET, sunset); - songpackEventMap.put(SongpackEventType.NOT_SUNSET, !sunset); - songpackEventMap.put(SongpackEventType.SUNRISE, sunrise); - songpackEventMap.put(SongpackEventType.NOT_SUNRISE, !sunrise); +        // Time +        // LF - added day :) +        songpackEventMap.put(SongpackEventType.DAY, day); +        songpackEventMap.put(SongpackEventType.NIGHT, night); +        songpackEventMap.put(SongpackEventType.SUNSET, sunset); +        songpackEventMap.put(SongpackEventType.SUNRISE, sunrise); - // Actions - // LF - Ok I admit this might not have much use but I think having the option anyway is good, right? - songpackEventMap.put(SongpackEventType.DYING, player.getHealth() / player.getMaxHealth() < 0.35); - songpackEventMap.put(SongpackEventType.NOT_DYING, player.getHealth() / player.getMaxHealth() >= 0.35); - songpackEventMap.put(SongpackEventType.FISHING, player.fishHook != null); - songpackEventMap.put(SongpackEventType.NOT_FISHING, player.fishHook = null); +        // Actions - // LF - Ok I admit this might not have much use but I think having the option anyway is good, right? +        songpackEventMap.put(SongpackEventType.DYING, player.getHealth() / player.getMaxHealth() < 0.35); +        songpackEventMap.put(SongpackEventType.FISHING, player.fishHook != null); - songpackEventMap.put(SongpackEventType.MINECART, riding instanceof MinecartEntity); - songpackEventMap.put(SongpackEventType.NOT_MINECART, !riding instanceof MinecartEntity); - songpackEventMap.put(SongpackEventType.BOAT, riding instanceof BoatEntity); - songpackEventMap.put(SongpackEventType.NOT_BOAT, !riding instanceof BoatEntity); - songpackEventMap.put(SongpackEventType.HORSE, riding instanceof HorseEntity); - songpackEventMap.put(SongpackEventType.NOT_HORSE, !riding instanceof HorseEntity); - songpackEventMap.put(SongpackEventType.PIG, riding instanceof PigEntity); - songpackEventMap.put(SongpackEventType.NOT_PIG, !riding instanceof PigEntity); +        songpackEventMap.put(SongpackEventType.MINECART, riding instanceof MinecartEntity); +        songpackEventMap.put(SongpackEventType.BOAT, riding instanceof BoatEntity); +        songpackEventMap.put(SongpackEventType.HORSE, riding instanceof HorseEntity); +        songpackEventMap.put(SongpackEventType.PIG, riding instanceof PigEntity); - songpackEventMap.put(SongpackEventType.OVERWORLD, indimension == World.OVERWORLD); - songpackEventMap.put(SongpackEventType.NOT_OVERWORLD, indimension == !World.OVERWORLD); - songpackEventMap.put(SongpackEventType.NETHER, indimension == World.NETHER); - songpackEventMap.put(SongpackEventType.NOT_NETHER, indimension == !World.NETHER); - songpackEventMap.put(SongpackEventType.END, indimension == World.END); - songpackEventMap.put(SongpackEventType.NOT_END, indimension == !World.END); +        songpackEventMap.put(SongpackEventType.OVERWORLD, indimension == World.OVERWORLD); +        songpackEventMap.put(SongpackEventType.NETHER, indimension == World.NETHER); +        songpackEventMap.put(SongpackEventType.END, indimension == World.END); - // LF - Why limit these to overworld? also, perhaps for the not version, I/we should remove the 'underground' check entirely? - songpackEventMap.put(SongpackEventType.UNDERGROUND, underground && pos.getY() < 55); - songpackEventMap.put(SongpackEventType.NOT_UNDERGROUND, pos.getY() >= 55); - songpackEventMap.put(SongpackEventType.DEEP_UNDERGROUND, underground && pos.getY() < 15); - songpackEventMap.put(SongpackEventType.NOT_DEEP_UNDERGROUND, underground && pos.getY() >= 15); - songpackEventMap.put(SongpackEventType.HIGH_UP, !underground && pos.getY() > 128); - songpackEventMap.put(SongpackEventType.NOT_HIGH_UP, !underground && pos.getY() > 128); +        // LF - Why limit these to overworld? - songpackEventMap.put(SongpackEventType.UNDERWATER, player.isSubmergedInWater()) - songpackEventMap.put(SongpackEventType.NOT_UNDERWATER, !player.isSubmergedInWater());; +        songpackEventMap.put(SongpackEventType.UNDERGROUND, underground && pos.getY() < 55); +        songpackEventMap.put(SongpackEventType.DEEP_UNDERGROUND, underground && pos.getY() < 15); +        songpackEventMap.put(SongpackEventType.HIGH_UP, !underground && pos.getY() > 128); - // Weather - // LF - I actually don't know how to approach this one in a useful way. - songpackEventMap.put(SongpackEventType.RAIN, world.isRaining() && biome.value().getPrecipitation(pos, world.getSeaLevel()) == Biome.Precipitation.RAIN); - songpackEventMap.put(SongpackEventType.SNOW, world.isRaining() && biome.value().getPrecipitation(pos, world.getSeaLevel()) == Biome.Precipitation.SNOW); +        songpackEventMap.put(SongpackEventType.UNDERWATER, player.isSubmergedInWater()); - songpackEventMap.put(SongpackEventType.STORM, world.isThundering()); +        // Weather +        songpackEventMap.put(SongpackEventType.RAIN, world.isRaining() && biome.value().getPrecipitation(pos, world.getSeaLevel()) == Biome.Precipitation.RAIN); +        songpackEventMap.put(SongpackEventType.SNOW, world.isRaining() && biome.value().getPrecipitation(pos, world.getSeaLevel()) == Biome.Precipitation.SNOW); +        songpackEventMap.put(SongpackEventType.STORM, world.isThundering()); - var currentTags = biome.streamTags().toList(); - // Update all ConventionalBiomeTags - for (TagKey tag : BIOME_TAGS) { - boolean found = false; +        var currentTags = biome.streamTags().toList(); - // search by ID instead of comparing tagkey, doesn't work on non-fabric - for (TagKey curTag : currentTags) { - if (curTag.id() == tag.id()) { - found = true; - break; - } - } - // Update all ConventionalBiomeTags - - biomeTagEventMap.put(tag, found); - } +        // Update all ConventionalBiomeTags +        for (TagKey tag : BIOME_TAGS) { +            boolean found = false; +            // search by ID instead of comparing tagkey, doesn't work on non-fabric +            for (TagKey curTag : currentTags) { +                if (curTag.id() == tag.id()) { +                    found = true; +                    break; +                } +            } - // process recent damage sources +            biomeTagEventMap.put(tag, found); +        } - // remove past sources - recentEntityDamageSources.entrySet().removeIf(entry -> entry.getKey() == null || !entry.getKey().isAlive() || world.getTime() - entry.getValue() > TIME_FOR_FORGET_DAMAGE_SOURCE); - // add new damage sources - var recentDamage = player.getRecentDamageSource(); +        // process recent damage sources - if (recentDamage != null && recentDamage.getSource() != null) { - recentEntityDamageSources.put(recentDamage.getSource(), world.getTime()); - } +        // remove past sources +        recentEntityDamageSources.entrySet().removeIf(entry -> entry.getKey() == null || !entry.getKey().isAlive() || world.getTime() - entry.getValue() > TIME_FOR_FORGET_DAMAGE_SOURCE); +        // add new damage sources +        var recentDamage = player.getRecentDamageSource(); +        if (recentDamage != null && recentDamage.getSource() != null) { +            recentEntityDamageSources.put(recentDamage.getSource(), world.getTime()); +        } - // Search for nearby entities that could be relevant to music - { - int villagerCount = 0; - double radiusXZ = 30.0; - double radiusY = 15.0; +        // Search for nearby entities that could be relevant to music - Box box = new Box(player.getX() - radiusXZ, player.getY() - radiusY, player.getZ() - radiusXZ, - player.getX() + radiusXZ, player.getY() + radiusY, player.getZ() + radiusXZ); +        { +            int villagerCount = 0; - List nearbyVillagerCheck = world.getEntitiesByClass(VillagerEntity.class, box, entity -> entity != null); +            double radiusXZ = 30.0; +            double radiusY = 15.0; - for (VillagerEntity villagerEntity : nearbyVillagerCheck) { - villagerCount++; - } +            Box box = new Box(player.getX() - radiusXZ, player.getY() - radiusY, player.getZ() - radiusXZ, +                    player.getX() + radiusXZ, player.getY() + radiusY, player.getZ() + radiusXZ); - songpackEventMap.put(SongpackEventType.VILLAGE, villagerCount > 0); - songpackEventMap.put(SongpackEventType.NOT_VILLAGE, villagerCount = 0); +            List nearbyVillagerCheck = world.getEntitiesByClass(VillagerEntity.class, box, entity -> entity != null); - } +            for (VillagerEntity villagerEntity : nearbyVillagerCheck) { +                villagerCount++; +            } - { - List nearbyHostile = world.getEntitiesByClass(HostileEntity.class, - GetBoxAroundPlayer(player, 12.f, 6.f), - entity -> entity != null); +            songpackEventMap.put(SongpackEventType.VILLAGE, villagerCount > 0); - songpackEventMap.put(SongpackEventType.NEARBY_MOBS, nearbyHostile.size() >= 1); +        } - } +        { +            List nearbyHostile = world.getEntitiesByClass(HostileEntity.class, +                    GetBoxAroundPlayer(player, 12.f, 6.f), +                    entity -> entity != null); +            songpackEventMap.put(SongpackEventType.NEARBY_MOBS, nearbyHostile.size() >= 1); - //songpackEventMap.put(SongpackEventType.HOSTILE_MOBS, aggroMobsCount >= 4); +        } - //System.out.println("Villager count: " + villagerCount + ", Aggro mobs count: " + aggroMobsCount); +        //songpackEventMap.put(SongpackEventType.HOSTILE_MOBS, aggroMobsCount >= 4); - // try to get boss bars - boolean bossBarActive = false; +        //System.out.println("Villager count: " + villagerCount + ", Aggro mobs count: " + aggroMobsCount); - if (mc.inGameHud != null && mc.inGameHud.getBossBarHud() != null) { - try { - var bossBars = ((BossBarHudAccessor) mc.inGameHud.getBossBarHud()).getBossBars(); +        // try to get boss bars +        boolean bossBarActive = false; - if (!bossBars.isEmpty()) { - bossBarActive = true; - } - } catch (Exception e) { - } - } +        if (mc.inGameHud != null && mc.inGameHud.getBossBarHud() != null) { +            try { - songpackEventMap.put(SongpackEventType.BOSS, bossBarActive); - songpackEventMap.put(SongpackEventType.NOT_BOSS, !bossBarActive); +                var bossBars = ((BossBarHudAccessor) mc.inGameHud.getBossBarHud()).getBossBars(); +                if (!bossBars.isEmpty()) { +                    bossBarActive = true; +                } +            } catch (Exception e) { +            } +        } - songpackEventMap.put(SongpackEventType.GENERIC, true); - } +        songpackEventMap.put(SongpackEventType.BOSS, bossBarActive); - private static Box GetBoxAroundPlayer(ClientPlayerEntity player, float radiusXZ, float radiusY) { +        songpackEventMap.put(SongpackEventType.GENERIC, true); +    } - return new Box(player.getX() - radiusXZ, player.getY() - radiusY, player.getZ() - radiusXZ, - player.getX() + radiusXZ, player.getY() + radiusY, player.getZ() + radiusXZ); - } +    private static Box GetBoxAroundPlayer(ClientPlayerEntity player, float radiusXZ, float radiusY) { +        return new Box(player.getX() - radiusXZ, player.getY() - radiusY, player.getZ() - radiusXZ, +                player.getX() + radiusXZ, player.getY() + radiusY, player.getZ() + radiusXZ); - public static void initialize() { +    } - songpackEventMap.clear(); - for (SongpackEventType eventType : SongpackEventType.values()) { - songpackEventMap.put(eventType, false); - } - } +    public static void initialize() { +        songpackEventMap.clear(); +        for (SongpackEventType eventType : SongpackEventType.values()) { +            songpackEventMap.put(eventType, false); +        } +    } - private static final List reusableValidEntries = new ArrayList<>(); -/* public static List getAllValidEntries() { +    private static final List reusableValidEntries = new ArrayList<>(); - reusableValidEntries.clear(); - for (int i = 0; i < SongLoader.activeSongpack.entries.length; i++) { +/*    public static List getAllValidEntries() { - SongpackEntry entry = SongLoader.activeSongpack.entries[i]; - if (entry == null) continue; +        reusableValidEntries.clear(); - boolean eventsMet = true; +        for (int i = 0; i < SongLoader.activeSongpack.entries.length; i++) { - for (SongpackEventType songpackEvent : entry.songpackEvents) { +            SongpackEntry entry = SongLoader.activeSongpack.entries[i]; +            if (entry == null) continue; - if (!songpackEventMap.containsKey(songpackEvent)) - continue; +            boolean eventsMet = true; - if (!songpackEventMap.get(songpackEvent)) { - eventsMet = false; - break; - } - } +            for (SongpackEventType songpackEvent : entry.songpackEvents) { - for (TagKey biomeTagEvent : entry.biomeTagEvents) { +                if (!songpackEventMap.containsKey(songpackEvent)) +                    continue; - if (!biomeTagEventMap.containsKey(biomeTagEvent)) - continue; +                if (!songpackEventMap.get(songpackEvent)) { +                    eventsMet = false; +                    break; +                } +            } - if (!biomeTagEventMap.get(biomeTagEvent)) { - eventsMet = false; - break; - } - } +            for (TagKey biomeTagEvent : entry.biomeTagEvents) { - if (eventsMet) { - reusableValidEntries.add(entry); - } - } +                if (!biomeTagEventMap.containsKey(biomeTagEvent)) +                    continue; - return reusableValidEntries; - }*/ +                if (!biomeTagEventMap.get(biomeTagEvent)) { +                    eventsMet = false; +                    break; +                } +            } +            if (eventsMet) { +                reusableValidEntries.add(entry); +            } +        } - static boolean hasSongNotPlayedRecently(List songs) { - for (String song : songs) { - if (!recentlyPickedSongs.contains(song)) { - return true; - } - } - return false; - } +        return reusableValidEntries; +    }*/ - static List getNotRecentlyPlayedSongs(String[] songs) { - List notRecentlyPlayed = new ArrayList<>(Arrays.asList(songs)); - notRecentlyPlayed.removeAll(recentlyPickedSongs); - return notRecentlyPlayed; - } +    static boolean hasSongNotPlayedRecently(List songs) { +        for (String song : songs) { +            if (!recentlyPickedSongs.contains(song)) { +                return true; +            } +        } +        return false; +    } - static String pickRandomSong(List songs) { +    static List getNotRecentlyPlayedSongs(String[] songs) { +        List notRecentlyPlayed = new ArrayList<>(Arrays.asList(songs)); +        notRecentlyPlayed.removeAll(recentlyPickedSongs); +        return notRecentlyPlayed; +    } - List cleanedSongs = new ArrayList<>(songs); - cleanedSongs.removeAll(recentlyPickedSongs); +    static String pickRandomSong(List songs) { +        List cleanedSongs = new ArrayList<>(songs); - String picked; +        cleanedSongs.removeAll(recentlyPickedSongs); - // If there's remaining songs, pick one of those - if (!cleanedSongs.isEmpty()) { - int randomIndex = rand.nextInt(cleanedSongs.size()); - picked = cleanedSongs.get(randomIndex); - } - // Else we've played all these recently so just pick a new random one - else { - int randomIndex = rand.nextInt(songs.size()); - picked = songs.get(randomIndex); - } +        String picked; +        // If there's remaining songs, pick one of those +        if (!cleanedSongs.isEmpty()) { +            int randomIndex = rand.nextInt(cleanedSongs.size()); +            picked = cleanedSongs.get(randomIndex); +        } - // only track the past X songs - if (recentlyPickedSongs.size() >= 8) { - recentlyPickedSongs.remove(0); - } +        // Else we've played all these recently so just pick a new random one +        else { +            int randomIndex = rand.nextInt(songs.size()); +            picked = songs.get(randomIndex); +        } - recentlyPickedSongs.add(picked); +        // only track the past X songs +        if (recentlyPickedSongs.size() >= 8) { +            recentlyPickedSongs.remove(0); +        } - return picked; - } +        recentlyPickedSongs.add(picked); - public static String getSongName(String song) { - return song == null ? "" : song.replaceAll("([^A-Z])([A-Z])", "$1 $2"); - } +        return picked; +    } - - public static boolean isEntryValid(RMRuntimeEntry entry) { - for (var condition : entry.conditions) { +    public static String getSongName(String song) { +        return song == null ? "" : song.replaceAll("([^A-Z])([A-Z])", "$1 $2"); +    } - // each condition functions as an OR, if at least one of them is true then the condition is true +    +    public static boolean isEntryValid(RMRuntimeEntry entry) { +        for (var condition : entry.conditions) { - boolean songpackEventsValid = false; +            // each condition functions as an OR, if at least one of them is true then the condition is true - for (SongpackEventType songpackEvent : condition.songpackEvents) { - if (songpackEventMap.containsKey(songpackEvent) && songpackEventMap.get(songpackEvent)) { - songpackEventsValid = true; - break; - } - } - boolean biomeTypesValid = false; - for (var biome : condition.biomeTypes) { - if (currentBiomeName.contains(biome)) { - biomeTypesValid = true; - break; - } - } +            boolean songpackEventsValid = false; - boolean biomeTagsValid = false; - for (var biomeTag : condition.biomeTags) { - if (biomeTagEventMap.containsKey(biomeTag) && biomeTagEventMap.get(biomeTag)) { - biomeTagsValid = true; - break; - } - } +            for (SongpackEventType songpackEvent : condition.songpackEvents) { +                if (songpackEventMap.containsKey(songpackEvent) && songpackEventMap.get(songpackEvent)) { +                    songpackEventsValid = true; +                    break; +                } +            } - boolean dimsValid = false; - for (var dim : condition.dimTypes) { - if (currentDimName.contains(dim)) { - dimsValid = true; - break; - } - } +            boolean biomeTypesValid = false; +            for (var biome : condition.biomeTypes) { +                if (currentBiomeName.contains(biome)) { +                    biomeTypesValid = true; +                    break; +                } +            } +            boolean biomeTagsValid = false; +            for (var biomeTag : condition.biomeTags) { +                if (biomeTagEventMap.containsKey(biomeTag) && biomeTagEventMap.get(biomeTag)) { +                    biomeTagsValid = true; +                    break; +                } +            } - if (!songpackEventsValid && !biomeTypesValid && !biomeTagsValid && !dimsValid) { - // none of the OR conditions were valid on this condition, return false - return false; - } +            boolean dimsValid = false; +            for (var dim : condition.dimTypes) { +                if (currentDimName.contains(dim)) { +                    dimsValid = true; +                    break; +                } +            } - } - // we passed without failing so it must be true - return true; - - } +            if (!songpackEventsValid && !biomeTypesValid && !biomeTagsValid && !dimsValid) { +                // none of the OR conditions were valid on this condition, return false +                return false; +            } + +        } + +        // we passed without failing so it must be true +        return true; +        +    } @@ -480,3 +459,5 @@ public static boolean isEntryValid(RMRuntimeEntry entry) { } + +