Skip to content

Commit

Permalink
Clean up sound effect registration code
Browse files Browse the repository at this point in the history
  • Loading branch information
doctor4t committed Jan 3, 2025
1 parent d014246 commit b209a9b
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 18 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 1 addition & 14 deletions src/client/java/org/ladysnake/effective/core/Effective.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<SoundEvent> 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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b209a9b

Please sign in to comment.