package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import com.google.common.collect.Lists;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.entity.EquipmentSlot;
import com.mojang.datafixers.util.Pair;
import java.util.List;
import net.minecraft.network.protocol.Packet;

public class ClientboundSetEquipmentPacket implements Packet<ClientGamePacketListener> {
    private int entity;
    private final List<Pair<EquipmentSlot, ItemStack>> slots;
    
    public ClientboundSetEquipmentPacket() {
        this.slots = Lists.newArrayList();
    }
    
    public ClientboundSetEquipmentPacket(final int integer, final List<Pair<EquipmentSlot, ItemStack>> list) {
        this.entity = integer;
        this.slots = list;
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.entity = mg.readVarInt();
        final EquipmentSlot[] arr3 = EquipmentSlot.values();
        int integer4;
        do {
            integer4 = mg.readByte();
            final EquipmentSlot aor5 = arr3[integer4 & 0x7F];
            final ItemStack bki6 = mg.readItem();
            this.slots.add((Pair<EquipmentSlot, ItemStack>)Pair.of(aor5, bki6));
        } while ((integer4 & 0xFFFFFF80) != 0x0);
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeVarInt(this.entity);
        for (int integer3 = this.slots.size(), integer4 = 0; integer4 < integer3; ++integer4) {
            final Pair<EquipmentSlot, ItemStack> pair5 = this.slots.get(integer4);
            final EquipmentSlot aor6 = (EquipmentSlot)pair5.getFirst();
            final boolean boolean7 = integer4 != integer3 - 1;
            final int integer5 = aor6.ordinal();
            mg.writeByte(boolean7 ? (integer5 | 0xFFFFFF80) : integer5);
            mg.writeItem((ItemStack)pair5.getSecond());
        }
    }
    
    @Override
    public void handle(final ClientGamePacketListener nl) {
        nl.handleSetEquipment(this);
    }
    
    public int getEntity() {
        return this.entity;
    }
    
    public List<Pair<EquipmentSlot, ItemStack>> getSlots() {
        return this.slots;
    }
}
