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

71 lines
2.4 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.Minecraft;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.renderer.texture.TextureMap;
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 {
2018-10-13 23:46:30 +02:00
public static final ResourceLocation TEXTURE = new ResourceLocation(NaturesAura.MOD_ID, "particles/magic_round");
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-10-13 20:45:32 +02:00
this.setRBGColorF(((color >> 16) & 255) / 255F, ((color >> 8) & 255) / 255F, (color & 255) / 255F);
2018-10-13 20:35:18 +02:00
2018-10-13 20:45:32 +02:00
TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks();
2018-10-13 20:35:18 +02:00
this.setParticleTexture(map.getAtlasSprite(TEXTURE.toString()));
2018-10-14 14:27:18 +02:00
this.particleAlpha = 0.75F;
this.particleScale = this.desiredScale;
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++;
if (this.particleAge >= this.particleMaxAge) {
this.setExpired();
} else {
this.motionY -= 0.04D * (double) this.particleGravity;
this.move(this.motionX, this.motionY, this.motionZ);
if (this.fade) {
float lifeRatio = (float) this.particleAge / (float) this.particleMaxAge;
this.particleAlpha = 0.75F - (lifeRatio * 0.75F);
this.particleScale = this.desiredScale - (this.desiredScale * lifeRatio);
}
}
2018-10-13 20:35:18 +02:00
}
@Override
public int getFXLayer() {
return 1;
}
@Override
public int getBrightnessForRender(float f) {
return 15 << 20 | 15 << 4;
}
}