Skip to content

Commit

Permalink
allow area priority
Browse files Browse the repository at this point in the history
  • Loading branch information
HamaIndustries committed Nov 28, 2024
1 parent 562f3aa commit 59cdb21
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation "maven.modrinth:area_lib:0.0.2"
modImplementation "maven.modrinth:area_lib:0.0.4"
}

processResources {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ minecraft_version=1.21.1
loader_version=0.16.9

# Mod Properties
mod_version=4.0.0
mod_version=5.0.0
maven_group=symbolics.division.meret
archives_base_name=meret

Expand Down
52 changes: 40 additions & 12 deletions src/client/java/symbolics/division/meret/MeretClient.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package symbolics.division.meret;

import com.mojang.datafixers.util.Pair;
import dev.doublekekse.area_lib.Area;
import dev.doublekekse.area_lib.data.AreaClientData;
import dev.doublekekse.area_lib.data.AreaSavedData;
import it.unimi.dsi.fastutil.PriorityQueue;
import it.unimi.dsi.fastutil.objects.ObjectArrayPriorityQueue;
import net.fabricmc.api.ClientModInitializer;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.Holder;
Expand All @@ -13,6 +17,9 @@
import net.minecraft.world.item.JukeboxSong;
import org.jetbrains.annotations.Nullable;

import java.util.Comparator;
import java.util.Objects;

public class MeretClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
Expand All @@ -23,25 +30,46 @@ public void onInitializeClient() {
public static Music getOverride(LocalPlayer player) {
if (player == null) return null;

AreaSavedData.IdentifiableArea potentialArea = AreaClientData.getClientLevelData()
.find(player.level(), player.position());
Area[] areas = AreaClientData.getClientLevelData().getAreas().toArray(Area[]::new);

if (potentialArea == null) return null;
PriorityQueue<Area> queue = new ObjectArrayPriorityQueue<>(areas.length, Comparator.comparingInt(Area::getPriority));
// for (Area potentialArea : areas) {
// queue.enqueue(potentialArea);
// }

Registry<JukeboxSong> songRegistry = player.level().registryAccess().registry(Registries.JUKEBOX_SONG).orElse(null);

if (songRegistry == null) return null;
if (songRegistry == null) {
Meret.LOGGER.info("Could not get a handle on songRegistry, you will not hear any music.");
return null;
}

var songTags = songRegistry.getTagNames().toList();


// for (var tag : songTags) {
// Area area = AreaClientData.getClientLevelData().get(tag.location());
// if (area != null && area.contains(player))
// queue.enqueue(area);
// }

// return null;
// if (queue.isEmpty()) return null;

// songRegistry.getOrCreateTag()

TagKey<JukeboxSong> musicTag = TagKey.create(
Registries.JUKEBOX_SONG,
potentialArea.id()
);

HolderSet.Named<JukeboxSong> taggedHolders = songRegistry.getOrCreateTag(musicTag);
Holder<JukeboxSong> song = taggedHolders.getRandomElement(player.getRandom()).orElse(null);

if (song == null) return null;
// sorry jasmine (´・ω・`)
return songRegistry.getTagNames()
.map(tag -> new Pair<>(tag, AreaClientData.getClientLevelData().get(tag.location())))
.filter(p -> p.getSecond() != null && p.getSecond().contains(player))
.max(Comparator.comparingInt(p -> p.getSecond().getPriority()))
.flatMap(p -> songRegistry.getOrCreateTag(p.getFirst()).getRandomElement(player.getRandom()))
.map(song -> new Music(song.value().soundEvent(), 10, 10, false))
.orElse(null);

return new Music(song.value().soundEvent(), 20 * 3 * 60, 20 * 5 * 60, false);
// return new Music(song.value().soundEvent(), 10, 10, false);
//// return new Music(song.value().soundEvent(), 20 * 3 * 60, 20 * 5 * 60, false);
}
}

0 comments on commit 59cdb21

Please sign in to comment.