package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.Registry;
import net.minecraft.core.particles.ParticleType;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.network.protocol.Packet;

public class ClientboundLevelParticlesPacket implements Packet<ClientGamePacketListener> {
    private double x;
    private double y;
    private double z;
    private float xDist;
    private float yDist;
    private float zDist;
    private float maxSpeed;
    private int count;
    private boolean overrideLimiter;
    private ParticleOptions particle;
    
    public ClientboundLevelParticlesPacket() {
    }
    
    public <T extends ParticleOptions> ClientboundLevelParticlesPacket(final T gt, final boolean boolean2, final double double3, final double double4, final double double5, final float float6, final float float7, final float float8, final float float9, final int integer) {
        this.particle = gt;
        this.overrideLimiter = boolean2;
        this.x = double3;
        this.y = double4;
        this.z = double5;
        this.xDist = float6;
        this.yDist = float7;
        this.zDist = float8;
        this.maxSpeed = float9;
        this.count = integer;
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        ParticleType<?> gu3 = Registry.PARTICLE_TYPE.byId(kv.readInt());
        if (gu3 == null) {
            gu3 = ParticleTypes.BARRIER;
        }
        this.overrideLimiter = kv.readBoolean();
        this.x = kv.readDouble();
        this.y = kv.readDouble();
        this.z = kv.readDouble();
        this.xDist = kv.readFloat();
        this.yDist = kv.readFloat();
        this.zDist = kv.readFloat();
        this.maxSpeed = kv.readFloat();
        this.count = kv.readInt();
        this.particle = this.<ParticleOptions>readParticle(kv, gu3);
    }
    
    private <T extends ParticleOptions> T readParticle(final FriendlyByteBuf kv, final ParticleType<T> gu) {
        return gu.getDeserializer().fromNetwork(gu, kv);
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeInt(Registry.PARTICLE_TYPE.getId(this.particle.getType()));
        kv.writeBoolean(this.overrideLimiter);
        kv.writeDouble(this.x);
        kv.writeDouble(this.y);
        kv.writeDouble(this.z);
        kv.writeFloat(this.xDist);
        kv.writeFloat(this.yDist);
        kv.writeFloat(this.zDist);
        kv.writeFloat(this.maxSpeed);
        kv.writeInt(this.count);
        this.particle.writeToNetwork(kv);
    }
    
    public boolean isOverrideLimiter() {
        return this.overrideLimiter;
    }
    
    public double getX() {
        return this.x;
    }
    
    public double getY() {
        return this.y;
    }
    
    public double getZ() {
        return this.z;
    }
    
    public float getXDist() {
        return this.xDist;
    }
    
    public float getYDist() {
        return this.yDist;
    }
    
    public float getZDist() {
        return this.zDist;
    }
    
    public float getMaxSpeed() {
        return this.maxSpeed;
    }
    
    public int getCount() {
        return this.count;
    }
    
    public ParticleOptions getParticle() {
        return this.particle;
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleParticleEvent(this);
    }
}
