Files
Explosion-Overhaul/com/vinlanx/explosionoverhaul/client/BackgroundParticle.java
2026-05-04 10:03:58 +00:00

113 lines
4.2 KiB
Java

/*
* Decompiled with CFR 0.152.
*/
package com.vinlanx.explosionoverhaul.client;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
public class BackgroundParticle {
public float x;
public float y;
public float vx;
public float vy;
public float size;
public float life;
public float maxLife;
public int color;
public ParticleType type;
public BackgroundParticle(float x, float y, float vx, float vy, float size, float life, int color, ParticleType type) {
this.x = x;
this.y = y;
this.vx = vx;
this.vy = vy;
this.size = size;
this.life = life;
this.maxLife = life;
this.color = color;
this.type = type;
}
public void tick(float deltaTime) {
this.x += this.vx * deltaTime * 60.0f;
this.y += this.vy * deltaTime * 60.0f;
this.life -= deltaTime;
if (this.type == ParticleType.EMBER) {
this.vy += 0.5f * deltaTime * 60.0f;
}
if (this.type == ParticleType.SMOKE) {
this.size += 0.3f * deltaTime * 60.0f;
}
}
public boolean isDead() {
return this.life <= 0.0f;
}
public float getAlpha() {
float lifeRatio = this.life / this.maxLife;
if (this.type == ParticleType.FLASH) {
return lifeRatio > 0.7f ? 1.0f - (lifeRatio - 0.7f) / 0.3f : lifeRatio / 0.7f;
}
return Mth.m_14036_((float)lifeRatio, (float)0.0f, (float)1.0f);
}
public static BackgroundParticle createSpark(RandomSource random, int screenWidth, int screenHeight) {
float x = random.m_188501_() * (float)screenWidth;
float y = random.m_188501_() * (float)screenHeight;
float angle = random.m_188501_() * (float)Math.PI * 2.0f;
float speed = 2.0f + random.m_188501_() * 4.0f;
float vx = (float)Math.cos(angle) * speed;
float vy = (float)Math.sin(angle) * speed;
float size = 1.0f + random.m_188501_() * 2.0f;
float life = 0.5f + random.m_188501_() * 1.5f;
int[] colors = new int[]{-881908, -21965, -8841, -86};
int color = colors[random.m_188503_(colors.length)];
return new BackgroundParticle(x, y, vx, vy, size, life, color, ParticleType.SPARK);
}
public static BackgroundParticle createEmber(RandomSource random, int screenWidth, int screenHeight) {
float x = random.m_188501_() * (float)screenWidth;
float y = -20.0f;
float vx = (random.m_188501_() - 0.5f) * 2.0f;
float vy = 1.0f + random.m_188501_() * 2.0f;
float size = 2.0f + random.m_188501_() * 4.0f;
float life = 3.0f + random.m_188501_() * 4.0f;
int[] colors = new int[]{-4250588, -2529701, -10939115, -48094};
int color = colors[random.m_188503_(colors.length)];
return new BackgroundParticle(x, y, vx, vy, size, life, color, ParticleType.EMBER);
}
public static BackgroundParticle createFlash(RandomSource random, int screenWidth, int screenHeight) {
float x = random.m_188501_() * (float)screenWidth;
float y = random.m_188501_() * (float)screenHeight;
float size = 30.0f + random.m_188501_() * 70.0f;
float life = 0.2f + random.m_188501_() * 0.4f;
int[] colors = new int[]{-881908, -4250588, -21948};
int color = colors[random.m_188503_(colors.length)];
return new BackgroundParticle(x, y, 0.0f, 0.0f, size, life, color, ParticleType.FLASH);
}
public static BackgroundParticle createSmoke(RandomSource random, int screenWidth, int screenHeight) {
float x = random.m_188501_() * (float)screenWidth;
float y = (float)screenHeight + 20.0f;
float vx = (random.m_188501_() - 0.5f) * 1.0f;
float vy = -1.0f - random.m_188501_() * 2.0f;
float size = 15.0f + random.m_188501_() * 30.0f;
float life = 4.0f + random.m_188501_() * 6.0f;
int gray = 13 + random.m_188503_(30);
int color = 0xFF000000 | gray << 16 | gray << 8 | gray;
return new BackgroundParticle(x, y, vx, vy, size, life, color, ParticleType.SMOKE);
}
public static enum ParticleType {
SPARK,
EMBER,
FLASH,
SMOKE;
}
}