2018-10-13 20:35:18 +02:00
|
|
|
package de.ellpeck.naturesaura.particles;
|
|
|
|
|
2018-10-22 20:18:54 +02:00
|
|
|
import de.ellpeck.naturesaura.ModConfig;
|
2018-10-13 20:35:18 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.particle.Particle;
|
|
|
|
import net.minecraft.client.renderer.ActiveRenderInfo;
|
|
|
|
import net.minecraft.client.renderer.BufferBuilder;
|
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
|
|
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2018-10-14 17:46:00 +02:00
|
|
|
import java.util.function.Supplier;
|
2018-10-13 20:35:18 +02:00
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public final class ParticleHandler {
|
|
|
|
|
2019-02-19 17:23:03 +01:00
|
|
|
public static boolean depthEnabled = true;
|
|
|
|
public static int range = 32;
|
2018-10-13 20:35:18 +02:00
|
|
|
private static final List<Particle> PARTICLES = new ArrayList<>();
|
2019-02-19 17:23:03 +01:00
|
|
|
private static final List<Particle> PARTICLES_NO_DEPTH = new ArrayList<>();
|
2018-10-13 20:35:18 +02:00
|
|
|
|
2019-02-19 17:23:03 +01:00
|
|
|
public static void spawnParticle(Supplier<Particle> particle, double x, double y, double z) {
|
2018-10-14 17:46:00 +02:00
|
|
|
if (Minecraft.getMinecraft().player.getDistanceSq(x, y, z) <= range * range) {
|
|
|
|
Minecraft mc = Minecraft.getMinecraft();
|
2018-10-22 20:18:54 +02:00
|
|
|
if (ModConfig.client.respectVanillaParticleSettings) {
|
|
|
|
int setting = mc.gameSettings.particleSetting;
|
|
|
|
if (setting != 0 &&
|
|
|
|
(setting != 1 || mc.world.rand.nextInt(3) != 0) &&
|
2019-01-30 15:29:14 +01:00
|
|
|
(setting != 2 || mc.world.rand.nextInt(10) != 0))
|
2018-10-22 20:18:54 +02:00
|
|
|
return;
|
2018-10-14 17:46:00 +02:00
|
|
|
}
|
2018-10-22 20:18:54 +02:00
|
|
|
double setting = ModConfig.client.particleAmount;
|
2019-01-30 15:29:14 +01:00
|
|
|
if (setting < 1 && mc.world.rand.nextDouble() > setting)
|
2018-10-22 20:18:54 +02:00
|
|
|
return;
|
2019-02-19 17:23:03 +01:00
|
|
|
|
|
|
|
if (depthEnabled)
|
|
|
|
PARTICLES.add(particle.get());
|
|
|
|
else
|
|
|
|
PARTICLES_NO_DEPTH.add(particle.get());
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void updateParticles() {
|
2019-02-19 17:23:03 +01:00
|
|
|
updateList(PARTICLES);
|
|
|
|
updateList(PARTICLES_NO_DEPTH);
|
2019-03-17 22:51:45 +01:00
|
|
|
|
|
|
|
depthEnabled = true;
|
|
|
|
range = 32;
|
2019-02-19 17:23:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void updateList(List<Particle> particles) {
|
|
|
|
for (int i = particles.size() - 1; i >= 0; i--) {
|
|
|
|
Particle particle = particles.get(i);
|
2018-10-13 20:45:32 +02:00
|
|
|
particle.onUpdate();
|
2019-01-30 15:29:14 +01:00
|
|
|
if (!particle.isAlive())
|
2019-02-19 17:23:03 +01:00
|
|
|
particles.remove(i);
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void renderParticles(float partialTicks) {
|
2018-10-13 20:45:32 +02:00
|
|
|
Minecraft mc = Minecraft.getMinecraft();
|
2018-10-13 20:35:18 +02:00
|
|
|
EntityPlayer player = mc.player;
|
|
|
|
|
|
|
|
if (player != null) {
|
|
|
|
float x = ActiveRenderInfo.getRotationX();
|
|
|
|
float z = ActiveRenderInfo.getRotationZ();
|
|
|
|
float yz = ActiveRenderInfo.getRotationYZ();
|
|
|
|
float xy = ActiveRenderInfo.getRotationXY();
|
|
|
|
float xz = ActiveRenderInfo.getRotationXZ();
|
|
|
|
|
|
|
|
Particle.interpPosX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
|
|
|
|
Particle.interpPosY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
|
|
|
|
Particle.interpPosZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
|
|
|
|
Particle.cameraViewDir = player.getLook(partialTicks);
|
|
|
|
|
|
|
|
GlStateManager.pushMatrix();
|
|
|
|
|
2018-10-13 20:45:32 +02:00
|
|
|
GlStateManager.enableAlpha();
|
2018-10-13 20:35:18 +02:00
|
|
|
GlStateManager.enableBlend();
|
|
|
|
GlStateManager.alphaFunc(516, 0.003921569F);
|
|
|
|
GlStateManager.disableCull();
|
2019-02-19 17:23:03 +01:00
|
|
|
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE);
|
2018-10-13 20:35:18 +02:00
|
|
|
|
|
|
|
GlStateManager.depthMask(false);
|
|
|
|
|
2019-01-30 15:29:14 +01:00
|
|
|
mc.getTextureManager().bindTexture(ParticleMagic.TEXTURE);
|
2018-10-13 20:35:18 +02:00
|
|
|
Tessellator tessy = Tessellator.getInstance();
|
|
|
|
BufferBuilder buffer = tessy.getBuffer();
|
|
|
|
|
|
|
|
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP);
|
2019-01-30 15:29:14 +01:00
|
|
|
for (Particle particle : PARTICLES)
|
2018-10-13 20:45:32 +02:00
|
|
|
particle.renderParticle(buffer, player, partialTicks, x, xz, z, yz, xy);
|
2019-02-19 17:23:03 +01:00
|
|
|
tessy.draw();
|
2018-10-13 20:35:18 +02:00
|
|
|
|
2019-02-19 17:23:03 +01:00
|
|
|
GlStateManager.disableDepth();
|
|
|
|
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP);
|
|
|
|
for (Particle particle : PARTICLES_NO_DEPTH)
|
|
|
|
particle.renderParticle(buffer, player, partialTicks, x, xz, z, yz, xy);
|
2018-10-13 20:35:18 +02:00
|
|
|
tessy.draw();
|
2019-02-19 17:23:03 +01:00
|
|
|
GlStateManager.enableDepth();
|
2018-10-13 20:35:18 +02:00
|
|
|
|
|
|
|
GlStateManager.enableCull();
|
|
|
|
GlStateManager.depthMask(true);
|
|
|
|
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
|
|
|
|
GlStateManager.disableBlend();
|
|
|
|
GlStateManager.alphaFunc(516, 0.1F);
|
|
|
|
|
|
|
|
GlStateManager.popMatrix();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-19 17:23:03 +01:00
|
|
|
public static int getParticleAmount(boolean depth) {
|
|
|
|
return depth ? PARTICLES.size() : PARTICLES_NO_DEPTH.size();
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void clearParticles() {
|
2019-02-19 17:23:03 +01:00
|
|
|
if (!PARTICLES.isEmpty())
|
2018-10-13 20:35:18 +02:00
|
|
|
PARTICLES.clear();
|
2019-02-19 17:23:03 +01:00
|
|
|
if (!PARTICLES_NO_DEPTH.isEmpty())
|
|
|
|
PARTICLES_NO_DEPTH.clear();
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
|
|
|
}
|