package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.util.Iterator;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.core.NonNullList;
import net.minecraft.world.item.ItemStack;
import java.util.List;
import net.minecraft.network.protocol.Packet;

public class ClientboundContainerSetContentPacket implements Packet<ClientGamePacketListener> {
    private int containerId;
    private List<ItemStack> items;
    
    public ClientboundContainerSetContentPacket() {
    }
    
    public ClientboundContainerSetContentPacket(final int integer, final NonNullList<ItemStack> fy) {
        this.containerId = integer;
        this.items = NonNullList.<ItemStack>withSize(fy.size(), ItemStack.EMPTY);
        for (int integer2 = 0; integer2 < this.items.size(); ++integer2) {
            this.items.set(integer2, fy.get(integer2).copy());
        }
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.containerId = kv.readUnsignedByte();
        final int integer3 = kv.readShort();
        this.items = NonNullList.<ItemStack>withSize(integer3, ItemStack.EMPTY);
        for (int integer4 = 0; integer4 < integer3; ++integer4) {
            this.items.set(integer4, kv.readItem());
        }
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeByte(this.containerId);
        kv.writeShort(this.items.size());
        for (final ItemStack ben4 : this.items) {
            kv.writeItem(ben4);
        }
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleContainerContent(this);
    }
    
    public int getContainerId() {
        return this.containerId;
    }
    
    public List<ItemStack> getItems() {
        return this.items;
    }
}
