Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/java/circuitlord/reactivemusic/SongLoader.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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 {
Expand Down
42 changes: 39 additions & 3 deletions src/main/java/circuitlord/reactivemusic/SongPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,6 +39,9 @@ public final class SongPicker {

public static Map<TagKey<Biome>, Boolean> biomeTagEventMap = new HashMap<>();

// This can probably be done differently (I'm tired, boss...)
public static Map<EntityType<?>, Boolean> entityEventMap = new HashMap<>();

public static Map<Entity, Long> recentEntityDamageSources = new HashMap<>();


Expand Down Expand Up @@ -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));
Expand All @@ -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());
Expand Down Expand Up @@ -191,6 +196,26 @@ public static void tickEventMap() {

}

// TODO: change entityEventMap to Map of <entityTypes, numberOfEntities> 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<MobEntity> 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<HostileEntity> nearbyHostile = world.getEntitiesByClass(HostileEntity.class,
GetBoxAroundPlayer(player, 12.f, 6.f),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -313,6 +339,16 @@ public static List<SongpackEntry> getAllValidEntries() {
}
}

for (EntityType<?> entityEvent : entry.entityEvents) {
if (!entityEventMap.containsKey(entityEvent))
{
//continue;
//if (!entityEventMap.get(entityEvent)) {
eventsMet = false;
break;
}
}

for (TagKey<Biome> biomeTagEvent : entry.biomeTagEvents) {

if (!biomeTagEventMap.containsKey(biomeTagEvent))
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/circuitlord/reactivemusic/SongpackEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,4 +26,5 @@ public class SongpackEntry {
public int id = -1;
public List<SongpackEventType> songpackEvents = new ArrayList<>();
public List<TagKey<Biome>> biomeTagEvents = new ArrayList<>();
}
public List<EntityType<?>> entityEvents = new ArrayList<>();
}
7 changes: 7 additions & 0 deletions src/main/resources/musicpack/ReactiveMusic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down