Unicopia/src/main/java/com/minelittlepony/unicopia/particle/SphereParticleEffect.java

72 lines
2.3 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.particle;
2020-05-03 19:20:51 +02:00
import java.util.Locale;
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-22 12:10:45 +01:00
import net.minecraft.util.math.Vec3f;
2020-05-03 19:20:51 +02:00
import net.minecraft.util.registry.Registry;
public class SphereParticleEffect implements ParticleEffect {
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-22 12:10:45 +01:00
private final Vec3f color;
2020-05-03 19:20:51 +02:00
private final float alpha;
private final float radius;
2021-12-22 12:10:45 +01:00
protected SphereParticleEffect(ParticleType<? extends SphereParticleEffect> type, StringReader reader) throws CommandSyntaxException {
this(AbstractDustParticleEffect.readColor(reader), ParticleFactoryHelper.readFloat(reader), ParticleFactoryHelper.readFloat(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) {
this(AbstractDustParticleEffect.readColor(buf), buf.readFloat(), buf.readFloat());
2020-05-03 19:20:51 +02:00
}
2021-12-22 12:10:45 +01:00
public SphereParticleEffect(int tint, float alpha, float rad) {
this(new Vec3f(Color.r(tint), Color.g(tint), Color.b(tint)), alpha, rad);
2020-05-03 19:20:51 +02:00
}
2021-12-22 12:10:45 +01:00
public SphereParticleEffect(Vec3f color, float alpha, float rad) {
this.color = color;
this.alpha = alpha;
this.radius = rad;
2020-05-03 19:20:51 +02:00
}
2021-12-22 12:10:45 +01:00
public Vec3f getColor() {
return color;
2020-05-03 19:20:51 +02:00
}
public float getAlpha() {
return alpha;
}
public float getRadius() {
return radius;
}
@Override
public ParticleType<?> getType() {
return UParticles.SPHERE;
}
@Override
public void write(PacketByteBuf buf) {
2021-12-22 12:10:45 +01:00
buf.writeFloat(color.getX());
buf.writeFloat(color.getY());
buf.writeFloat(color.getZ());
2020-05-03 19:20:51 +02:00
buf.writeFloat(alpha);
buf.writeFloat(radius);
}
@Override
public String asString() {
2021-12-22 12:10:45 +01:00
return String.format(Locale.ROOT, "%s %.2f %.2f %.2f %.2f", Registry.PARTICLE_TYPE.getId(getType()), color.getX(), color.getY(), color.getZ(), alpha, radius);
2020-05-03 19:20:51 +02:00
}
}