2018-10-13 20:35:18 +02:00
|
|
|
package de.ellpeck.naturesaura.particles;
|
|
|
|
|
2020-01-28 18:08:56 +01:00
|
|
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
2020-01-21 23:02:39 +01:00
|
|
|
import com.mojang.blaze3d.platform.GlStateManager;
|
2020-01-28 18:08:56 +01:00
|
|
|
import com.mojang.blaze3d.systems.RenderSystem;
|
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;
|
2020-01-21 23:02:39 +01:00
|
|
|
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
2018-10-13 20:35:18 +02:00
|
|
|
import net.minecraft.client.particle.Particle;
|
|
|
|
import net.minecraft.client.renderer.ActiveRenderInfo;
|
|
|
|
import net.minecraft.client.renderer.BufferBuilder;
|
2020-01-29 18:18:41 +01:00
|
|
|
import net.minecraft.client.renderer.LightTexture;
|
2018-10-13 20:35:18 +02:00
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
|
|
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
2020-01-24 17:05:41 +01:00
|
|
|
import net.minecraft.client.settings.ParticleStatus;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2018-10-13 20:35:18 +02:00
|
|
|
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
|
|
|
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2018-10-13 20:35:18 +02:00
|
|
|
public final class ParticleHandler {
|
|
|
|
|
|
|
|
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<>();
|
2020-02-07 15:22:30 +01:00
|
|
|
public static boolean depthEnabled = true;
|
|
|
|
public static int range = 32;
|
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) {
|
2019-11-04 19:08:49 +01:00
|
|
|
if (Minecraft.getInstance().player.getDistanceSq(x, y, z) <= range * range) {
|
|
|
|
Minecraft mc = Minecraft.getInstance();
|
2020-01-24 17:05:41 +01:00
|
|
|
if (ModConfig.instance.respectVanillaParticleSettings.get()) {
|
|
|
|
ParticleStatus setting = mc.gameSettings.particles;
|
|
|
|
if (setting != ParticleStatus.ALL &&
|
|
|
|
(setting != ParticleStatus.DECREASED || mc.world.rand.nextInt(3) != 0) &&
|
|
|
|
(setting != ParticleStatus.MINIMAL || mc.world.rand.nextInt(10) != 0))
|
2018-10-22 20:18:54 +02:00
|
|
|
return;
|
2018-10-14 17:46:00 +02:00
|
|
|
}
|
2020-01-24 17:05:41 +01:00
|
|
|
double setting = ModConfig.instance.particleAmount.get();
|
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);
|
2019-11-04 19:08:49 +01:00
|
|
|
particle.tick();
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-28 18:08:56 +01:00
|
|
|
public static void renderParticles(MatrixStack stack, float partialTicks) {
|
2019-11-04 19:08:49 +01:00
|
|
|
Minecraft mc = Minecraft.getInstance();
|
2020-01-21 23:02:39 +01:00
|
|
|
ClientPlayerEntity player = mc.player;
|
2018-10-13 20:35:18 +02:00
|
|
|
|
|
|
|
if (player != null) {
|
2020-01-21 23:02:39 +01:00
|
|
|
ActiveRenderInfo info = mc.gameRenderer.getActiveRenderInfo();
|
2020-01-29 18:18:41 +01:00
|
|
|
LightTexture lightmap = mc.gameRenderer.getLightTexture();
|
2018-10-13 20:35:18 +02:00
|
|
|
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.pushMatrix();
|
|
|
|
RenderSystem.multMatrix(stack.getLast().getPositionMatrix());
|
2020-01-29 18:18:41 +01:00
|
|
|
lightmap.enableLightmap();
|
2018-10-13 20:35:18 +02:00
|
|
|
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.enableAlphaTest();
|
2020-01-29 18:18:41 +01:00
|
|
|
RenderSystem.enableBlend();
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.alphaFunc(516, 0.003921569F);
|
2020-01-29 18:18:41 +01:00
|
|
|
RenderSystem.disableCull();
|
2020-01-29 14:32:32 +01:00
|
|
|
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE);
|
2020-01-29 18:18:41 +01:00
|
|
|
RenderSystem.enableFog();
|
|
|
|
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
2018-10-13 20:35:18 +02:00
|
|
|
|
2020-01-29 18:18:41 +01:00
|
|
|
RenderSystem.depthMask(false);
|
2018-10-13 20:35:18 +02:00
|
|
|
|
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();
|
|
|
|
|
2020-01-29 14:32:32 +01:00
|
|
|
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP);
|
2019-01-30 15:29:14 +01:00
|
|
|
for (Particle particle : PARTICLES)
|
2020-01-28 18:08:56 +01:00
|
|
|
particle.renderParticle(buffer, info, partialTicks);
|
2019-02-19 17:23:03 +01:00
|
|
|
tessy.draw();
|
2018-10-13 20:35:18 +02:00
|
|
|
|
2020-01-29 18:18:41 +01:00
|
|
|
RenderSystem.disableDepthTest();
|
2020-01-29 14:32:32 +01:00
|
|
|
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP);
|
2019-02-19 17:23:03 +01:00
|
|
|
for (Particle particle : PARTICLES_NO_DEPTH)
|
2020-01-28 18:08:56 +01:00
|
|
|
particle.renderParticle(buffer, info, partialTicks);
|
2018-10-13 20:35:18 +02:00
|
|
|
tessy.draw();
|
2020-01-29 18:18:41 +01:00
|
|
|
RenderSystem.enableDepthTest();
|
2018-10-13 20:35:18 +02:00
|
|
|
|
2020-01-29 18:18:41 +01:00
|
|
|
RenderSystem.enableCull();
|
|
|
|
RenderSystem.depthMask(true);
|
2020-01-29 14:32:32 +01:00
|
|
|
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
|
2020-01-29 18:18:41 +01:00
|
|
|
RenderSystem.disableBlend();
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.alphaFunc(516, 0.1F);
|
2020-01-29 18:18:41 +01:00
|
|
|
RenderSystem.disableFog();
|
2018-10-13 20:35:18 +02:00
|
|
|
|
2020-01-29 18:18:41 +01:00
|
|
|
lightmap.disableLightmap();
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.popMatrix();
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|