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

84 lines
2.7 KiB
Java
Raw Normal View History

2020-10-14 21:07:36 +02:00
package com.minelittlepony.unicopia.particle;
import java.util.Locale;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleType;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.Registry;
public class OrientedBillboardParticleEffect implements ParticleEffect {
public static final ParticleEffect.Factory<OrientedBillboardParticleEffect> FACTORY = new ParticleEffect.Factory<OrientedBillboardParticleEffect>() {
@Override
public OrientedBillboardParticleEffect read(ParticleType<OrientedBillboardParticleEffect> type, StringReader reader) throws CommandSyntaxException {
reader.expect(' ');
boolean fixed = reader.readBoolean();
reader.expect(' ');
float yaw = (float)reader.readDouble();
reader.expect(' ');
float pitch = (float)reader.readDouble();
return new OrientedBillboardParticleEffect(type, fixed, yaw, pitch);
}
@Override
public OrientedBillboardParticleEffect read(ParticleType<OrientedBillboardParticleEffect> particleType, PacketByteBuf buf) {
return new OrientedBillboardParticleEffect(particleType, buf.readBoolean(), buf.readFloat(), buf.readFloat());
}
};
private final boolean fixed;
private final float yaw;
private final float pitch;
private final ParticleType<OrientedBillboardParticleEffect> type;
public OrientedBillboardParticleEffect(ParticleType<OrientedBillboardParticleEffect> type, Vec3d orientation) {
this(type, (float)orientation.getX(), (float)orientation.getY());
}
public OrientedBillboardParticleEffect(ParticleType<OrientedBillboardParticleEffect> type, float yaw, float pitch) {
this(type, true, yaw, pitch);
}
private OrientedBillboardParticleEffect(ParticleType<OrientedBillboardParticleEffect> type, boolean fixed, float yaw, float pitch) {
this.fixed = fixed;
this.yaw = yaw;
this.pitch = pitch;
this.type = type;
}
public boolean isAngleFixed() {
return fixed;
}
public float getYaw() {
return yaw;
}
public float getPitch() {
return pitch;
}
@Override
public ParticleType<?> getType() {
return type;
}
@Override
public void write(PacketByteBuf buf) {
buf.writeBoolean(fixed);
buf.writeFloat(yaw);
buf.writeFloat(pitch);
}
@Override
public String asString() {
return String.format(Locale.ROOT, "%s %b %.2f %.2f", Registry.PARTICLE_TYPE.getId(getType()), fixed, yaw, pitch);
}
}