add fade to particles

This commit is contained in:
Ellpeck 2019-01-30 15:29:14 +01:00
parent 871201d77c
commit da498aea97
4 changed files with 35 additions and 23 deletions

View file

@ -92,11 +92,6 @@ public class ClientEvents {
mc.profiler.endSection();
}
@SubscribeEvent
public void onTextureStitch(TextureStitchEvent event) {
event.getMap().registerSprite(ParticleMagic.TEXTURE);
}
@SubscribeEvent
public void onClientTick(ClientTickEvent event) {
if (event.phase == Phase.END) {

View file

@ -7,7 +7,6 @@ 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.texture.TextureMap;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.relauncher.Side;
@ -30,14 +29,12 @@ public final class ParticleHandler {
int setting = mc.gameSettings.particleSetting;
if (setting != 0 &&
(setting != 1 || mc.world.rand.nextInt(3) != 0) &&
(setting != 2 || mc.world.rand.nextInt(10) != 0)) {
(setting != 2 || mc.world.rand.nextInt(10) != 0))
return;
}
}
double setting = ModConfig.client.particleAmount;
if (setting < 1 && mc.world.rand.nextDouble() > setting) {
if (setting < 1 && mc.world.rand.nextDouble() > setting)
return;
}
PARTICLES.add(particle.get());
}
}
@ -46,9 +43,8 @@ public final class ParticleHandler {
for (int i = PARTICLES.size() - 1; i >= 0; i--) {
Particle particle = PARTICLES.get(i);
particle.onUpdate();
if (!particle.isAlive()) {
if (!particle.isAlive())
PARTICLES.remove(i);
}
}
}
@ -77,15 +73,14 @@ public final class ParticleHandler {
GlStateManager.depthMask(false);
mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
mc.getTextureManager().bindTexture(ParticleMagic.TEXTURE);
Tessellator tessy = Tessellator.getInstance();
BufferBuilder buffer = tessy.getBuffer();
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE);
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP);
for (Particle particle : PARTICLES) {
for (Particle particle : PARTICLES)
particle.renderParticle(buffer, player, partialTicks, x, xz, z, yz, xy);
}
tessy.draw();

View file

@ -1,9 +1,9 @@
package de.ellpeck.naturesaura.particles;
import de.ellpeck.naturesaura.NaturesAura;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
@ -12,7 +12,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ParticleMagic extends Particle {
public static final ResourceLocation TEXTURE = new ResourceLocation(NaturesAura.MOD_ID, "particles/magic_round");
public static final ResourceLocation TEXTURE = new ResourceLocation(NaturesAura.MOD_ID, "textures/particles/magic_round.png");
private final float desiredScale;
private final boolean fade;
@ -34,9 +34,6 @@ public class ParticleMagic extends Particle {
float b = ((color & 255) / 255F) * (1F - this.rand.nextFloat() * 0.25F);
this.setRBGColorF(r, g, b);
TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks();
this.setParticleTexture(map.getAtlasSprite(TEXTURE.toString()));
this.particleAlpha = 1F;
this.particleScale = 0F;
}
@ -65,8 +62,28 @@ public class ParticleMagic extends Particle {
}
@Override
public int getFXLayer() {
return 1;
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();
}
@Override

View file

@ -0,0 +1,5 @@
{
"texture": {
"blur": true
}
}