Fix sparkle particles with the same workaround

This commit is contained in:
Vincent Lee committed 2020-01-16 16:01:48 -06:00
1 parent 596f753c9f
commit 0885a5d9d8
9 files changed
+47 -55

No files matched your search

@@ -14,11 +14,16 @@ import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.IAnimatedSprite;
import net.minecraft.client.particle.IParticleRenderType;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.SpriteTexturedParticle;
import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.client.renderer.texture.Texture;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.Direction;
@@ -33,30 +38,28 @@ import vazkii.botania.common.core.handler.ConfigHandler;
import javax.annotation.Nonnull;
public class FXSparkle extends Particle {
public class FXSparkle extends SpriteTexturedParticle {
private static boolean lastBlur;
private static boolean lastMipmap;
private static final ResourceLocation vanillaParticles = new ResourceLocation("textures/particle/particles.png");
public static final ResourceLocation particles = new ResourceLocation(LibResources.MISC_PARTICLES);
protected float particleScale = (this.rand.nextFloat() * 0.5F + 0.5F) * 2.0F;
private final boolean corrupt;
public final boolean fake;
private final int multiplier;
public final int particle = 16;
private final boolean slowdown = true;
private final IAnimatedSprite sprite;
public FXSparkle(World world, double x, double y, double z, float size,
float red, float green, float blue, int m,
boolean fake, boolean noClip, boolean corrupt) {
float red, float green, float blue, int m,
boolean fake, boolean noClip, boolean corrupt, IAnimatedSprite sprite) {
super(world, x, y, z, 0.0D, 0.0D, 0.0D);
particleRed = red;
particleGreen = green;
particleBlue = blue;
particleAlpha = 0.75F;
particleGravity = 0;
motionX = motionY = motionZ = 0;
particleScale *= size;
particleScale = (this.rand.nextFloat() * 0.5F + 0.5F) * 0.2F * size;
maxAge = 3 * m;
multiplier = m;
setSize(0.01F, 0.01F);
prevPosX = posX;
prevPosY = posY;
@@ -64,38 +67,18 @@ public class FXSparkle extends Particle {
this.fake = fake;
this.corrupt = corrupt;
this.canCollide = !fake && !noClip;
}
public void setCanCollide(boolean canCollide) {
this.canCollide = canCollide;
this.sprite = sprite;
selectSpriteWithAge(sprite);
}
@Override
public void buildGeometry(IVertexBuilder buffer, ActiveRenderInfo info, float partialTicks) {
/* todo 1.15 redo this in a modern way (using TexturedParticle)
int part = particle + age/multiplier;
float var8 = part % 8 / 8.0F;
float var9 = var8 + 0.0624375F*2;
float var10 = part / 8 / 8.0F;
float var11 = var10 + 0.0624375F*2;
float var12 = 0.1F * particleScale;
boolean shrink = true;
if (shrink) var12 *= (maxAge-age+1)/(float)maxAge;
float var13 = (float)(prevPosX + (posX - prevPosX) * partialTicks - interpPosX);
float var14 = (float)(prevPosY + (posY - prevPosY) * partialTicks - interpPosY);
float var15 = (float)(prevPosZ + (posZ - prevPosZ) * partialTicks - interpPosZ);
float var16 = 1.0F;
buffer.pos(var13 - rotationX * var12 - rotationXY * var12, var14 - rotationZ * var12, var15 - rotationYZ * var12 - rotationXZ * var12).tex(var9, var11).color(particleRed * var16, particleGreen * var16, particleBlue * var16, 1).endVertex();
buffer.pos(var13 - rotationX * var12 + rotationXY * var12, var14 + rotationZ * var12, var15 - rotationYZ * var12 + rotationXZ * var12).tex(var9, var10).color(particleRed * var16, particleGreen * var16, particleBlue * var16, 1).endVertex();
buffer.pos(var13 + rotationX * var12 + rotationXY * var12, var14 + rotationZ * var12, var15 + rotationYZ * var12 + rotationXZ * var12).tex(var8, var10).color(particleRed * var16, particleGreen * var16, particleBlue * var16, 1).endVertex();
buffer.pos(var13 + rotationX * var12 - rotationXY * var12, var14 - rotationZ * var12, var15 + rotationYZ * var12 - rotationXZ * var12).tex(var8, var11).color(particleRed * var16, particleGreen * var16, particleBlue * var16, 1).endVertex();
*/
public float getScale(float partialTicks) {
return particleScale * (maxAge-age+1) / (float)maxAge;
}
@Override
public void tick() {
selectSpriteWithAge(sprite);
prevPosX = posX;
prevPosY = posY;
prevPosZ = posZ;
@@ -183,12 +166,20 @@ public class FXSparkle extends Particle {
RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
RenderSystem.alphaFunc(GL11.GL_GREATER, 0.003921569F);
RenderSystem.disableLighting();
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 0.75F);
textureManager.bindTexture(ConfigHandler.CLIENT.matrixMode.get() ? vanillaParticles : particles);
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
textureManager.bindTexture(AtlasTexture.LOCATION_PARTICLES_TEXTURE);
// todo 1.15 see same spot in FXWisp
try {
Texture tex = textureManager.getTexture(AtlasTexture.LOCATION_PARTICLES_TEXTURE);
lastBlur = FXWisp.BLUR.getBoolean(tex);
lastMipmap = FXWisp.MIPMAP.getBoolean(tex);
tex.setBlurMipmapDirect(true, false);
} catch (IllegalAccessException ignored) {
}
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP);
}
private static void endRenderCommon() {
Minecraft.getInstance().textureManager.getTexture(AtlasTexture.LOCATION_PARTICLES_TEXTURE).setBlurMipmapDirect(lastBlur, lastMipmap);
RenderSystem.alphaFunc(GL11.GL_GREATER, 0.1F);
RenderSystem.disableBlend();
RenderSystem.depthMask(true);
@@ -35,8 +35,8 @@ import javax.annotation.Nonnull;
import java.lang.reflect.Field;
public class FXWisp extends SpriteTexturedParticle {
private static final Field BLUR = ObfuscationReflectionHelper.findField(Texture.class, "field_174940_b");
private static final Field MIPMAP = ObfuscationReflectionHelper.findField(Texture.class, "field_174941_c");
public static final Field BLUR = ObfuscationReflectionHelper.findField(Texture.class, "field_174940_b");
public static final Field MIPMAP = ObfuscationReflectionHelper.findField(Texture.class, "field_174941_c");
private static boolean lastBlur;
private static boolean lastMipmap;
@@ -54,7 +54,7 @@ public class FXWisp extends SpriteTexturedParticle {
particleRed = red;
particleGreen = green;
particleBlue = blue;
particleAlpha = 0.5F;
particleAlpha = 0.375F;
particleGravity = 0;
particleScale = (this.rand.nextFloat() * 0.5F + 0.5F) * 2.0F * size;
moteParticleScale = particleScale;
@@ -121,7 +121,6 @@ public class FXWisp extends SpriteTexturedParticle {
RenderSystem.alphaFunc(GL11.GL_GREATER, 0.003921569F);
RenderSystem.disableLighting();
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 0.75F);
textureManager.bindTexture(AtlasTexture.LOCATION_PARTICLES_TEXTURE);
// todo 1.15 method to save last blur mipmap not present, remove workaround when MinecraftForge#6450 merged
try {
@@ -31,7 +31,7 @@ public class ModParticles {
@SubscribeEvent
public static void registerFactories(ParticleFactoryRegisterEvent evt) {
Minecraft.getInstance().particles.registerFactory(ModParticles.WISP, WispParticleType.Factory::new);
Minecraft.getInstance().particles.registerFactory(ModParticles.SPARKLE, new SparkleParticleType.Factory());
Minecraft.getInstance().particles.registerFactory(ModParticles.SPARKLE, SparkleParticleType.Factory::new);
}
}
}
@@ -1,5 +1,6 @@
package vazkii.botania.client.fx;
import net.minecraft.client.particle.IAnimatedSprite;
import net.minecraft.client.particle.IParticleFactory;
import net.minecraft.client.particle.Particle;
import net.minecraft.particles.ParticleType;
@@ -11,9 +12,15 @@ public class SparkleParticleType extends ParticleType<SparkleParticleData> {
}
public static class Factory implements IParticleFactory<SparkleParticleData> {
private final IAnimatedSprite sprite;
public Factory(IAnimatedSprite sprite) {
this.sprite = sprite;
}
@Override
public Particle makeParticle(SparkleParticleData data, World world, double x, double y, double z, double mx, double my, double mz) {
return new FXSparkle(world, x, y, z, data.size, data.r, data.g, data.b, data.m, data.fake, data.noClip, data.corrupt);
return new FXSparkle(world, x, y, z, data.size, data.r, data.g, data.b, data.m, data.fake, data.noClip, data.corrupt, sprite);
}
}
}
@@ -124,7 +124,6 @@ public final class LibResources {
public static final String MODEL_AVATAR_TORNADO = PREFIX_MODEL + "avatar_tornado.png";
public static final String MODEL_AVATAR_DIRT = PREFIX_MODEL + "avatar_dirt.png";
public static final String MISC_PARTICLES = PREFIX_MISC + "particles.png";
public static final String MISC_WISP_LARGE = PREFIX_MISC + "wisp_large.png";
public static final String MISC_WISP_SMALL = PREFIX_MISC + "wisp_small.png";
public static final String MISC_HALO = PREFIX_MISC + "halo.png";
@@ -38,7 +38,6 @@ public final class ConfigHandler {
public final ForgeConfigSpec.BooleanValue staticFloaters;
public final ForgeConfigSpec.BooleanValue debugInfo;
public final ForgeConfigSpec.BooleanValue matrixMode;
public final ForgeConfigSpec.BooleanValue referencesEnabled;
public Client(ForgeConfigSpec.Builder builder) {
@@ -102,9 +101,6 @@ public final class ConfigHandler {
debugInfo = builder
.comment("Set to false to disable Botania's messages in the F3 debug screen")
.define("debug_info", true);
matrixMode = builder
.comment("Set this to true if you are the chosen one. For lovers of glitch art and just general mad people.")
.define("matrix_mode", false);
referencesEnabled = builder
.comment("Set this to false to disable the references in the flower tooltips. (You monster D:)")
.define("references", true);