Skip to content

Commit

Permalink
feat: get random song in tag
Browse files Browse the repository at this point in the history
  • Loading branch information
CallMeEchoCodes committed Nov 26, 2024
1 parent 8f333f4 commit 1371974
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import dev.doublekekse.area_lib.data.AreaSavedData;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -17,6 +19,8 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Optional;

@Mixin(Minecraft.class)
public class MinecraftMixin {
@Shadow public LocalPlayer player;
Expand All @@ -26,16 +30,26 @@ public class MinecraftMixin {
at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/Optionull;map(Ljava/lang/Object;Ljava/util/function/Function;)Ljava/lang/Object;")
)
public void modifyGetSituationalMusic(CallbackInfoReturnable<Music> ci) {
if (this.player != null) {
AreaSavedData.IdentifiableArea potentialArea = AreaClientData.getClientLevelData().find(this.player.level(), this.player.position());
Registry<JukeboxSong> songRegistry = this.player.level().registryAccess().registry(Registries.JUKEBOX_SONG).get();
if (this.player == null) return;

AreaSavedData.IdentifiableArea potentialArea = AreaClientData.getClientLevelData()
.find(this.player.level(), this.player.position());

if (potentialArea == null) return;

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

if (songRegistry == null) return;

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

// I have this
ResourceLocation musicTypeTag = potentialArea.id();
// I need to get a random jukebox sound tagged with this
HolderSet.Named<JukeboxSong> taggedHolders = songRegistry.getOrCreateTag(musicTag);
Holder<JukeboxSong> song = taggedHolders.getRandomElement(this.player.getRandom()).orElse(null);
if (song == null) return;



}
}
}
2 changes: 1 addition & 1 deletion src/client/resources/meret.client.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"package": "symbolics.division.meret.mixin.client",
"compatibilityLevel": "JAVA_21",
"client": [
"ExampleClientMixin"
"MinecraftMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
15 changes: 0 additions & 15 deletions src/main/java/symbolics/division/meret/mixin/ExampleMixin.java

This file was deleted.

1 change: 0 additions & 1 deletion src/main/resources/meret.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"package": "symbolics.division.meret.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"ExampleMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 1371974

Please sign in to comment.