diff --git a/changelog.md b/changelog.md index cb826cc..8b3addf 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,7 @@ Effective 2.4.4 (Alpha) - 1.21.1 - Fixed the game crashing when loading in a world with Sodium - Tweaked the splash droplet spawn radius - Fixed ripple and cascade particles not using the last sprite in the animation +- Cleaned up sound effect registration code ------------------------------------------------------ Effective 2.4.3 (Alpha) - 1.21.1 diff --git a/src/client/java/org/ladysnake/effective/core/Effective.java b/src/client/java/org/ladysnake/effective/core/Effective.java index c703c0f..9c25589 100644 --- a/src/client/java/org/ladysnake/effective/core/Effective.java +++ b/src/client/java/org/ladysnake/effective/core/Effective.java @@ -55,17 +55,14 @@ public class Effective implements ClientModInitializer { private static final Uniform1f intensityHypno = HYPNO_SHADER.findUniform1f("Intensity"); private static final Uniform1f sTimeHypno = HYPNO_SHADER.findUniform1f("STime"); private static final Uniform1f rainbowHypno = HYPNO_SHADER.findUniform1f("Rainbow"); + private static int ticksJeb; // freeze frames for feedbacking public static int freezeFrames = -1; // particle types - public static SimpleParticleType BUBBLE; - public static SimpleParticleType CASCADE; - public static SimpleParticleType MIST; public static SimpleParticleType EYES; public static SimpleParticleType WILL_O_WISP; - public static SimpleParticleType CHORUS_PETAL; // public static AllayTwinkleParticleType ALLAY_TWINKLE; // lodestone particles @@ -74,10 +71,6 @@ public class Effective implements ClientModInitializer { // public static FlameParticleType FLAME = new FlameParticleType(); // public static FlameParticleType DRAGON_BREATH = new FlameParticleType(); // public static FireflyParticleType FIREFLY = new FireflyParticleType(); - // sound events - public static SoundEvent AMBIENCE_WATERFALL = SoundEvent.of(Effective.id("ambience.waterfall")); - public static SoundEvent PARRY = SoundEvent.of(Effective.id("entity.parry")); - private static int ticksJeb; public static boolean isNightTime(World world) { return world.getSkyAngle(world.getTimeOfDay()) >= 0.25965086 && world.getSkyAngle(world.getTimeOfDay()) <= 0.7403491; @@ -114,8 +107,6 @@ public void onInitializeClient() { EffectiveParticles.initialize(); // Particles - CHORUS_PETAL = Registry.register(Registries.PARTICLE_TYPE, Effective.id("chorus_petal"), FabricParticleTypes.simple(true)); - ParticleFactoryRegistry.getInstance().register(CHORUS_PETAL, ChorusPetalParticle.Factory::new); EYES = Registry.register(Registries.PARTICLE_TYPE, Effective.id("eyes"), FabricParticleTypes.simple(true)); ParticleFactoryRegistry.getInstance().register(EYES, EyesParticle.Factory::new); WILL_O_WISP = Registry.register(Registries.PARTICLE_TYPE, Effective.id("will_o_wisp"), FabricParticleTypes.simple(true)); @@ -135,10 +126,6 @@ public void onInitializeClient() { // ParticleFactoryRegistry.getInstance().register(FIREFLY, FireflyParticleType.Factory::new); // FIREFLY = Registry.register(Registries.PARTICLE_TYPE, Effective.id("firefly"), FIREFLY); - // sound events - AMBIENCE_WATERFALL = Registry.register(Registries.SOUND_EVENT, AMBIENCE_WATERFALL.getId(), AMBIENCE_WATERFALL); - PARRY = Registry.register(Registries.SOUND_EVENT, PARRY.getId(), PARRY); - // events ClientTickEvents.END_CLIENT_TICK.register(client -> { WaterfallCloudGenerators.tick(); diff --git a/src/client/java/org/ladysnake/effective/core/index/EffectiveParticles.java b/src/client/java/org/ladysnake/effective/core/index/EffectiveParticles.java index 1f7c7bb..c2989fe 100644 --- a/src/client/java/org/ladysnake/effective/core/index/EffectiveParticles.java +++ b/src/client/java/org/ladysnake/effective/core/index/EffectiveParticles.java @@ -29,6 +29,7 @@ public interface EffectiveParticles { SimpleParticleType CASCADE = create("cascade", FabricParticleTypes.simple(true)); SimpleParticleType GLOW_CASCADE = create("glow_cascade", FabricParticleTypes.simple(true)); SimpleParticleType MIST = create("mist", FabricParticleTypes.simple(true)); + SimpleParticleType CHORUS_PETAL = create("chorus_petal", FabricParticleTypes.simple(true)); static void initialize() { PARTICLES.keySet().forEach(particle -> Registry.register(Registries.PARTICLE_TYPE, PARTICLES.get(particle), particle)); @@ -53,5 +54,6 @@ private static void registerFactories() { ParticleFactoryRegistry.getInstance().register(CASCADE, CascadeParticle.Factory::new); ParticleFactoryRegistry.getInstance().register(GLOW_CASCADE, GlowCascadeParticle.Factory::new); ParticleFactoryRegistry.getInstance().register(MIST, MistParticle.Factory::new); + ParticleFactoryRegistry.getInstance().register(CHORUS_PETAL, ChorusPetalParticle.Factory::new); } } diff --git a/src/client/java/org/ladysnake/effective/core/index/EffectiveSounds.java b/src/client/java/org/ladysnake/effective/core/index/EffectiveSounds.java new file mode 100644 index 0000000..a83427a --- /dev/null +++ b/src/client/java/org/ladysnake/effective/core/index/EffectiveSounds.java @@ -0,0 +1,47 @@ +package org.ladysnake.effective.core.index; + +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.sound.BlockSoundGroup; +import net.minecraft.sound.SoundEvent; +import org.ladysnake.effective.core.Effective; + +import java.util.LinkedList; +import java.util.List; + +public interface EffectiveSounds { + + List SOUND_EVENTS = new LinkedList<>(); + + SoundEvent AMBIENCE_WATERFALL = create("ambience.waterfall"); + SoundEvent PARRY = create("entity.parry"); + + static SoundEvent create(String name) { + SoundEvent soundEvent = SoundEvent.of(Effective.id(name)); + SOUND_EVENTS.add(soundEvent); + return soundEvent; + } + + static BlockSoundGroup createBlockSoundGroup(String name, float volume, float pitch) { + return new BlockSoundGroup(volume, pitch, + create("block." + name + ".break"), + create("block." + name + ".step"), + create("block." + name + ".place"), + create("block." + name + ".hit"), + create("block." + name + ".fall")); + } + + static BlockSoundGroup copyBlockSoundGroup(BlockSoundGroup blockSoundGroup, float volume, float pitch) { + return new BlockSoundGroup(volume, pitch, + blockSoundGroup.getBreakSound(), + blockSoundGroup.getStepSound(), + blockSoundGroup.getPlaceSound(), + blockSoundGroup.getHitSound(), + blockSoundGroup.getFallSound()); + } + + static void initialize() { + SOUND_EVENTS.forEach(soundEvent -> Registry.register(Registries.SOUND_EVENT, soundEvent.getId(), soundEvent)); + } + +} diff --git a/src/client/java/org/ladysnake/effective/core/mixin/choruspetals/BrokenChorusFlowerPetalSpawner.java b/src/client/java/org/ladysnake/effective/core/mixin/choruspetals/BrokenChorusFlowerPetalSpawner.java index 2d31f1e..1545e6a 100644 --- a/src/client/java/org/ladysnake/effective/core/mixin/choruspetals/BrokenChorusFlowerPetalSpawner.java +++ b/src/client/java/org/ladysnake/effective/core/mixin/choruspetals/BrokenChorusFlowerPetalSpawner.java @@ -11,6 +11,7 @@ import net.minecraft.util.math.random.Random; import org.ladysnake.effective.core.Effective; import org.ladysnake.effective.core.EffectiveConfig; +import org.ladysnake.effective.core.index.EffectiveParticles; import org.ladysnake.effective.core.utils.EffectiveUtils; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -34,7 +35,7 @@ public abstract class BrokenChorusFlowerPetalSpawner { public void addBlockBreakParticles(BlockPos pos, BlockState state, CallbackInfo ci) { if (state.getBlock() == Blocks.CHORUS_FLOWER) { for (int i = 0; i < (6 - state.get(ChorusFlowerBlock.AGE)) * (EffectiveConfig.chorusPetalDensity * 10f); i++) { - this.addParticle(Effective.CHORUS_PETAL, (double) pos.getX() + 0.5, (double) pos.getY() + 0.5, (double) pos.getZ() + 0.5, EffectiveUtils.getRandomFloatOrNegative(this.random) / 10f, EffectiveUtils.getRandomFloatOrNegative(this.random) / 10f, EffectiveUtils.getRandomFloatOrNegative(this.random) / 10f); + this.addParticle(EffectiveParticles.CHORUS_PETAL, (double) pos.getX() + 0.5, (double) pos.getY() + 0.5, (double) pos.getZ() + 0.5, EffectiveUtils.getRandomFloatOrNegative(this.random) / 10f, EffectiveUtils.getRandomFloatOrNegative(this.random) / 10f, EffectiveUtils.getRandomFloatOrNegative(this.random) / 10f); } } } diff --git a/src/client/java/org/ladysnake/effective/core/mixin/choruspetals/ChorusPetalSpawner.java b/src/client/java/org/ladysnake/effective/core/mixin/choruspetals/ChorusPetalSpawner.java index d6b4390..8ced5fc 100644 --- a/src/client/java/org/ladysnake/effective/core/mixin/choruspetals/ChorusPetalSpawner.java +++ b/src/client/java/org/ladysnake/effective/core/mixin/choruspetals/ChorusPetalSpawner.java @@ -7,6 +7,7 @@ import net.minecraft.world.World; import org.ladysnake.effective.core.Effective; import org.ladysnake.effective.core.EffectiveConfig; +import org.ladysnake.effective.core.index.EffectiveParticles; import org.ladysnake.effective.core.mixin.BlockMixin; import org.ladysnake.effective.core.utils.EffectiveUtils; import org.spongepowered.asm.mixin.Mixin; @@ -17,7 +18,7 @@ public abstract class ChorusPetalSpawner extends BlockMixin { @Override protected void effective$randomDisplayTick(BlockState state, World world, BlockPos pos, Random random, CallbackInfo ci) { for (int i = 0; i < (6 - state.get(ChorusFlowerBlock.AGE)) * EffectiveConfig.chorusPetalDensity; i++) { - world.addParticle(Effective.CHORUS_PETAL, true, pos.getX() + 0.5 + EffectiveUtils.getRandomFloatOrNegative(random) * 5, pos.getY() + 0.5 + EffectiveUtils.getRandomFloatOrNegative(random) * 5, pos.getZ() + 0.5 + EffectiveUtils.getRandomFloatOrNegative(random) * 5, 0f, 0f, 0f); + world.addParticle(EffectiveParticles.CHORUS_PETAL, true, pos.getX() + 0.5 + EffectiveUtils.getRandomFloatOrNegative(random) * 5, pos.getY() + 0.5 + EffectiveUtils.getRandomFloatOrNegative(random) * 5, pos.getZ() + 0.5 + EffectiveUtils.getRandomFloatOrNegative(random) * 5, 0f, 0f, 0f); } } } diff --git a/src/client/java/org/ladysnake/effective/core/mixin/feedbacking/FeedbackingParryFireballEffect.java b/src/client/java/org/ladysnake/effective/core/mixin/feedbacking/FeedbackingParryFireballEffect.java index c1f2cf2..97a8322 100644 --- a/src/client/java/org/ladysnake/effective/core/mixin/feedbacking/FeedbackingParryFireballEffect.java +++ b/src/client/java/org/ladysnake/effective/core/mixin/feedbacking/FeedbackingParryFireballEffect.java @@ -6,6 +6,7 @@ import net.minecraft.entity.projectile.ExplosiveProjectileEntity; import org.ladysnake.effective.core.Effective; import org.ladysnake.effective.core.EffectiveConfig; +import org.ladysnake.effective.core.index.EffectiveSounds; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -20,7 +21,7 @@ public abstract class FeedbackingParryFireballEffect { @Inject(method = "attack", at = @At("HEAD")) public void attack(Entity target, CallbackInfo ci) { if (EffectiveConfig.ultrakill && this.isMainPlayer() && target instanceof ExplosiveProjectileEntity) { - MinecraftClient.getInstance().player.playSound(Effective.PARRY); + MinecraftClient.getInstance().player.playSound(EffectiveSounds.PARRY); Effective.freezeFrames = 5; } diff --git a/src/client/java/org/ladysnake/effective/core/world/WaterfallCloudGenerators.java b/src/client/java/org/ladysnake/effective/core/world/WaterfallCloudGenerators.java index 3a21768..a5d0360 100644 --- a/src/client/java/org/ladysnake/effective/core/world/WaterfallCloudGenerators.java +++ b/src/client/java/org/ladysnake/effective/core/world/WaterfallCloudGenerators.java @@ -18,6 +18,7 @@ import org.ladysnake.effective.core.Effective; import org.ladysnake.effective.core.EffectiveConfig; import org.ladysnake.effective.core.index.EffectiveParticles; +import org.ladysnake.effective.core.index.EffectiveSounds; import org.ladysnake.effective.core.sound.WaterfallSoundInstance; import org.ladysnake.effective.core.utils.EffectiveUtils; @@ -70,7 +71,7 @@ public static void tick() { } if (EffectiveUtils.isInCave(world, waterfall.blockPos()) == EffectiveUtils.isInCave(world, client.player.getBlockPos()) && world.random.nextInt(200) == 0) { // make it so cascades underground can only be heard by players underground, and surface cascades can only be heard by players on the surface - client.getSoundManager().play(WaterfallSoundInstance.ambient(Effective.AMBIENCE_WATERFALL, 1.2f + world.random.nextFloat() / 10f, waterfall.blockPos(), EffectiveConfig.cascadeSoundDistanceBlocks), (int) (distance / 2)); + client.getSoundManager().play(WaterfallSoundInstance.ambient(EffectiveSounds.AMBIENCE_WATERFALL, 1.2f + world.random.nextFloat() / 10f, waterfall.blockPos(), EffectiveConfig.cascadeSoundDistanceBlocks), (int) (distance / 2)); } }); generators.removeIf(waterfall -> waterfall == null || getWaterfallAt(world, waterfall.blockPos(), world.getFluidState(waterfall.blockPos())).strength() <= 0);