2020-09-22 15:11:20 +02:00
|
|
|
package com.minelittlepony.unicopia.particle;
|
2020-05-03 19:20:51 +02:00
|
|
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
2022-12-18 22:07:24 +01:00
|
|
|
import org.joml.Vector3f;
|
|
|
|
|
2020-06-26 11:44:47 +02:00
|
|
|
import com.minelittlepony.common.util.Color;
|
2020-05-03 19:20:51 +02:00
|
|
|
import com.mojang.brigadier.StringReader;
|
|
|
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|
|
|
|
2021-12-22 12:10:45 +01:00
|
|
|
import net.minecraft.particle.AbstractDustParticleEffect;
|
2020-05-03 19:20:51 +02:00
|
|
|
import net.minecraft.particle.ParticleEffect;
|
|
|
|
import net.minecraft.particle.ParticleType;
|
2020-06-26 11:44:47 +02:00
|
|
|
import net.minecraft.network.PacketByteBuf;
|
2021-12-26 15:11:34 +01:00
|
|
|
import net.minecraft.util.math.Vec3d;
|
2022-12-18 22:07:24 +01:00
|
|
|
import net.minecraft.registry.Registries;
|
2020-05-03 19:20:51 +02:00
|
|
|
|
|
|
|
public class SphereParticleEffect implements ParticleEffect {
|
2021-12-23 23:38:02 +01:00
|
|
|
@SuppressWarnings("deprecation")
|
2021-12-22 12:10:45 +01:00
|
|
|
public static final Factory<SphereParticleEffect> FACTORY = ParticleFactoryHelper.of(SphereParticleEffect::new, SphereParticleEffect::new);
|
2020-05-03 19:20:51 +02:00
|
|
|
|
2021-12-26 15:11:34 +01:00
|
|
|
private static final Vec3d DEFAULT_OFFSET = new Vec3d(0, 0.5, 0);
|
|
|
|
|
2022-12-18 22:07:24 +01:00
|
|
|
private final Vector3f color;
|
2020-05-03 19:20:51 +02:00
|
|
|
private final float alpha;
|
|
|
|
private final float radius;
|
|
|
|
|
2021-12-26 15:11:34 +01:00
|
|
|
private Vec3d offset = Vec3d.ZERO;
|
|
|
|
|
2021-12-26 19:13:28 +01:00
|
|
|
private final ParticleType<? extends SphereParticleEffect> type;
|
|
|
|
|
2021-12-22 12:10:45 +01:00
|
|
|
protected SphereParticleEffect(ParticleType<? extends SphereParticleEffect> type, StringReader reader) throws CommandSyntaxException {
|
2021-12-26 19:13:28 +01:00
|
|
|
this(type, AbstractDustParticleEffect.readColor(reader), ParticleFactoryHelper.readFloat(reader), ParticleFactoryHelper.readFloat(reader), ParticleFactoryHelper.readVector(reader));
|
2020-05-03 19:20:51 +02:00
|
|
|
}
|
|
|
|
|
2021-12-22 12:10:45 +01:00
|
|
|
protected SphereParticleEffect(ParticleType<? extends SphereParticleEffect> type, PacketByteBuf buf) {
|
2021-12-26 19:13:28 +01:00
|
|
|
this(type, AbstractDustParticleEffect.readColor(buf), buf.readFloat(), buf.readFloat());
|
2020-05-03 19:20:51 +02:00
|
|
|
}
|
|
|
|
|
2021-12-26 19:13:28 +01:00
|
|
|
public SphereParticleEffect(ParticleType<? extends SphereParticleEffect> type, int tint, float alpha, float rad) {
|
|
|
|
this(type, tint, alpha, rad, DEFAULT_OFFSET);
|
2020-05-03 19:20:51 +02:00
|
|
|
}
|
|
|
|
|
2022-12-18 22:07:24 +01:00
|
|
|
public SphereParticleEffect(ParticleType<? extends SphereParticleEffect> type, Vector3f color, float alpha, float rad) {
|
2021-12-26 19:13:28 +01:00
|
|
|
this(type, color, alpha, rad, DEFAULT_OFFSET);
|
2021-12-26 15:11:34 +01:00
|
|
|
}
|
|
|
|
|
2021-12-26 19:13:28 +01:00
|
|
|
public SphereParticleEffect(ParticleType<? extends SphereParticleEffect> type, int tint, float alpha, float rad, Vec3d offset) {
|
2022-12-18 22:07:24 +01:00
|
|
|
this(type, new Vector3f(Color.r(tint) * 255, Color.g(tint) * 255, Color.b(tint) * 255), alpha, rad, offset);
|
2021-12-26 15:11:34 +01:00
|
|
|
}
|
|
|
|
|
2022-12-18 22:07:24 +01:00
|
|
|
public SphereParticleEffect(ParticleType<? extends SphereParticleEffect> type, Vector3f color, float alpha, float rad, Vec3d offset) {
|
2021-12-26 19:13:28 +01:00
|
|
|
this.type = type;
|
2021-12-22 12:10:45 +01:00
|
|
|
this.color = color;
|
2021-12-26 15:11:34 +01:00
|
|
|
this.offset = offset;
|
2021-12-22 12:10:45 +01:00
|
|
|
this.alpha = alpha;
|
|
|
|
this.radius = rad;
|
2020-05-03 19:20:51 +02:00
|
|
|
}
|
|
|
|
|
2021-12-26 15:11:34 +01:00
|
|
|
public Vec3d getOffset() {
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2022-09-17 19:13:39 +02:00
|
|
|
public void setOffset(Vec3d offset) {
|
|
|
|
this.offset = offset;
|
|
|
|
}
|
|
|
|
|
2022-12-18 22:07:24 +01:00
|
|
|
public Vector3f getColor() {
|
2021-12-22 12:10:45 +01:00
|
|
|
return color;
|
2020-05-03 19:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public float getAlpha() {
|
|
|
|
return alpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
public float getRadius() {
|
|
|
|
return radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ParticleType<?> getType() {
|
2021-12-26 19:13:28 +01:00
|
|
|
return type;
|
2020-05-03 19:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void write(PacketByteBuf buf) {
|
2022-12-18 22:07:24 +01:00
|
|
|
buf.writeFloat(color.x);
|
|
|
|
buf.writeFloat(color.y);
|
|
|
|
buf.writeFloat(color.z);
|
2020-05-03 19:20:51 +02:00
|
|
|
buf.writeFloat(alpha);
|
|
|
|
buf.writeFloat(radius);
|
2021-12-26 15:11:34 +01:00
|
|
|
buf.writeDouble(offset.getX());
|
|
|
|
buf.writeDouble(offset.getY());
|
|
|
|
buf.writeDouble(offset.getZ());
|
2020-05-03 19:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String asString() {
|
2021-12-26 15:11:34 +01:00
|
|
|
return String.format(Locale.ROOT, "%s %.2f %.2f %.2f %.2f %.2f %.2f %.2f",
|
2022-12-18 22:07:24 +01:00
|
|
|
Registries.PARTICLE_TYPE.getId(getType()),
|
|
|
|
color.x, color.y, color.z,
|
2021-12-26 15:11:34 +01:00
|
|
|
alpha,
|
|
|
|
radius,
|
|
|
|
offset.getX(), offset.getY(), offset.getZ()
|
|
|
|
);
|
2020-05-03 19:20:51 +02:00
|
|
|
}
|
|
|
|
}
|