Skip to content

Commit

Permalink
Cleanup particle registration code
Browse files Browse the repository at this point in the history
  • Loading branch information
doctor4t committed Dec 29, 2024
1 parent cbea500 commit d5fe512
Show file tree
Hide file tree
Showing 15 changed files with 289 additions and 150 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Every effect is customisable and can be toggled in the configuration.

## Current features:
### Water effects:
- Splashes, droplets and ripples when entities fall in water
x Splashes, droplets and ripples when entities fall in water
- Waterfall clouds
- Appears when water flows into two block deep water source blocks / a water source above a wool block (to make it silent)
- Can also be used on beaches to simulate waves crashing
Expand Down
57 changes: 22 additions & 35 deletions src/client/java/org/ladysnake/effective/core/Effective.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.ladysnake.effective.core.gui.ParryScreen;
import org.ladysnake.effective.core.index.EffectiveParticles;
import org.ladysnake.effective.core.particle.*;
import org.ladysnake.effective.core.particle.types.SplashParticleType;
import org.ladysnake.effective.core.render.entity.model.SplashBottomModel;
import org.ladysnake.effective.core.render.entity.model.SplashBottomRimModel;
import org.ladysnake.effective.core.render.entity.model.SplashModel;
Expand All @@ -37,6 +37,7 @@

