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 FACTORY = new ParticleEffect.Factory() { @Override public OrientedBillboardParticleEffect read(ParticleType 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 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 type; public OrientedBillboardParticleEffect(ParticleType type, Vec3d orientation) { this(type, (float)orientation.getX(), (float)orientation.getY()); } public OrientedBillboardParticleEffect(ParticleType type, float yaw, float pitch) { this(type, true, yaw, pitch); } private OrientedBillboardParticleEffect(ParticleType 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); } }