From 8c6c58937cc8087261853d44d0b9625bb7c9d512 Mon Sep 17 00:00:00 2001 From: MrBenjaminBowman <40965491+MrBenjaminBowman@users.noreply.github.com> Date: Tue, 3 Dec 2024 11:49:24 -0500 Subject: [PATCH 1/6] SongpackEntry - add entityEvent --- src/main/java/circuitlord/reactivemusic/SongpackEntry.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/circuitlord/reactivemusic/SongpackEntry.java b/src/main/java/circuitlord/reactivemusic/SongpackEntry.java index bfdb25b..24c1b46 100644 --- a/src/main/java/circuitlord/reactivemusic/SongpackEntry.java +++ b/src/main/java/circuitlord/reactivemusic/SongpackEntry.java @@ -25,4 +25,5 @@ public class SongpackEntry { public int id = -1; public List songpackEvents = new ArrayList<>(); public List> biomeTagEvents = new ArrayList<>(); -} \ No newline at end of file + public List> entityEvents = new ArrayList<>(); +} From f87a9f8445752f741b5793d759b2820deb66fdfc Mon Sep 17 00:00:00 2001 From: MrBenjaminBowman <40965491+MrBenjaminBowman@users.noreply.github.com> Date: Tue, 3 Dec 2024 11:50:10 -0500 Subject: [PATCH 2/6] import EntityType forgor --- src/main/java/circuitlord/reactivemusic/SongpackEntry.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/circuitlord/reactivemusic/SongpackEntry.java b/src/main/java/circuitlord/reactivemusic/SongpackEntry.java index 24c1b46..8aba513 100644 --- a/src/main/java/circuitlord/reactivemusic/SongpackEntry.java +++ b/src/main/java/circuitlord/reactivemusic/SongpackEntry.java @@ -3,6 +3,7 @@ import net.minecraft.loot.entry.TagEntry; import net.minecraft.registry.tag.TagKey; import net.minecraft.world.biome.Biome; +import net.minecraft.entity.EntityType; import java.util.ArrayList; import java.util.List; From 0a45c0efadae17b33c92c032ac1d80e3622f04f2 Mon Sep 17 00:00:00 2001 From: MrBenjaminBowman <40965491+MrBenjaminBowman@users.noreply.github.com> Date: Tue, 3 Dec 2024 11:54:28 -0500 Subject: [PATCH 3/6] SongLoader - add entity= path to config loading --- .../circuitlord/reactivemusic/SongLoader.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/circuitlord/reactivemusic/SongLoader.java b/src/main/java/circuitlord/reactivemusic/SongLoader.java index c5c2cb0..a3dfd6e 100644 --- a/src/main/java/circuitlord/reactivemusic/SongLoader.java +++ b/src/main/java/circuitlord/reactivemusic/SongLoader.java @@ -1,6 +1,7 @@ package circuitlord.reactivemusic; import net.fabricmc.loader.api.FabricLoader; + import net.minecraft.entity.EntityType; import net.minecraft.world.biome.Biome; import org.yaml.snakeyaml.Yaml; @@ -241,6 +242,22 @@ public static SongpackConfig loadSongpackConfig(Path configPath, boolean embedde // go to next event if (foundTag) continue; } + + // try to figure out if it's an entity= + if (val.startsWith("entity=")) { + String entityName = val.substring(7); + + boolean foundEntityType = false; + var entityType = EntityType.get(entityName); + // Check if an EntityType of entityName exists + if (EntityType.get(entityName).isPresent()) { + songpack.entries[i].entityEvents.add(entityType.get()); + foundEntityType = true; + } + + // go to next event + if (foundEntityType) continue; + } // last case -- try casting to songpack event enum else { From 54cca8d144941090363163d695032cb7ee1587e6 Mon Sep 17 00:00:00 2001 From: MrBenjaminBowman <40965491+MrBenjaminBowman@users.noreply.github.com> Date: Tue, 3 Dec 2024 12:07:43 -0500 Subject: [PATCH 4/6] SongPicker.java - add entity event handling Uses similar system to biome events --- .../circuitlord/reactivemusic/SongPicker.java | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/main/java/circuitlord/reactivemusic/SongPicker.java b/src/main/java/circuitlord/reactivemusic/SongPicker.java index bf970b9..851ae67 100644 --- a/src/main/java/circuitlord/reactivemusic/SongPicker.java +++ b/src/main/java/circuitlord/reactivemusic/SongPicker.java @@ -10,8 +10,10 @@ import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; import net.minecraft.entity.mob.HostileEntity; -import net.minecraft.entity.mob.Monster; +import net.minecraft.entity.mob.MobEntity; +import net.minecraft.entity.mob.Monster; // note: unused atm import net.minecraft.entity.passive.HorseEntity; import net.minecraft.entity.passive.PigEntity; import net.minecraft.entity.passive.VillagerEntity; @@ -37,6 +39,9 @@ public final class SongPicker { public static Map, Boolean> biomeTagEventMap = new HashMap<>(); + // This can probably be done differently (I'm tired, boss...) + public static Map, Boolean> entityEventMap = new HashMap<>(); + public static Map recentEntityDamageSources = new HashMap<>(); @@ -136,7 +141,7 @@ public static void tickEventMap() { // Weather songpackEventMap.put(SongpackEventType.RAIN, world.isRaining()); - + // TODO: implement SNOW // TODO: WILL BE REMOVED, use biomeTagEventMap songpackEventMap.put(SongpackEventType.MOUNTAIN, biome.isIn(BiomeTags.IS_MOUNTAIN)); @@ -148,7 +153,7 @@ public static void tickEventMap() { biomeTagEventMap.put(tag, biome.isIn(tag)); } -/* var biomeTagsList = biome.streamTags().toList(); + /* var biomeTagsList = biome.streamTags().toList(); for (var tag : biomeTagsList) { System.out.println(tag.id().toString()); @@ -191,6 +196,26 @@ public static void tickEventMap() { } + // TODO: change entityEventMap to Map of for threshold requirements + // TODO: this would probably also work for checking hostile mobs & villagers from the same map + { + entityEventMap.clear(); + //int entityCount = 0; + + double radiusXZ = 30.0; + double radiusY = 15.0; + // This might as well be GetBoxAroundPlayer + Box box = new Box(player.getX() - radiusXZ, player.getY() - radiusY, player.getZ() - radiusXZ, + player.getX() + radiusXZ, player.getY() + radiusY, player.getZ() + radiusXZ); + + List nearbyEntityCheck = mc.world.getEntitiesByClass(MobEntity.class, box, entity -> entity != null); + + for (MobEntity entity : nearbyEntityCheck) { + entityEventMap.put(entity.getType(), nearbyEntityCheck.size() >= 1); + ReactiveMusic.LOGGER.info("Entity type: " + String.valueOf(entity.getType())); + } + } + { List nearbyHostile = world.getEntitiesByClass(HostileEntity.class, GetBoxAroundPlayer(player, 12.f, 6.f), @@ -239,6 +264,7 @@ private static Box GetBoxAroundPlayer(ClientPlayerEntity player, float radiusXZ, public static void initialize() { songpackEventMap.clear(); + entityEventMap.clear(); // I think this is superfluous for (SongpackEventType eventType : SongpackEventType.values()) { songpackEventMap.put(eventType, false); @@ -313,6 +339,16 @@ public static List getAllValidEntries() { } } + for (EntityType entityEvent : entry.entityEvents) { + if (!entityEventMap.containsKey(entityEvent)) + { + //continue; + //if (!entityEventMap.get(entityEvent)) { + eventsMet = false; + break; + } + } + for (TagKey biomeTagEvent : entry.biomeTagEvents) { if (!biomeTagEventMap.containsKey(biomeTagEvent)) From da541847a3383e9b5373271abf7d75802dc3c174 Mon Sep 17 00:00:00 2001 From: MrBenjaminBowman <40965491+MrBenjaminBowman@users.noreply.github.com> Date: Tue, 3 Dec 2024 12:10:34 -0500 Subject: [PATCH 5/6] ReactiveMusic.yaml - entity event example --- src/main/resources/musicpack/ReactiveMusic.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/resources/musicpack/ReactiveMusic.yaml b/src/main/resources/musicpack/ReactiveMusic.yaml index 5443fd2..8b57f4f 100644 --- a/src/main/resources/musicpack/ReactiveMusic.yaml +++ b/src/main/resources/musicpack/ReactiveMusic.yaml @@ -22,6 +22,13 @@ entries: # - "CastleInTheSky" # - "CircleOfLife" +# TODO: check if this works with modded mobs as well (with modname:mobname) + - events: ["ENTITY=zombie"] + alwaysPlay: true + alwaysStop: true + songs: + - "LastStand" + - "Ruthless" - events: [ "UNDERWATER" ] From 817658721e90ff2a3378a2dd8259a3571b3df0e6 Mon Sep 17 00:00:00 2001 From: MrBenjaminBowman <40965491+MrBenjaminBowman@users.noreply.github.com> Date: Tue, 3 Dec 2024 12:17:02 -0500 Subject: [PATCH 6/6] SongPicker.java - commented out entity debug logger --- src/main/java/circuitlord/reactivemusic/SongPicker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/circuitlord/reactivemusic/SongPicker.java b/src/main/java/circuitlord/reactivemusic/SongPicker.java index 851ae67..a772310 100644 --- a/src/main/java/circuitlord/reactivemusic/SongPicker.java +++ b/src/main/java/circuitlord/reactivemusic/SongPicker.java @@ -212,7 +212,7 @@ public static void tickEventMap() { for (MobEntity entity : nearbyEntityCheck) { entityEventMap.put(entity.getType(), nearbyEntityCheck.size() >= 1); - ReactiveMusic.LOGGER.info("Entity type: " + String.valueOf(entity.getType())); + // ReactiveMusic.LOGGER.info("Entity type: " + String.valueOf(entity.getType())); } }