mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Move poisoned joke sound to a tag
This commit is contained in:
parent
00bd1a65b9
commit
30eab4ee6a
6 changed files with 81 additions and 80 deletions
|
@ -7,6 +7,7 @@ import net.minecraft.entity.effect.StatusEffect;
|
|||
import net.minecraft.item.Item;
|
||||
import net.minecraft.registry.*;
|
||||
import net.minecraft.registry.tag.TagKey;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
|
||||
|
@ -148,4 +149,12 @@ public interface UTags {
|
|||
return TagKey.of(RegistryKeys.STATUS_EFFECT, Unicopia.id(name));
|
||||
}
|
||||
}
|
||||
|
||||
interface Sounds {
|
||||
TagKey<SoundEvent> POISON_JOKE_EVENTS = sound("poison_joke_events");
|
||||
|
||||
private static TagKey<SoundEvent> sound(String name) {
|
||||
return TagKey.of(RegistryKeys.SOUND_EVENT, Unicopia.id(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import com.minelittlepony.unicopia.entity.effect.SeaponyGraceStatusEffect;
|
|||
import com.minelittlepony.unicopia.entity.effect.UPotions;
|
||||
import com.minelittlepony.unicopia.entity.mob.UEntities;
|
||||
import com.minelittlepony.unicopia.item.UItems;
|
||||
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
||||
import com.minelittlepony.unicopia.network.Channel;
|
||||
import com.minelittlepony.unicopia.particle.UParticles;
|
||||
import com.minelittlepony.unicopia.server.world.BlockDestructionManager;
|
||||
|
@ -104,7 +103,6 @@ public class Unicopia implements ModInitializer {
|
|||
|
||||
private void registerServerDataReloaders(ResourceManagerHelper registry) {
|
||||
registry.registerReloadListener(TreeTypeLoader.INSTANCE);
|
||||
registry.registerReloadListener(UEnchantments.POISONED_JOKE);
|
||||
registry.registerReloadListener(new TraitLoader());
|
||||
registry.registerReloadListener(StateMapLoader.INSTANCE);
|
||||
registry.registerReloadListener(SpellbookChapterLoader.INSTANCE);
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package com.minelittlepony.unicopia.datagen.providers.tag;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import com.minelittlepony.unicopia.UTags;
|
||||
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
|
||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
|
||||
public class USoundEventTagProvider extends FabricTagProvider<SoundEvent> {
|
||||
public USoundEventTagProvider(FabricDataOutput output, CompletableFuture<WrapperLookup> registriesFuture) {
|
||||
super(output, RegistryKeys.SOUND_EVENT, registriesFuture);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(WrapperLookup lookup) {
|
||||
getOrCreateTagBuilder(UTags.Sounds.POISON_JOKE_EVENTS).add(
|
||||
SoundEvents.AMBIENT_CAVE.registryKey(),
|
||||
SoundEvents.MUSIC_MENU.registryKey(),
|
||||
SoundEvents.ENTITY_GENERIC_EXPLODE.registryKey(),
|
||||
SoundEvents.AMBIENT_NETHER_WASTES_LOOP.registryKey(),
|
||||
SoundEvents.AMBIENT_NETHER_WASTES_MOOD.registryKey(),
|
||||
SoundEvents.AMBIENT_CRIMSON_FOREST_MOOD.registryKey(),
|
||||
SoundEvents.AMBIENT_BASALT_DELTAS_MOOD.registryKey(),
|
||||
SoundEvents.AMBIENT_BASALT_DELTAS_LOOP.registryKey()
|
||||
).add(
|
||||
SoundEvents.ENTITY_CREEPER_PRIMED,
|
||||
SoundEvents.BLOCK_STONE_BUTTON_CLICK_ON,
|
||||
SoundEvents.BLOCK_STONE_BUTTON_CLICK_OFF,
|
||||
SoundEvents.BLOCK_WOODEN_PRESSURE_PLATE_CLICK_ON,
|
||||
SoundEvents.BLOCK_WOODEN_PRESSURE_PLATE_CLICK_OFF,
|
||||
SoundEvents.BLOCK_WOODEN_DOOR_CLOSE,
|
||||
SoundEvents.BLOCK_STONE_BREAK,
|
||||
SoundEvents.ITEM_SHIELD_BREAK,
|
||||
SoundEvents.ENTITY_BLAZE_AMBIENT,
|
||||
SoundEvents.ENTITY_ZOMBIE_AMBIENT,
|
||||
SoundEvents.ENTITY_DROWNED_AMBIENT,
|
||||
SoundEvents.ENTITY_ENDERMITE_AMBIENT,
|
||||
SoundEvents.ENTITY_SKELETON_AMBIENT,
|
||||
SoundEvents.ENTITY_SKELETON_HORSE_AMBIENT,
|
||||
SoundEvents.ENTITY_ZOGLIN_AMBIENT,
|
||||
SoundEvents.ENTITY_ZOMBIFIED_PIGLIN_AMBIENT,
|
||||
SoundEvents.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR,
|
||||
SoundEvents.ENTITY_TNT_PRIMED,
|
||||
SoundEvents.AMBIENT_UNDERWATER_LOOP_ADDITIONS_ULTRA_RARE,
|
||||
SoundEvents.AMBIENT_UNDERWATER_LOOP_ADDITIONS_RARE
|
||||
);
|
||||
|
||||
}
|
||||
}
|
|
@ -10,8 +10,10 @@ import java.util.stream.Stream;
|
|||
|
||||
import org.apache.commons.lang3.reflect.TypeUtils;
|
||||
|
||||
import com.minelittlepony.unicopia.UTags;
|
||||
import com.minelittlepony.unicopia.Unicopia;
|
||||
import com.minelittlepony.unicopia.entity.Living;
|
||||
import com.minelittlepony.unicopia.util.RegistryUtils;
|
||||
import com.minelittlepony.unicopia.util.Resources;
|
||||
|
||||
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
|
||||
|
@ -23,11 +25,7 @@ import net.minecraft.util.math.random.Random;
|
|||
import net.minecraft.util.profiler.Profiler;
|
||||
import net.minecraft.registry.Registries;
|
||||
|
||||
public class PoisonedJokeEnchantment extends SimpleEnchantment implements IdentifiableResourceReloadListener {
|
||||
private static final Identifier ID = Unicopia.id("data/poisoned_joke_sounds");
|
||||
private static final Identifier FILE = Unicopia.id("poisoned_joke_sounds.json");
|
||||
private static final Type TYPE = TypeUtils.parameterize(List.class, Identifier.class);
|
||||
private List<SoundEvent> sounds = new ArrayList<>();
|
||||
public class PoisonedJokeEnchantment extends SimpleEnchantment {
|
||||
|
||||
protected PoisonedJokeEnchantment(Options options) {
|
||||
super(options);
|
||||
|
@ -35,7 +33,7 @@ public class PoisonedJokeEnchantment extends SimpleEnchantment implements Identi
|
|||
|
||||
@Override
|
||||
public void onUserTick(Living<?> user, int level) {
|
||||
if (sounds.isEmpty() || user.asWorld().isClient) {
|
||||
if (user.asWorld().isClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -47,45 +45,15 @@ public class PoisonedJokeEnchantment extends SimpleEnchantment implements Identi
|
|||
if (rng.nextInt(Math.max(1, (light * 9) + (int)data.level)) == 0) {
|
||||
data.level = rng.nextInt(5000);
|
||||
|
||||
user.asWorld().playSoundFromEntity(
|
||||
null,
|
||||
user.asEntity(),
|
||||
sounds.get(rng.nextInt(sounds.size())), SoundCategory.HOSTILE,
|
||||
0.5F + rng.nextFloat() * 0.5F,
|
||||
0.5F + rng.nextFloat() * 0.5F
|
||||
);
|
||||
RegistryUtils.pickRandom(user.asWorld(), UTags.Sounds.POISON_JOKE_EVENTS).ifPresent(event -> {
|
||||
user.asWorld().playSoundFromEntity(
|
||||
null,
|
||||
user.asEntity(),
|
||||
event, SoundCategory.HOSTILE,
|
||||
0.5F + rng.nextFloat() * 0.5F,
|
||||
0.5F + rng.nextFloat() * 0.5F
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getFabricId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> reload(Synchronizer sync, ResourceManager manager,
|
||||
Profiler serverProfiler, Profiler clientProfiler,
|
||||
Executor serverExecutor, Executor clientExecutor) {
|
||||
|
||||
return sync.whenPrepared(null).thenRunAsync(() -> {
|
||||
clientProfiler.startTick();
|
||||
clientProfiler.push("Loading poisoned joke sound options");
|
||||
|
||||
sounds = Resources.getResources(manager, FILE)
|
||||
.flatMap(r -> Resources.loadFile(r, TYPE, "Failed to load sounds file at "))
|
||||
.distinct()
|
||||
.flatMap(this::findSound)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
clientProfiler.pop();
|
||||
clientProfiler.endTick();
|
||||
}, clientExecutor);
|
||||
}
|
||||
|
||||
private Stream<SoundEvent> findSound(Identifier id) {
|
||||
return Registries.SOUND_EVENT.getOrEmpty(id).map(Stream::of).orElseGet(() -> {
|
||||
Unicopia.LOGGER.warn("Could not find sound with id {}", id);
|
||||
return Stream.empty();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.Optional;
|
|||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
|
||||
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
|
||||
|
@ -34,10 +35,11 @@ public interface RegistryUtils {
|
|||
}
|
||||
|
||||
static <T> Optional<T> pickRandom(World world, TagKey<T> key) {
|
||||
return world.getRegistryManager().getOptional(key.registry())
|
||||
.flatMap(registry -> registry.getEntryList(key))
|
||||
.flatMap(entries -> entries.getRandom(world.random))
|
||||
.map(RegistryEntry::value);
|
||||
return pickRandomEntry(world, key).map(RegistryEntry::value);
|
||||
}
|
||||
|
||||
static <T> Optional<RegistryEntry<T>> pickRandomEntry(World world, TagKey<T> key) {
|
||||
return pickRandomEntry(world, key, Predicates.alwaysTrue());
|
||||
}
|
||||
|
||||
static <T> Optional<T> pickRandom(World world, TagKey<T> key, Predicate<T> filter) {
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
[
|
||||
"minecraft:ambient.cave",
|
||||
"minecraft:entity.creeper.primed",
|
||||
"minecraft:block.stone_button.click_on",
|
||||
"minecraft:block.stone_button.click_off",
|
||||
"minecraft:block.wooden_pressure_plate.click_on",
|
||||
"minecraft:block.wooden_door.close",
|
||||
"minecraft:block.stone.break",
|
||||
"minecraft:item.shield.break",
|
||||
"minecraft:entity.blaze.ambient",
|
||||
"minecraft:entity.zombie.ambient",
|
||||
"minecraft:entity.drowned.ambient",
|
||||
"minecraft:entity.endermite.ambient",
|
||||
"minecraft:entity.skeleton.ambient",
|
||||
"minecraft:entity.skeleton_horse.ambient",
|
||||
"minecraft:entity.zoglin.ambient",
|
||||
"minecraft:entity.zombified_piglin.ambient",
|
||||
"minecraft:entity.zombie.break_wooden_door",
|
||||
"minecraft:music.menu",
|
||||
"minecraft:entity.tnt.primed",
|
||||
"minecraft:entity.generic.explode",
|
||||
"minecraft:ambient.nether_wastes.loop",
|
||||
"minecraft:ambient.nether_wastes.mood",
|
||||
"minecraft:ambient.crimson_forest.mood",
|
||||
"minecraft:ambient.basalt_deltas.mood",
|
||||
"minecraft:ambient.basalt_deltas.loop",
|
||||
"minecraft:ambient.underwater.loop.additions.ultra_rare",
|
||||
"minecraft:ambient.underwater.loop.additions.rare"
|
||||
]
|
Loading…
Reference in a new issue