Skip to content

Commit

Permalink
set up sound event for reference
Browse files Browse the repository at this point in the history
  • Loading branch information
HamaIndustries committed Nov 26, 2024
1 parent 4c98fc1 commit 64cd528
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
15 changes: 13 additions & 2 deletions src/client/java/symbolics/division/meret/MeretClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.sounds.Music;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.JukeboxSong;
import org.jetbrains.annotations.Nullable;
Expand All @@ -31,6 +32,7 @@ public static Music getOverride(LocalPlayer player) {
System.out.println("found area " + potentialArea.id().toString());

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

if (songRegistry == null) return null;

Expand All @@ -39,11 +41,20 @@ public static Music getOverride(LocalPlayer player) {
potentialArea.id()
);

TagKey<SoundEvent> soundTag = TagKey.create(
Registries.SOUND_EVENT,
potentialArea.id()
);

HolderSet.Named<SoundEvent> taggedSoundHolders = soundRegistry.getOrCreateTag(soundTag);

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

if (soundSong == null) return null;

// vanilla game music values
return new Music(song.value().soundEvent(), 300, 300, false);
return new Music(soundSong, 300, 300, false);
}
}
27 changes: 22 additions & 5 deletions src/main/java/symbolics/division/meret/Meret.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,40 @@

import net.fabricmc.api.ModInitializer;

import net.fabricmc.fabric.impl.biome.modification.BuiltInRegistryKeys;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.sounds.SoundEvent;
import org.intellij.lang.annotations.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Meret implements ModInitializer {
public static final String MOD_ID = "meret";

// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final String MF_ID = "mf121_music";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

public static ResourceLocation id(String id) {
return ResourceLocation.fromNamespaceAndPath(MOD_ID, id);
}

public static final class OVERRIDES {
public static final ResourceLocation INDUSTRIAL_ID = ResourceLocation.fromNamespaceAndPath("mf121_music", "music.chrono_stereo");
public static final SoundEvent INDUSTRIAL = SoundEvent.createVariableRangeEvent(INDUSTRIAL_ID);
}

@Override
public void onInitialize() {
// This code runs as soon as Minecraft is in a mod-load-ready state.
// However, some things (like resources) may still be uninitialized.
// Proceed with mild caution.

LOGGER.info("Hello Fabric world!");
Registry.register(BuiltInRegistries.SOUND_EVENT, OVERRIDES.INDUSTRIAL_ID, OVERRIDES.INDUSTRIAL);
// Registry.register(Registries.SOUND_EVENT, OVERRIDES.INDUSTRIAL_ID, OVERRIDES.INDUSTRIAL);

}
}
Binary file modified src/main/resources/assets/meret/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 64cd528

Please sign in to comment.