NaturesAura/src/main/java/de/ellpeck/naturesaura/particles/ParticleMagic.java

93 lines
4.3 KiB
Java
Raw Normal View History

2018-10-13 20:35:18 +02:00
package de.ellpeck.naturesaura.particles;
import de.ellpeck.naturesaura.NaturesAura;
import net.minecraft.client.particle.Particle;
2019-01-30 15:29:14 +01:00
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.entity.Entity;
2018-10-13 20:35:18 +02:00
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ParticleMagic extends Particle {
2019-01-30 15:29:14 +01:00
public static final ResourceLocation TEXTURE = new ResourceLocation(NaturesAura.MOD_ID, "textures/particles/magic_round.png");
2018-10-13 20:35:18 +02:00
private final float desiredScale;
2018-10-14 14:27:18 +02:00
private final boolean fade;
2018-10-13 20:35:18 +02:00
2018-10-14 14:27:18 +02:00
public ParticleMagic(World world, double posX, double posY, double posZ, double motionX, double motionY, double motionZ, int color, float scale, int maxAge, float gravity, boolean collision, boolean fade) {
2018-10-13 20:35:18 +02:00
super(world, posX, posY, posZ);
this.desiredScale = scale;
2018-10-13 20:45:32 +02:00
this.particleMaxAge = maxAge;
2018-10-13 20:35:18 +02:00
this.canCollide = collision;
this.particleGravity = gravity;
2018-10-14 14:27:18 +02:00
this.fade = fade;
2018-10-13 20:35:18 +02:00
this.motionX = motionX;
this.motionY = motionY;
this.motionZ = motionZ;
2018-11-05 22:37:40 +01:00
float r = (((color >> 16) & 255) / 255F) * (1F - this.rand.nextFloat() * 0.25F);
float g = (((color >> 8) & 255) / 255F) * (1F - this.rand.nextFloat() * 0.25F);
float b = ((color & 255) / 255F) * (1F - this.rand.nextFloat() * 0.25F);
2018-10-28 16:21:43 +01:00
this.setRBGColorF(r, g, b);
2018-10-13 20:35:18 +02:00
2019-01-28 20:19:08 +01:00
this.particleAlpha = 1F;
this.particleScale = 0F;
2018-10-13 20:35:18 +02:00
}
@Override
2018-10-13 20:45:32 +02:00
public void onUpdate() {
2018-10-14 14:27:18 +02:00
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
2018-10-13 20:35:18 +02:00
2018-10-14 14:27:18 +02:00
this.particleAge++;
2019-01-29 19:55:38 +01:00
if (this.particleAge > this.particleMaxAge) {
2018-10-14 14:27:18 +02:00
this.setExpired();
} else {
this.motionY -= 0.04D * (double) this.particleGravity;
this.move(this.motionX, this.motionY, this.motionZ);
float lifeRatio = (float) this.particleAge / (float) this.particleMaxAge;
2019-01-29 19:55:38 +01:00
if (this.fade && lifeRatio > 0.75F)
this.particleAlpha = 1F - (lifeRatio - 0.75F) / 0.25F;
if (lifeRatio <= 0.25F)
this.particleScale = this.desiredScale * (lifeRatio / 0.25F);
else if (this.fade)
this.particleScale = this.desiredScale * (1F - (lifeRatio - 0.25F) / 0.75F);
2018-10-14 14:27:18 +02:00
}
2018-10-13 20:35:18 +02:00
}
@Override
2019-01-30 15:29:14 +01:00
public void renderParticle(BufferBuilder buffer, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
double x = this.prevPosX + (this.posX - this.prevPosX) * partialTicks - interpPosX;
double y = this.prevPosY + (this.posY - this.prevPosY) * partialTicks - interpPosY;
double z = this.prevPosZ + (this.posZ - this.prevPosZ) * partialTicks - interpPosZ;
float sc = 0.1F * this.particleScale;
int brightness = this.getBrightnessForRender(partialTicks);
int sky = brightness >> 16 & 0xFFFF;
int block = brightness & 0xFFFF;
buffer.pos(x + (-rotationX * sc - rotationXY * sc), y + -rotationZ * sc, z + (-rotationYZ * sc - rotationXZ * sc))
.tex(0, 1).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha)
.lightmap(sky, block).endVertex();
buffer.pos(x + (-rotationX * sc + rotationXY * sc), y + (rotationZ * sc), z + (-rotationYZ * sc + rotationXZ * sc))
.tex(1, 1).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha)
.lightmap(sky, block).endVertex();
buffer.pos(x + (rotationX * sc + rotationXY * sc), y + (rotationZ * sc), z + (rotationYZ * sc + rotationXZ * sc))
.tex(1, 0).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha)
.lightmap(sky, block).endVertex();
buffer.pos(x + (rotationX * sc - rotationXY * sc), y + (-rotationZ * sc), z + (rotationYZ * sc - rotationXZ * sc))
.tex(0, 0).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha)
.lightmap(sky, block).endVertex();
2018-10-13 20:35:18 +02:00
}
@Override
public int getBrightnessForRender(float f) {
return 15 << 20 | 15 << 4;
}
}