From f867ffaceee10c208f08766840b157d04b0e5541 Mon Sep 17 00:00:00 2001 From: LudoCrypt <60561627+LudoCrypt@users.noreply.github.com> Date: Thu, 10 Feb 2022 14:12:58 -0600 Subject: [PATCH] Override Travel Sound --- gradle.properties | 2 +- .../limlib/api/sound/LiminalTravelSound.java | 4 ++++ .../limlib/impl/world/LiminalSoundRegistry.java | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 1ceff7e..5537308 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,6 +6,6 @@ loader_version=0.12.12 fabric_version=0.45.2+1.18 satin_version=1.7.2 -mod_version = 4.1.1 +mod_version = 4.1.2 maven_group = net.ludocrypt archives_base_name = limlib \ No newline at end of file diff --git a/src/main/java/net/ludocrypt/limlib/api/sound/LiminalTravelSound.java b/src/main/java/net/ludocrypt/limlib/api/sound/LiminalTravelSound.java index 31e8587..85422dc 100644 --- a/src/main/java/net/ludocrypt/limlib/api/sound/LiminalTravelSound.java +++ b/src/main/java/net/ludocrypt/limlib/api/sound/LiminalTravelSound.java @@ -26,6 +26,10 @@ public abstract class LiminalTravelSound { public abstract Codec getCodec(); + public int priority() { + return 1000; + } + public static class SimpleTravelSound extends LiminalTravelSound { public static final Codec CODEC = RecordCodecBuilder.create((instance) -> { diff --git a/src/main/java/net/ludocrypt/limlib/impl/world/LiminalSoundRegistry.java b/src/main/java/net/ludocrypt/limlib/impl/world/LiminalSoundRegistry.java index 66dcf57..fad05d0 100644 --- a/src/main/java/net/ludocrypt/limlib/impl/world/LiminalSoundRegistry.java +++ b/src/main/java/net/ludocrypt/limlib/impl/world/LiminalSoundRegistry.java @@ -1,9 +1,12 @@ package net.ludocrypt.limlib.impl.world; +import java.util.Collections; +import java.util.List; import java.util.Optional; import org.apache.commons.lang3.mutable.MutableObject; +import com.google.common.collect.Lists; import com.mojang.serialization.Codec; import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder; @@ -22,11 +25,16 @@ public class LiminalSoundRegistry { // I can't parameterize this @SuppressWarnings("unchecked") public static final SimpleRegistry> LIMINAL_TRAVEL_SOUND = (SimpleRegistry>) (Object) FabricRegistryBuilder.createSimple(Codec.class, new Identifier("limlib", "liminal_travel_sound_codec")).attribute(RegistryAttribute.SYNCED).buildAndRegister(); + public static final SimpleRegistry OVERRIDE_TRAVEL_SOUND = FabricRegistryBuilder.createSimple(LiminalTravelSound.class, new Identifier("limlib", "liminal_travel_sound")).attribute(RegistryAttribute.SYNCED).buildAndRegister(); public static Codec register(Identifier id, Codec sound) { return Registry.register(LIMINAL_TRAVEL_SOUND, id, sound); } + public static LiminalTravelSound registerOverride(Identifier id, LiminalTravelSound sound) { + return Registry.register(OVERRIDE_TRAVEL_SOUND, id, sound); + } + public static Optional getCurrent(ServerWorld from, ServerWorld to) { MutableObject> mutableSound = new MutableObject>(Optional.of(SoundEvents.BLOCK_PORTAL_TRAVEL)); @@ -41,6 +49,12 @@ public static Optional getCurrent(ServerWorld from, ServerWorld to) toTravelSound.get().hookSound(from, to, mutableSound); } + List list = Lists.newArrayList(OVERRIDE_TRAVEL_SOUND.iterator()); + Collections.sort(list, (a, b) -> Integer.compare(a == null ? 1000 : a.priority(), b == null ? 1000 : b.priority())); + for (LiminalTravelSound sound : list) { + sound.hookSound(from, to, mutableSound); + } + return mutableSound.getValue(); }