164 lines
5.4 KiB
Java
164 lines
5.4 KiB
Java
package net.minecraft.client.particle;
|
|
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
import net.minecraft.client.multiplayer.ClientLevel;
|
|
import net.minecraft.core.particles.SimpleParticleType;
|
|
import net.minecraft.util.Mth;
|
|
import net.minecraft.util.RandomSource;
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public class GlowParticle extends TextureSheetParticle {
|
|
static final RandomSource RANDOM = RandomSource.create();
|
|
private final SpriteSet sprites;
|
|
|
|
GlowParticle(ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, SpriteSet sprites) {
|
|
super(level, x, y, z, xSpeed, ySpeed, zSpeed);
|
|
this.friction = 0.96F;
|
|
this.speedUpWhenYMotionIsBlocked = true;
|
|
this.sprites = sprites;
|
|
this.quadSize *= 0.75F;
|
|
this.hasPhysics = false;
|
|
this.setSpriteFromAge(sprites);
|
|
}
|
|
|
|
@Override
|
|
public ParticleRenderType getRenderType() {
|
|
return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT;
|
|
}
|
|
|
|
@Override
|
|
public int getLightColor(float partialTick) {
|
|
float f = (this.age + partialTick) / this.lifetime;
|
|
f = Mth.clamp(f, 0.0F, 1.0F);
|
|
int i = super.getLightColor(partialTick);
|
|
int j = i & 0xFF;
|
|
int k = i >> 16 & 0xFF;
|
|
j += (int)(f * 15.0F * 16.0F);
|
|
if (j > 240) {
|
|
j = 240;
|
|
}
|
|
|
|
return j | k << 16;
|
|
}
|
|
|
|
@Override
|
|
public void tick() {
|
|
super.tick();
|
|
this.setSpriteFromAge(this.sprites);
|
|
}
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public static class ElectricSparkProvider implements ParticleProvider<SimpleParticleType> {
|
|
private final double SPEED_FACTOR = 0.25;
|
|
private final SpriteSet sprite;
|
|
|
|
public ElectricSparkProvider(SpriteSet sprites) {
|
|
this.sprite = sprites;
|
|
}
|
|
|
|
public Particle createParticle(SimpleParticleType simpleParticleType, ClientLevel clientLevel, double d, double e, double f, double g, double h, double i) {
|
|
GlowParticle glowParticle = new GlowParticle(clientLevel, d, e, f, 0.0, 0.0, 0.0, this.sprite);
|
|
glowParticle.setColor(1.0F, 0.9F, 1.0F);
|
|
glowParticle.setParticleSpeed(g * 0.25, h * 0.25, i * 0.25);
|
|
int j = 2;
|
|
int k = 4;
|
|
glowParticle.setLifetime(clientLevel.random.nextInt(2) + 2);
|
|
return glowParticle;
|
|
}
|
|
}
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public static class GlowSquidProvider implements ParticleProvider<SimpleParticleType> {
|
|
private final SpriteSet sprite;
|
|
|
|
public GlowSquidProvider(SpriteSet sprites) {
|
|
this.sprite = sprites;
|
|
}
|
|
|
|
public Particle createParticle(SimpleParticleType simpleParticleType, ClientLevel clientLevel, double d, double e, double f, double g, double h, double i) {
|
|
GlowParticle glowParticle = new GlowParticle(
|
|
clientLevel, d, e, f, 0.5 - GlowParticle.RANDOM.nextDouble(), h, 0.5 - GlowParticle.RANDOM.nextDouble(), this.sprite
|
|
);
|
|
if (clientLevel.random.nextBoolean()) {
|
|
glowParticle.setColor(0.6F, 1.0F, 0.8F);
|
|
} else {
|
|
glowParticle.setColor(0.08F, 0.4F, 0.4F);
|
|
}
|
|
|
|
glowParticle.yd *= 0.2F;
|
|
if (g == 0.0 && i == 0.0) {
|
|
glowParticle.xd *= 0.1F;
|
|
glowParticle.zd *= 0.1F;
|
|
}
|
|
|
|
glowParticle.setLifetime((int)(8.0 / (clientLevel.random.nextDouble() * 0.8 + 0.2)));
|
|
return glowParticle;
|
|
}
|
|
}
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public static class ScrapeProvider implements ParticleProvider<SimpleParticleType> {
|
|
private final double SPEED_FACTOR = 0.01;
|
|
private final SpriteSet sprite;
|
|
|
|
public ScrapeProvider(SpriteSet sprites) {
|
|
this.sprite = sprites;
|
|
}
|
|
|
|
public Particle createParticle(SimpleParticleType simpleParticleType, ClientLevel clientLevel, double d, double e, double f, double g, double h, double i) {
|
|
GlowParticle glowParticle = new GlowParticle(clientLevel, d, e, f, 0.0, 0.0, 0.0, this.sprite);
|
|
if (clientLevel.random.nextBoolean()) {
|
|
glowParticle.setColor(0.29F, 0.58F, 0.51F);
|
|
} else {
|
|
glowParticle.setColor(0.43F, 0.77F, 0.62F);
|
|
}
|
|
|
|
glowParticle.setParticleSpeed(g * 0.01, h * 0.01, i * 0.01);
|
|
int j = 10;
|
|
int k = 40;
|
|
glowParticle.setLifetime(clientLevel.random.nextInt(30) + 10);
|
|
return glowParticle;
|
|
}
|
|
}
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public static class WaxOffProvider implements ParticleProvider<SimpleParticleType> {
|
|
private final double SPEED_FACTOR = 0.01;
|
|
private final SpriteSet sprite;
|
|
|
|
public WaxOffProvider(SpriteSet sprites) {
|
|
this.sprite = sprites;
|
|
}
|
|
|
|
public Particle createParticle(SimpleParticleType simpleParticleType, ClientLevel clientLevel, double d, double e, double f, double g, double h, double i) {
|
|
GlowParticle glowParticle = new GlowParticle(clientLevel, d, e, f, 0.0, 0.0, 0.0, this.sprite);
|
|
glowParticle.setColor(1.0F, 0.9F, 1.0F);
|
|
glowParticle.setParticleSpeed(g * 0.01 / 2.0, h * 0.01, i * 0.01 / 2.0);
|
|
int j = 10;
|
|
int k = 40;
|
|
glowParticle.setLifetime(clientLevel.random.nextInt(30) + 10);
|
|
return glowParticle;
|
|
}
|
|
}
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public static class WaxOnProvider implements ParticleProvider<SimpleParticleType> {
|
|
private final double SPEED_FACTOR = 0.01;
|
|
private final SpriteSet sprite;
|
|
|
|
public WaxOnProvider(SpriteSet sprites) {
|
|
this.sprite = sprites;
|
|
}
|
|
|
|
public Particle createParticle(SimpleParticleType simpleParticleType, ClientLevel clientLevel, double d, double e, double f, double g, double h, double i) {
|
|
GlowParticle glowParticle = new GlowParticle(clientLevel, d, e, f, 0.0, 0.0, 0.0, this.sprite);
|
|
glowParticle.setColor(0.91F, 0.55F, 0.08F);
|
|
glowParticle.setParticleSpeed(g * 0.01 / 2.0, h * 0.01, i * 0.01 / 2.0);
|
|
int j = 10;
|
|
int k = 40;
|
|
glowParticle.setLifetime(clientLevel.random.nextInt(30) + 10);
|
|
return glowParticle;
|
|
}
|
|
}
|
|
}
|