2018-10-13 20:35:18 +02:00
|
|
|
package de.ellpeck.naturesaura.particles;
|
|
|
|
|
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;
|
2020-12-04 14:15:34 +01:00
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
2018-10-13 20:35:18 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
2020-12-04 14:15:34 +01:00
|
|
|
import net.minecraft.client.particle.IParticleRenderType;
|
2018-10-13 20:35:18 +02:00
|
|
|
import net.minecraft.client.particle.Particle;
|
|
|
|
import net.minecraft.client.renderer.BufferBuilder;
|
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
2020-12-04 14:15:34 +01:00
|
|
|
import net.minecraft.client.renderer.texture.TextureManager;
|
2018-10-13 20:35:18 +02:00
|
|
|
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;
|
|
|
|
|
2020-12-04 14:15:34 +01:00
|
|
|
import java.util.Locale;
|
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 {
|
|
|
|
|
2020-12-04 14:15:34 +01:00
|
|
|
public static final IParticleRenderType MAGIC = new IParticleRenderType() {
|
|
|
|
@Override
|
|
|
|
public void beginRender(BufferBuilder buffer, TextureManager textureManager) {
|
|
|
|
setupRendering(textureManager);
|
|
|
|
RenderSystem.enableDepthTest();
|
|
|
|
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void finishRender(Tessellator tessellator) {
|
|
|
|
tessellator.draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return NaturesAura.MOD_ID.toUpperCase(Locale.ROOT) + "_MAGIC";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
public static final IParticleRenderType MAGIC_NO_DEPTH = new IParticleRenderType() {
|
|
|
|
@Override
|
|
|
|
public void beginRender(BufferBuilder buffer, TextureManager textureManager) {
|
|
|
|
setupRendering(textureManager);
|
|
|
|
RenderSystem.disableDepthTest();
|
|
|
|
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void finishRender(Tessellator tessellator) {
|
|
|
|
tessellator.draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return NaturesAura.MOD_ID.toUpperCase(Locale.ROOT) + "_MAGIC_NO_DEPTH";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-02-07 15:22:30 +01:00
|
|
|
public static boolean depthEnabled = true;
|
|
|
|
public static int range = 32;
|
2020-02-28 15:36:12 +01:00
|
|
|
public static boolean culling = true;
|
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) {
|
2020-12-04 14:15:34 +01:00
|
|
|
Minecraft mc = Minecraft.getInstance();
|
|
|
|
if (mc.player.getDistanceSq(x, y, z) <= range * range) {
|
2020-02-28 15:36:12 +01:00
|
|
|
if (culling) {
|
|
|
|
if (ModConfig.instance.respectVanillaParticleSettings.get()) {
|
|
|
|
ParticleStatus setting = mc.gameSettings.particles;
|
|
|
|
if (setting != ParticleStatus.ALL &&
|
2021-12-04 15:40:09 +01:00
|
|
|
(setting != ParticleStatus.DECREASED || mc.level.rand.nextInt(3) != 0) &&
|
|
|
|
(setting != ParticleStatus.MINIMAL || mc.level.rand.nextInt(10) != 0))
|
2020-02-28 15:36:12 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
double setting = ModConfig.instance.particleAmount.get();
|
2021-12-04 15:40:09 +01:00
|
|
|
if (setting < 1 && mc.level.rand.nextDouble() > setting)
|
2018-10-22 20:18:54 +02:00
|
|
|
return;
|
2018-10-14 17:46:00 +02:00
|
|
|
}
|
2020-12-04 14:15:34 +01:00
|
|
|
mc.particles.addEffect(particle.get());
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-04 14:15:34 +01:00
|
|
|
private static void setupRendering(TextureManager textureManager) {
|
|
|
|
RenderSystem.enableAlphaTest();
|
|
|
|
RenderSystem.enableBlend();
|
|
|
|
RenderSystem.alphaFunc(516, 0.003921569F);
|
|
|
|
RenderSystem.disableCull();
|
|
|
|
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE);
|
|
|
|
RenderSystem.enableFog();
|
|
|
|
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
RenderSystem.depthMask(false);
|
|
|
|
textureManager.bindTexture(ParticleMagic.TEXTURE);
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
|
|
|
}
|