Fix cube particle rendering

This commit is contained in:
PepperBell 2021-11-07 11:12:00 -08:00
parent ad9a6272c2
commit d82146a541

View file

@ -7,6 +7,7 @@ import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.blaze3d.vertex.VertexFormat; import com.mojang.blaze3d.vertex.VertexFormat;
import com.simibubi.create.AllSpecialTextures;
import net.minecraft.client.Camera; import net.minecraft.client.Camera;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;
@ -40,21 +41,10 @@ public class CubeParticle extends Particle {
// RIGHT // RIGHT
new Vec3(1, -1, 1), new Vec3(1, 1, 1), new Vec3(1, 1, -1), new Vec3(1, -1, -1) }; new Vec3(1, -1, 1), new Vec3(1, 1, 1), new Vec3(1, 1, -1), new Vec3(1, -1, -1) };
public static final Vec3[] CUBE_NORMALS = { private static final ParticleRenderType RENDER_TYPE = new ParticleRenderType() {
// modified normals for the sides
new Vec3(0, 1, 0), new Vec3(0, -1, 0), new Vec3(0, 0, 1), new Vec3(0, 0, 1), new Vec3(0, 0, 1),
new Vec3(0, 0, 1),
/*
* new Vector3d(0, 1, 0), new Vector3d(0, -1, 0), new Vector3d(0, 0, 1), new Vector3d(0, 0,
* -1), new Vector3d(-1, 0, 0), new Vector3d(1, 0, 0)
*/
};
private static final ParticleRenderType renderType = new ParticleRenderType() {
@Override @Override
public void begin(BufferBuilder builder, TextureManager textureManager) { public void begin(BufferBuilder builder, TextureManager textureManager) {
RenderSystem.disableTexture(); AllSpecialTextures.BLANK.bind();
// transparent, additive blending // transparent, additive blending
RenderSystem.depthMask(false); RenderSystem.depthMask(false);
@ -66,7 +56,7 @@ public class CubeParticle extends Particle {
// RenderSystem.disableBlend(); // RenderSystem.disableBlend();
// RenderSystem.enableLighting(); // RenderSystem.enableLighting();
builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.PARTICLE);
} }
@Override @Override
@ -74,7 +64,6 @@ public class CubeParticle extends Particle {
tessellator.end(); tessellator.end();
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA,
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.enableTexture();
} }
}; };
@ -134,7 +123,7 @@ public class CubeParticle extends Particle {
float lerpedZ = (float) (Mth.lerp(p_225606_3_, this.zo, this.z) - projectedView.z()); float lerpedZ = (float) (Mth.lerp(p_225606_3_, this.zo, this.z) - projectedView.z());
// int light = getBrightnessForRender(p_225606_3_); // int light = getBrightnessForRender(p_225606_3_);
int light = LightTexture.FULL_BRIGHT;// 15<<20 && 15<<4 int light = LightTexture.FULL_BRIGHT;
double ageMultiplier = 1 - Math.pow(age, 3) / Math.pow(lifetime, 3); double ageMultiplier = 1 - Math.pow(age, 3) / Math.pow(lifetime, 3);
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
@ -146,12 +135,10 @@ public class CubeParticle extends Particle {
.scale(scale * ageMultiplier) .scale(scale * ageMultiplier)
.add(lerpedX, lerpedY, lerpedZ); .add(lerpedX, lerpedY, lerpedZ);
Vec3 normal = CUBE_NORMALS[i];
builder.vertex(vec.x, vec.y, vec.z) builder.vertex(vec.x, vec.y, vec.z)
.uv(j / 2, j % 2)
.color(rCol, gCol, bCol, alpha) .color(rCol, gCol, bCol, alpha)
.uv(0, 0)
.uv2(light) .uv2(light)
.normal((float) normal.x, (float) normal.y, (float) normal.z)
.endVertex(); .endVertex();
} }
} }
@ -159,13 +146,11 @@ public class CubeParticle extends Particle {
@Override @Override
public ParticleRenderType getRenderType() { public ParticleRenderType getRenderType() {
return renderType; return RENDER_TYPE;
} }
public static class Factory implements ParticleProvider<CubeParticleData> { public static class Factory implements ParticleProvider<CubeParticleData> {
public Factory() {}
@Override @Override
public Particle createParticle(CubeParticleData data, ClientLevel world, double x, double y, double z, double motionX, public Particle createParticle(CubeParticleData data, ClientLevel world, double x, double y, double z, double motionX,
double motionY, double motionZ) { double motionY, double motionZ) {