package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.util.Iterator;
import java.io.IOException;
import net.minecraft.util.Mth;
import net.minecraft.network.FriendlyByteBuf;
import com.google.common.collect.Lists;
import net.minecraft.world.phys.Vec3;
import net.minecraft.core.BlockPos;
import java.util.List;
import net.minecraft.network.protocol.Packet;

public class ClientboundExplodePacket implements Packet<ClientGamePacketListener> {
    private double x;
    private double y;
    private double z;
    private float power;
    private List<BlockPos> toBlow;
    private float knockbackX;
    private float knockbackY;
    private float knockbackZ;
    
    public ClientboundExplodePacket() {
    }
    
    public ClientboundExplodePacket(final double double1, final double double2, final double double3, final float float4, final List<BlockPos> list, final Vec3 cvl) {
        this.x = double1;
        this.y = double2;
        this.z = double3;
        this.power = float4;
        this.toBlow = Lists.newArrayList(list);
        if (cvl != null) {
            this.knockbackX = (float)cvl.x;
            this.knockbackY = (float)cvl.y;
            this.knockbackZ = (float)cvl.z;
        }
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.x = kv.readFloat();
        this.y = kv.readFloat();
        this.z = kv.readFloat();
        this.power = kv.readFloat();
        final int integer3 = kv.readInt();
        this.toBlow = Lists.newArrayListWithCapacity(integer3);
        final int integer4 = Mth.floor(this.x);
        final int integer5 = Mth.floor(this.y);
        final int integer6 = Mth.floor(this.z);
        for (int integer7 = 0; integer7 < integer3; ++integer7) {
            final int integer8 = kv.readByte() + integer4;
            final int integer9 = kv.readByte() + integer5;
            final int integer10 = kv.readByte() + integer6;
            this.toBlow.add(new BlockPos(integer8, integer9, integer10));
        }
        this.knockbackX = kv.readFloat();
        this.knockbackY = kv.readFloat();
        this.knockbackZ = kv.readFloat();
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeFloat((float)this.x);
        kv.writeFloat((float)this.y);
        kv.writeFloat((float)this.z);
        kv.writeFloat(this.power);
        kv.writeInt(this.toBlow.size());
        final int integer3 = Mth.floor(this.x);
        final int integer4 = Mth.floor(this.y);
        final int integer5 = Mth.floor(this.z);
        for (final BlockPos fk7 : this.toBlow) {
            final int integer6 = fk7.getX() - integer3;
            final int integer7 = fk7.getY() - integer4;
            final int integer8 = fk7.getZ() - integer5;
            kv.writeByte(integer6);
            kv.writeByte(integer7);
            kv.writeByte(integer8);
        }
        kv.writeFloat(this.knockbackX);
        kv.writeFloat(this.knockbackY);
        kv.writeFloat(this.knockbackZ);
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleExplosion(this);
    }
    
    public float getKnockbackX() {
        return this.knockbackX;
    }
    
    public float getKnockbackY() {
        return this.knockbackY;
    }
    
    public float getKnockbackZ() {
        return this.knockbackZ;
    }
    
    public double getX() {
        return this.x;
    }
    
    public double getY() {
        return this.y;
    }
    
    public double getZ() {
        return this.z;
    }
    
    public float getPower() {
        return this.power;
    }
    
    public List<BlockPos> getToBlow() {
        return this.toBlow;
    }
}
