Skip to content

Commit

Permalink
Override Travel Sound
Browse files Browse the repository at this point in the history
  • Loading branch information
LudoCrypt committed Feb 10, 2022
1 parent 1da176f commit f867ffa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public abstract class LiminalTravelSound {

public abstract Codec<? extends LiminalTravelSound> getCodec();

public int priority() {
return 1000;
}

public static class SimpleTravelSound extends LiminalTravelSound {

public static final Codec<SimpleTravelSound> CODEC = RecordCodecBuilder.create((instance) -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,11 +25,16 @@ public class LiminalSoundRegistry {
// I can't parameterize this
@SuppressWarnings("unchecked")
public static final SimpleRegistry<Codec<? extends LiminalTravelSound>> LIMINAL_TRAVEL_SOUND = (SimpleRegistry<Codec<? extends LiminalTravelSound>>) (Object) FabricRegistryBuilder.createSimple(Codec.class, new Identifier("limlib", "liminal_travel_sound_codec")).attribute(RegistryAttribute.SYNCED).buildAndRegister();
public static final SimpleRegistry<LiminalTravelSound> OVERRIDE_TRAVEL_SOUND = FabricRegistryBuilder.createSimple(LiminalTravelSound.class, new Identifier("limlib", "liminal_travel_sound")).attribute(RegistryAttribute.SYNCED).buildAndRegister();

public static Codec<? extends LiminalTravelSound> register(Identifier id, Codec<? extends LiminalTravelSound> 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<SoundEvent> getCurrent(ServerWorld from, ServerWorld to) {
MutableObject<Optional<SoundEvent>> mutableSound = new MutableObject<Optional<SoundEvent>>(Optional.of(SoundEvents.BLOCK_PORTAL_TRAVEL));

Expand All @@ -41,6 +49,12 @@ public static Optional<SoundEvent> getCurrent(ServerWorld from, ServerWorld to)
toTravelSound.get().hookSound(from, to, mutableSound);
}

List<LiminalTravelSound> 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();
}

Expand Down

0 comments on commit f867ffa

Please sign in to comment.