Skip to content

Commit

Permalink
Fix ripples and cascade particles not using the last sprite in the list
Browse files Browse the repository at this point in the history
  • Loading branch information
doctor4t committed Jan 3, 2025
1 parent 72278c4 commit 591a7d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public ParticleTextureSheet getType() {
public void tick() {
super.tick();

this.setSpriteForAge(this.spriteProvider);

this.prevPosX = this.x;
this.prevPosY = this.y;
this.prevPosZ = this.z;
Expand All @@ -57,6 +55,8 @@ public void tick() {
this.velocityZ *= 0.95f;

this.move(velocityX, velocityY, velocityZ);

this.setSpriteForAge(this.spriteProvider);
}

@Environment(EnvType.CLIENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import net.minecraft.client.world.ClientWorld;
import net.minecraft.particle.SimpleParticleType;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import org.joml.Quaternionf;
import org.joml.Vector3f;

import java.util.Random;

Expand All @@ -20,12 +18,13 @@ public class RippleParticle extends SpriteBillboardParticle {
public RippleParticle(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.spriteProvider = spriteProvider;
this.setSpriteForAge(spriteProvider);

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

this.spriteProvider = spriteProvider;

int scaleAgeModifier = 1 + new Random().nextInt(10);
this.scale *= 2f + random.nextFloat() / 10f * scaleAgeModifier;
this.maxAge = 10 + new Random().nextInt(scaleAgeModifier);
Expand All @@ -44,47 +43,15 @@ public void tick() {
if (this.age++ >= this.maxAge) {
this.markDead();
}

this.setSpriteForAge(spriteProvider);
}

@Override
public void buildGeometry(VertexConsumer vertexConsumer, Camera camera, float tickDelta) {
this.setSpriteForAge(spriteProvider);

Vec3d vec3d = camera.getPos();
float f = (float) (MathHelper.lerp(tickDelta, this.prevPosX, this.x) - vec3d.getX());
float g = (float) (MathHelper.lerp(tickDelta, this.prevPosY, this.y) - vec3d.getY());
float h = (float) (MathHelper.lerp(tickDelta, this.prevPosZ, this.z) - vec3d.getZ());
Quaternionf quaternion2;
if (this.angle == 0.0F) {
quaternion2 = camera.getRotation();
} else {
quaternion2 = new Quaternionf(camera.getRotation());
float i = MathHelper.lerp(tickDelta, this.prevAngle, this.angle);
quaternion2.rotateZ(i);
}

Vector3f vec3f = new Vector3f(-1.0F, -1.0F, 0.0F);
vec3f.rotate(quaternion2);
Vector3f[] Vec3fs = new Vector3f[]{new Vector3f(-1.0F, -1.0F, 0.0F), new Vector3f(-1.0F, 1.0F, 0.0F), new Vector3f(1.0F, 1.0F, 0.0F), new Vector3f(1.0F, -1.0F, 0.0F)};
float j = this.getSize(tickDelta);

for (int k = 0; k < 4; ++k) {
Vector3f Vec3f2 = Vec3fs[k];
Vec3f2.rotate(new Quaternionf().rotateXYZ((float) Math.toRadians(90f), 0f, 0f));
Vec3f2.mul(j);
Vec3f2.add(f, g, h);
}

float minU = this.getMinU();
float maxU = this.getMaxU();
float minV = this.getMinV();
float maxV = this.getMaxV();
int l = this.getBrightness(tickDelta);

vertexConsumer.vertex(Vec3fs[0].x(), Vec3fs[0].y(), Vec3fs[0].z()).texture(maxU, maxV).color(red, green, blue, alpha).light(l);
vertexConsumer.vertex(Vec3fs[1].x(), Vec3fs[1].y(), Vec3fs[1].z()).texture(maxU, minV).color(red, green, blue, alpha).light(l);
vertexConsumer.vertex(Vec3fs[2].x(), Vec3fs[2].y(), Vec3fs[2].z()).texture(minU, minV).color(red, green, blue, alpha).light(l);
vertexConsumer.vertex(Vec3fs[3].x(), Vec3fs[3].y(), Vec3fs[3].z()).texture(minU, maxV).color(red, green, blue, alpha).light(l);
Quaternionf quaternionf = new Quaternionf();
quaternionf.rotateX((float) Math.toRadians(-90f));
this.method_60373(vertexConsumer, camera, quaternionf, tickDelta);
}

@Environment(EnvType.CLIENT)
Expand Down

0 comments on commit 591a7d5

Please sign in to comment.