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 hf, 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 = hf;
        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 mg) throws IOException {
        ParticleType<?> hg3 = Registry.PARTICLE_TYPE.byId(mg.readInt());
        if (hg3 == null) {
            hg3 = ParticleTypes.BARRIER;
        }
        this.overrideLimiter = mg.readBoolean();
        this.x = mg.readDouble();
        this.y = mg.readDouble();
        this.z = mg.readDouble();
        this.xDist = mg.readFloat();
        this.yDist = mg.readFloat();
        this.zDist = mg.readFloat();
        this.maxSpeed = mg.readFloat();
        this.count = mg.readInt();
        this.particle = this.<ParticleOptions>readParticle(mg, hg3);
    }
    
    private <T extends ParticleOptions> T readParticle(final FriendlyByteBuf mg, final ParticleType<T> hg) {
        return hg.getDeserializer().fromNetwork(hg, mg);
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeInt(Registry.PARTICLE_TYPE.getId(this.particle.getType()));
        mg.writeBoolean(this.overrideLimiter);
        mg.writeDouble(this.x);
        mg.writeDouble(this.y);
        mg.writeDouble(this.z);
        mg.writeFloat(this.xDist);
        mg.writeFloat(this.yDist);
        mg.writeFloat(this.zDist);
        mg.writeFloat(this.maxSpeed);
        mg.writeInt(this.count);
        this.particle.writeToNetwork(mg);
    }
    
    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 nl) {
        nl.handleParticleEvent(this);
    }
}
