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 dem) {
        this.x = double1;
        this.y = double2;
        this.z = double3;
        this.power = float4;
        this.toBlow = Lists.newArrayList(list);
        if (dem != null) {
            this.knockbackX = (float)dem.x;
            this.knockbackY = (float)dem.y;
            this.knockbackZ = (float)dem.z;
        }
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.x = mg.readFloat();
        this.y = mg.readFloat();
        this.z = mg.readFloat();
        this.power = mg.readFloat();
        final int integer3 = mg.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 = mg.readByte() + integer4;
            final int integer9 = mg.readByte() + integer5;
            final int integer10 = mg.readByte() + integer6;
            this.toBlow.add(new BlockPos(integer8, integer9, integer10));
        }
        this.knockbackX = mg.readFloat();
        this.knockbackY = mg.readFloat();
        this.knockbackZ = mg.readFloat();
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeFloat((float)this.x);
        mg.writeFloat((float)this.y);
        mg.writeFloat((float)this.z);
        mg.writeFloat(this.power);
        mg.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 fu7 : this.toBlow) {
            final int integer6 = fu7.getX() - integer3;
            final int integer7 = fu7.getY() - integer4;
            final int integer8 = fu7.getZ() - integer5;
            mg.writeByte(integer6);
            mg.writeByte(integer7);
            mg.writeByte(integer8);
        }
        mg.writeFloat(this.knockbackX);
        mg.writeFloat(this.knockbackY);
        mg.writeFloat(this.knockbackZ);
    }
    
    @Override
    public void handle(final ClientGamePacketListener nl) {
        nl.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;
    }
}
