mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 19:59:36 +00:00
170 lines
6.0 KiB
Java
170 lines
6.0 KiB
Java
/**
|
|
* This class was created by <Azanor>. It's distributed as
|
|
* part of the Botania Mod. Get the Source Code in github:
|
|
* https://github.com/Vazkii/Botania
|
|
*
|
|
* Botania is Open Source and distributed under the
|
|
* Botania License: http://botaniamod.net/license.php
|
|
*
|
|
* File Created @ [? (GMT)]
|
|
*/
|
|
package vazkii.botania.client.fx;
|
|
|
|
import com.mojang.blaze3d.platform.GlStateManager;
|
|
import net.minecraft.client.particle.IParticleRenderType;
|
|
import net.minecraft.client.particle.Particle;
|
|
import net.minecraft.client.renderer.ActiveRenderInfo;
|
|
import net.minecraft.client.renderer.BufferBuilder;
|
|
import net.minecraft.client.renderer.Tessellator;
|
|
import net.minecraft.client.renderer.texture.TextureManager;
|
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|
import net.minecraft.util.ResourceLocation;
|
|
import net.minecraft.world.World;
|
|
import org.lwjgl.opengl.GL11;
|
|
import vazkii.botania.client.lib.LibResources;
|
|
import vazkii.botania.common.core.handler.ConfigHandler;
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
public class FXWisp extends Particle {
|
|
|
|
private static final ResourceLocation vanillaParticles = new ResourceLocation("textures/particle/particles.png");
|
|
public static final ResourceLocation particles = new ResourceLocation(LibResources.MISC_WISP_LARGE);
|
|
|
|
protected float particleScale = (this.rand.nextFloat() * 0.5F + 0.5F) * 2.0F;
|
|
private final boolean depthTest;
|
|
private final float moteParticleScale;
|
|
private final int moteHalfLife;
|
|
|
|
public FXWisp(World world, double d, double d1, double d2, double xSpeed, double ySpeed, double zSpeed,
|
|
float size, float red, float green, float blue, boolean depthTest, float maxAgeMul, boolean noClip) {
|
|
super(world, d, d1, d2, 0, 0, 0);
|
|
// super applies wiggle to motion so set it here instead
|
|
motionX = xSpeed;
|
|
motionY = ySpeed;
|
|
motionZ = zSpeed;
|
|
particleRed = red;
|
|
particleGreen = green;
|
|
particleBlue = blue;
|
|
particleGravity = 0;
|
|
particleScale *= size;
|
|
moteParticleScale = particleScale;
|
|
maxAge = (int)(28D / (Math.random() * 0.3D + 0.7D) * maxAgeMul);
|
|
this.depthTest = depthTest;
|
|
|
|
moteHalfLife = maxAge / 2;
|
|
setSize(0.01F, 0.01F);
|
|
|
|
prevPosX = posX;
|
|
prevPosY = posY;
|
|
prevPosZ = posZ;
|
|
this.canCollide = !noClip;
|
|
}
|
|
|
|
@Override
|
|
public void renderParticle(BufferBuilder buffer, ActiveRenderInfo entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
|
|
float agescale = (float)age / (float) moteHalfLife;
|
|
if (agescale > 1F)
|
|
agescale = 2 - agescale;
|
|
|
|
particleScale = moteParticleScale * agescale;
|
|
|
|
float f10 = 0.5F * particleScale;
|
|
float f11 = (float)(prevPosX + (posX - prevPosX) * partialTicks - interpPosX);
|
|
float f12 = (float)(prevPosY + (posY - prevPosY) * partialTicks - interpPosY);
|
|
float f13 = (float)(prevPosZ + (posZ - prevPosZ) * partialTicks - interpPosZ);
|
|
int combined = 15 << 20 | 15 << 4;
|
|
int k3 = combined >> 16 & 0xFFFF;
|
|
int l3 = combined & 0xFFFF;
|
|
buffer.pos(f11 - rotationX * f10 - rotationXY * f10, f12 - rotationZ * f10, f13 - rotationYZ * f10 - rotationXZ * f10).tex(0, 1).lightmap(k3, l3).color(particleRed, particleGreen, particleBlue, 0.5F).endVertex();
|
|
buffer.pos(f11 - rotationX * f10 + rotationXY * f10, f12 + rotationZ * f10, f13 - rotationYZ * f10 + rotationXZ * f10).tex(1, 1).lightmap(k3, l3).color(particleRed, particleGreen, particleBlue, 0.5F).endVertex();
|
|
buffer.pos(f11 + rotationX * f10 + rotationXY * f10, f12 + rotationZ * f10, f13 + rotationYZ * f10 + rotationXZ * f10).tex(1, 0).lightmap(k3, l3).color(particleRed, particleGreen, particleBlue, 0.5F).endVertex();
|
|
buffer.pos(f11 + rotationX * f10 - rotationXY * f10, f12 - rotationZ * f10, f13 + rotationYZ * f10 - rotationXZ * f10).tex(0, 0).lightmap(k3, l3).color(particleRed, particleGreen, particleBlue, 0.5F).endVertex();
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public IParticleRenderType getRenderType() {
|
|
return depthTest ? NORMAL_RENDER : DIW_RENDER;
|
|
}
|
|
|
|
// [VanillaCopy] of super, without drag when onGround is true
|
|
@Override
|
|
public void tick() {
|
|
this.prevPosX = this.posX;
|
|
this.prevPosY = this.posY;
|
|
this.prevPosZ = this.posZ;
|
|
|
|
if (this.age++ >= this.maxAge)
|
|
{
|
|
this.setExpired();
|
|
}
|
|
|
|
this.motionY -= 0.04D * (double)this.particleGravity;
|
|
this.move(this.motionX, this.motionY, this.motionZ);
|
|
this.motionX *= 0.9800000190734863D;
|
|
this.motionY *= 0.9800000190734863D;
|
|
this.motionZ *= 0.9800000190734863D;
|
|
}
|
|
|
|
public void setGravity(float value) {
|
|
particleGravity = value;
|
|
}
|
|
|
|
private static void beginRenderCommon(BufferBuilder bufferBuilder, TextureManager textureManager) {
|
|
GlStateManager.depthMask(false);
|
|
GlStateManager.enableBlend();
|
|
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
|
|
GlStateManager.alphaFunc(GL11.GL_GREATER, 0.003921569F);
|
|
GlStateManager.disableLighting();
|
|
|
|
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 0.75F);
|
|
textureManager.bindTexture(ConfigHandler.CLIENT.matrixMode.get() ? vanillaParticles : particles);
|
|
bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_LMAP_COLOR);
|
|
}
|
|
|
|
private static void endRenderCommon() {
|
|
GlStateManager.alphaFunc(GL11.GL_GREATER, 0.1F);
|
|
GlStateManager.disableBlend();
|
|
GlStateManager.depthMask(true);
|
|
}
|
|
|
|
private static final IParticleRenderType NORMAL_RENDER = new IParticleRenderType() {
|
|
@Override
|
|
public void beginRender(BufferBuilder bufferBuilder, TextureManager textureManager) {
|
|
beginRenderCommon(bufferBuilder, textureManager);
|
|
}
|
|
|
|
@Override
|
|
public void finishRender(Tessellator tessellator) {
|
|
tessellator.draw();
|
|
endRenderCommon();
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "botania:wisp";
|
|
}
|
|
};
|
|
|
|
private static final IParticleRenderType DIW_RENDER = new IParticleRenderType() {
|
|
@Override
|
|
public void beginRender(BufferBuilder bufferBuilder, TextureManager textureManager) {
|
|
beginRenderCommon(bufferBuilder, textureManager);
|
|
GlStateManager.disableDepthTest();
|
|
}
|
|
|
|
@Override
|
|
public void finishRender(Tessellator tessellator) {
|
|
tessellator.draw();
|
|
GlStateManager.enableDepthTest();
|
|
endRenderCommon();
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "botania:depth_ignoring_wisp";
|
|
}
|
|
};
|
|
}
|