public class Effective implements ClientModInitializer {
public static final String MODID = "effective";

// rainbow shader for jeb glow squid
public static final ManagedCoreShader RAINBOW_SHADER = ShaderEffectManager.getInstance().manageCoreShader(Effective.id("jeb"));
private static final Uniform1f uniformSTimeJeb = RAINBOW_SHADER.findUniform1f("Time");
Expand All @@ -47,28 +48,24 @@ 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");

// freeze frames for feedbacking
public static int freezeFrames = -1;

// particle types
public static SplashParticleType SPLASH;
public static SimpleParticleType DROPLET;
public static SimpleParticleType RIPPLE;
public static SplashParticleType GLOW_SPLASH;
public static SimpleParticleType GLOW_DROPLET;
public static SimpleParticleType GLOW_RIPPLE;
// public static AllayTwinkleParticleType ALLAY_TWINKLE;
public static SimpleParticleType CHORUS_PETAL;
public static SimpleParticleType BUBBLE;
public static SimpleParticleType WATERFALL_CLOUD;
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
// public static LodestoneWorldParticleType PIXEL = new LodestoneWorldParticleType();
// public static LodestoneWorldParticleType WISP = new LodestoneWorldParticleType();
// public static FlameParticleType FLAME = new FlameParticleType();
// public static FlameParticleType DRAGON_BREATH = new FlameParticleType();
// public static BubbleParticleType BUBBLE = new BubbleParticleType();
// public static WaterfallCloudParticleType WATERFALL_CLOUD = new WaterfallCloudParticleType();
// public static MistParticleType MIST = new MistParticleType();
// public static FireflyParticleType FIREFLY = new FireflyParticleType();
// sound events
public static SoundEvent AMBIENCE_WATERFALL = SoundEvent.of(Effective.id("ambience.waterfall"));
Expand Down Expand Up @@ -97,30 +94,24 @@ public static Identifier id(String string) {

@Override
public void onInitializeClient() {
// load config
// Load config
EffectiveConfig.init(MODID, EffectiveConfig.class);

// register model layers
// Register splash model layers
EntityModelLayerRegistry.registerModelLayer(SplashModel.MODEL_LAYER, SplashModel::getTexturedModelData);
EntityModelLayerRegistry.registerModelLayer(SplashBottomModel.MODEL_LAYER, SplashBottomModel::getTexturedModelData);
EntityModelLayerRegistry.registerModelLayer(SplashRimModel.MODEL_LAYER, SplashRimModel::getTexturedModelData);
EntityModelLayerRegistry.registerModelLayer(SplashBottomRimModel.MODEL_LAYER, SplashBottomRimModel::getTexturedModelData);

// particles
SPLASH = Registry.register(Registries.PARTICLE_TYPE, Effective.id("splash"), new SplashParticleType(true));
ParticleFactoryRegistry.getInstance().register(SPLASH, SplashParticle.Factory::new);
DROPLET = Registry.register(Registries.PARTICLE_TYPE, Effective.id("droplet"), FabricParticleTypes.simple(true));
ParticleFactoryRegistry.getInstance().register(DROPLET, DropletParticle.Factory::new);
RIPPLE = Registry.register(Registries.PARTICLE_TYPE, Effective.id("ripple"), FabricParticleTypes.simple(true));
ParticleFactoryRegistry.getInstance().register(RIPPLE, RippleParticle.Factory::new);
GLOW_SPLASH = Registry.register(Registries.PARTICLE_TYPE, Effective.id("glow_splash"), new SplashParticleType(true));
ParticleFactoryRegistry.getInstance().register(GLOW_SPLASH, GlowSplashParticle.Factory::new);
GLOW_DROPLET = Registry.register(Registries.PARTICLE_TYPE, Effective.id("glow_droplet"), FabricParticleTypes.simple(true));
ParticleFactoryRegistry.getInstance().register(GLOW_DROPLET, GlowDropletParticle.Factory::new);
GLOW_RIPPLE = Registry.register(Registries.PARTICLE_TYPE, Effective.id("glow_ripple"), FabricParticleTypes.simple(true));
ParticleFactoryRegistry.getInstance().register(GLOW_RIPPLE, GlowRippleParticle.Factory::new);
// ALLAY_TWINKLE = Registry.register(Registries.PARTICLE_TYPE, Effective.id("allay_twinkle"), new AllayTwinkleParticleType());
// ParticleFactoryRegistry.getInstance().register(ALLAY_TWINKLE, AllayTwinkleParticleType.Factory::new);
// Initialize particles
EffectiveParticles.initialize();

// Particles
// WATERFALL_CLOUD = Registry.register(Registries.PARTICLE_TYPE, Effective.id("waterfall_cloud"), WATERFALL_CLOUD);
// ParticleFactoryRegistry.getInstance().register(WATERFALL_CLOUD, WaterfallCloudParticle.Factory::new);
// MIST = Registry.register(Registries.PARTICLE_TYPE, Effective.id("mist"), MIST);
// ParticleFactoryRegistry.getInstance().register(MIST, MistParticleType.Factory::new);

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));
Expand All @@ -129,6 +120,8 @@ public void onInitializeClient() {
ParticleFactoryRegistry.getInstance().register(WILL_O_WISP, fabricSpriteProvider -> new WillOWispParticle.Factory(fabricSpriteProvider, Effective.id("textures/entity/will_o_wisp.png"), 0.1f, 0.75f, 1.0f, 0.0f, 0.1f, 1.0f));

// lodestone particles
// ALLAY_TWINKLE = Registry.register(Registries.PARTICLE_TYPE, Effective.id("allay_twinkle"), new AllayTwinkleParticleType());
// ParticleFactoryRegistry.getInstance().register(ALLAY_TWINKLE, AllayTwinkleParticleType.Factory::new);
// ParticleFactoryRegistry.getInstance().register(PIXEL, LodestoneWorldParticleType.Factory::new);
// PIXEL = Registry.register(Registries.PARTICLE_TYPE, Effective.id("pixel"), PIXEL);
// ParticleFactoryRegistry.getInstance().register(WISP, LodestoneWorldParticleType.Factory::new);
Expand All @@ -137,12 +130,6 @@ public void onInitializeClient() {
// FLAME = Registry.register(Registries.PARTICLE_TYPE, Effective.id("flame"), FLAME);
// ParticleFactoryRegistry.getInstance().register(DRAGON_BREATH, FlameParticleType.Factory::new);
// DRAGON_BREATH = Registry.register(Registries.PARTICLE_TYPE, Effective.id("dragon_breath"), DRAGON_BREATH);
// ParticleFactoryRegistry.getInstance().register(BUBBLE, BubbleParticleType.Factory::new);
// BUBBLE = Registry.register(Registries.PARTICLE_TYPE, Effective.id("bubble"), BUBBLE);
// ParticleFactoryRegistry.getInstance().register(WATERFALL_CLOUD, WaterfallCloudParticleType.Factory::new);
// WATERFALL_CLOUD = Registry.register(Registries.PARTICLE_TYPE, Effective.id("waterfall_cloud"), WATERFALL_CLOUD);
// ParticleFactoryRegistry.getInstance().register(MIST, MistParticleType.Factory::new);
// MIST = Registry.register(Registries.PARTICLE_TYPE, Effective.id("mist"), MIST);
// ParticleFactoryRegistry.getInstance().register(FIREFLY, FireflyParticleType.Factory::new);
// FIREFLY = Registry.register(Registries.PARTICLE_TYPE, Effective.id("firefly"), FIREFLY);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.ladysnake.effective.core.index;

import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes;
import net.minecraft.particle.ParticleType;
import net.minecraft.particle.SimpleParticleType;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import org.ladysnake.effective.core.Effective;
import org.ladysnake.effective.core.particle.*;
import org.ladysnake.effective.core.particle.types.SplashParticleType;

import java.util.LinkedHashMap;
import java.util.Map;

public interface EffectiveParticles {

Map<ParticleType<?>, Identifier> PARTICLES = new LinkedHashMap<>();

SplashParticleType SPLASH = create("splash", new SplashParticleType(true));
SplashParticleType GLOW_SPLASH = create("glow_splash", new SplashParticleType(true));
SimpleParticleType DROPLET = create("droplet", FabricParticleTypes.simple(true));
SimpleParticleType GLOW_DROPLET = create("glow_droplet", FabricParticleTypes.simple(true));
SimpleParticleType RIPPLE = create("ripple", FabricParticleTypes.simple(true));
SimpleParticleType GLOW_RIPPLE = create("glow_ripple", FabricParticleTypes.simple(true));
SimpleParticleType BUBBLE = create("bubble", FabricParticleTypes.simple(true));
SimpleParticleType END_BUBBLE = create("end_bubble", FabricParticleTypes.simple(true));

static void initialize() {
PARTICLES.keySet().forEach(particle -> Registry.register(Registries.PARTICLE_TYPE, PARTICLES.get(particle), particle));

registerFactories();
}

private static <T extends ParticleType<?>> T create(String name, T particle) {
PARTICLES.put(particle, Effective.id(name));
return particle;
}

private static void registerFactories() {
ParticleFactoryRegistry.getInstance().register(SPLASH, SplashParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(GLOW_SPLASH, GlowSplashParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(DROPLET, DropletParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(GLOW_DROPLET, GlowDropletParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(RIPPLE, RippleParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(GLOW_RIPPLE, GlowRippleParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(BUBBLE, BubbleParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(END_BUBBLE, BubbleParticle.Factory::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.passive.GlowSquidEntity;
import net.minecraft.entity.passive.SquidEntity;
import org.ladysnake.effective.core.world.RenderedHypnotizingEntities;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,52 @@
//package org.ladysnake.effective.core.particle;
//
//import net.fabricmc.fabric.impl.client.particle.FabricSpriteProviderImpl;
//import net.minecraft.client.world.ClientWorld;
//import net.minecraft.util.math.BlockPos;
//import team.lodestar.lodestone.systems.particle.world.FrameSetParticle;
//import team.lodestar.lodestone.systems.particle.world.options.WorldParticleOptions;
//
//public class BubbleParticle extends FrameSetParticle {
// public BubbleParticle(ClientWorld world, WorldParticleOptions data, FabricSpriteProviderImpl spriteSet, double x, double y, double z, double xd, double yd, double zd) {
// super(world, data, spriteSet, x, y, z, xd, yd, zd);
// }
//
// @Override
// public void tick() {
// super.tick();
//
// if (!world.isWater(BlockPos.ofFloored(this.x, this.y, this.z))) {
// this.markDead();
// }
// }
//}
package org.ladysnake.effective.core.particle;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.particle.*;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.particle.SimpleParticleType;
import net.minecraft.util.math.BlockPos;

public class BubbleParticle extends SpriteBillboardParticle {
private final SpriteProvider spriteProvider;

public BubbleParticle(ClientWorld world, double x, double y, double z, double velocityX, double velocityY, double velocityZ, SpriteProvider spriteProvider) {
super(world, x, y, z, velocityX, velocityY, velocityZ);

this.velocityX = velocityX;
this.velocityY = velocityY;
this.velocityZ = velocityZ;

this.spriteProvider = spriteProvider;
this.maxAge = 500;
this.scale = .05f;

this.setSpriteForAge(spriteProvider);
}

public ParticleTextureSheet getType() {
return ParticleTextureSheet.PARTICLE_SHEET_OPAQUE;
}

public void tick() {
super.tick();

if (!world.isWater(BlockPos.ofFloored(this.x, this.y, this.z))) {
this.markDead();
}
}

@Environment(EnvType.CLIENT)
public static class Factory implements ParticleFactory<SimpleParticleType> {
private final SpriteProvider spriteProvider;

public Factory(SpriteProvider spriteProvider) {
this.spriteProvider = spriteProvider;
}

@Override
public Particle createParticle(SimpleParticleType parameters, ClientWorld world, double x, double y, double z, double velocityX, double velocityY, double velocityZ) {
return new BubbleParticle(world, x, y, z, velocityX, velocityY, velocityZ, this.spriteProvider);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import net.minecraft.util.math.Vec3d;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import org.ladysnake.effective.core.Effective;
import org.ladysnake.effective.core.index.EffectiveParticles;

import java.util.Random;

Expand Down Expand Up @@ -134,7 +134,7 @@ public void tick() {
for (int i = 0; i > -10; i--) {
BlockPos pos = BlockPos.ofFloored(this.x, Math.round(this.y) + i, this.z);
if (this.world.getBlockState(pos).getBlock() == Blocks.WATER && this.world.getBlockState(BlockPos.ofFloored(this.x, Math.round(this.y) + i, this.z)).getFluidState().isStill() && this.world.getBlockState(BlockPos.ofFloored(this.x, Math.round(this.y) + i + 1, this.z)).isAir()) {
this.world.addParticle(Effective.RIPPLE, this.x, Math.round(this.y) + i + 0.9f, this.z, 0, 0, 0);
this.world.addParticle(EffectiveParticles.RIPPLE, this.x, Math.round(this.y) + i + 0.9f, this.z, 0, 0, 0);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,22 @@
import net.fabricmc.api.Environment;
import net.minecraft.block.Blocks;
import net.minecraft.client.particle.*;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.particle.SimpleParticleType;
import net.minecraft.util.math.BlockPos;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import org.ladysnake.effective.core.Effective;
import org.ladysnake.effective.core.index.EffectiveParticles;

public class DropletParticle extends SpriteBillboardParticle {
private final SpriteProvider spriteProvider;

public DropletParticle(ClientWorld world, double x, double y, double z, double velocityX, double velocityY, double velocityZ, SpriteProvider spriteProvider) {
super(world, x, y, z, velocityX, velocityY, velocityZ);

this.velocityX = velocityX;
this.velocityY = velocityY;
this.velocityZ = velocityZ;

this.spriteProvider = spriteProvider;
this.maxAge = 500;
this.scale = .05f;

this.setSpriteForAge(spriteProvider);
}

Expand All @@ -50,7 +45,7 @@ public void tick() {
for (int i = 0; i > -10; i--) {
BlockPos pos = BlockPos.ofFloored(this.x, Math.round(this.y) + i, this.z);
if (this.world.getBlockState(pos).getBlock() == Blocks.WATER && this.world.getBlockState(BlockPos.ofFloored(this.x, Math.round(this.y) + i, this.z)).getFluidState().isStill() && this.world.getBlockState(BlockPos.ofFloored(this.x, Math.round(this.y) + i + 1, this.z)).isAir()) {
this.world.addParticle(Effective.RIPPLE, this.x, Math.round(this.y) + i + 0.9f, this.z, 0, 0, 0);
this.world.addParticle(EffectiveParticles.RIPPLE, this.x, Math.round(this.y) + i + 0.9f, this.z, 0, 0, 0);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.ladysnake.effective.core.particle;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.ParticleFactory;
import net.minecraft.client.particle.SpriteProvider;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.particle.SimpleParticleType;

public class EndBubbleParticle extends BubbleParticle {
public EndBubbleParticle(ClientWorld world, double x, double y, double z, double velocityX, double velocityY, double velocityZ, SpriteProvider spriteProvider) {
super(world, x, y, z, velocityX, velocityY, velocityZ, spriteProvider);

this.red = 0;
this.green = 1;
this.blue = 1;
}

@Environment(EnvType.CLIENT)
public static class Factory implements ParticleFactory<SimpleParticleType> {
private final SpriteProvider spriteProvider;

public Factory(SpriteProvider spriteProvider) {
this.spriteProvider = spriteProvider;
}

@Override
public Particle createParticle(SimpleParticleType parameters, ClientWorld world, double x, double y, double z, double velocityX, double velocityY, double velocityZ) {
return new EndBubbleParticle(world, x, y, z, velocityX, velocityY, velocityZ, this.spriteProvider);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@
import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.ParticleFactory;
import net.minecraft.client.particle.SpriteProvider;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.LightmapTextureManager;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.particle.SimpleParticleType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.LightType;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import org.ladysnake.effective.core.Effective;
import org.ladysnake.effective.core.index.EffectiveParticles;

public class GlowDropletParticle extends DropletParticle {
public float redAndGreen = random.nextFloat() / 5f;
Expand Down Expand Up @@ -49,7 +43,7 @@ public void tick() {
for (int i = 0; i > -10; i--) {
BlockPos pos = BlockPos.ofFloored(this.x, Math.round(this.y) + i, this.z);
if (this.world.getBlockState(pos).getBlock() == Blocks.WATER && this.world.getBlockState(BlockPos.ofFloored(this.x, Math.round(this.y) + i, this.z)).getFluidState().isStill() && this.world.getBlockState(BlockPos.ofFloored(this.x, Math.round(this.y) + i + 1, this.z)).isAir()) {
this.world.addParticle(Effective.GLOW_RIPPLE, this.x, Math.round(this.y) + i + 0.9f, this.z, 0, 0, 0);
this.world.addParticle(EffectiveParticles.GLOW_RIPPLE, this.x, Math.round(this.y) + i + 0.9f, this.z, 0, 0, 0);
break;
}
}
Expand Down
Loading

0 comments on commit d5fe512

Please sign in to comment.