73 lines
2.3 KiB
Java
73 lines
2.3 KiB
Java
package net.minecraft.network.protocol.game;
|
|
|
|
import java.util.List;
|
|
import net.minecraft.core.NonNullList;
|
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
|
import net.minecraft.network.codec.StreamCodec;
|
|
import net.minecraft.network.protocol.Packet;
|
|
import net.minecraft.network.protocol.PacketType;
|
|
import net.minecraft.world.item.ItemStack;
|
|
|
|
public class ClientboundContainerSetContentPacket implements Packet<ClientGamePacketListener> {
|
|
public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundContainerSetContentPacket> STREAM_CODEC = Packet.codec(
|
|
ClientboundContainerSetContentPacket::write, ClientboundContainerSetContentPacket::new
|
|
);
|
|
private final int containerId;
|
|
private final int stateId;
|
|
private final List<ItemStack> items;
|
|
private final ItemStack carriedItem;
|
|
|
|
public ClientboundContainerSetContentPacket(int containerId, int stateId, NonNullList<ItemStack> items, ItemStack carriedItem) {
|
|
this.containerId = containerId;
|
|
this.stateId = stateId;
|
|
this.items = NonNullList.<ItemStack>withSize(items.size(), ItemStack.EMPTY);
|
|
|
|
for (int i = 0; i < items.size(); i++) {
|
|
this.items.set(i, items.get(i).copy());
|
|
}
|
|
|
|
this.carriedItem = carriedItem.copy();
|
|
}
|
|
|
|
private ClientboundContainerSetContentPacket(RegistryFriendlyByteBuf buffer) {
|
|
this.containerId = buffer.readContainerId();
|
|
this.stateId = buffer.readVarInt();
|
|
this.items = ItemStack.OPTIONAL_LIST_STREAM_CODEC.decode(buffer);
|
|
this.carriedItem = ItemStack.OPTIONAL_STREAM_CODEC.decode(buffer);
|
|
}
|
|
|
|
private void write(RegistryFriendlyByteBuf buffer) {
|
|
buffer.writeContainerId(this.containerId);
|
|
buffer.writeVarInt(this.stateId);
|
|
ItemStack.OPTIONAL_LIST_STREAM_CODEC.encode(buffer, this.items);
|
|
ItemStack.OPTIONAL_STREAM_CODEC.encode(buffer, this.carriedItem);
|
|
}
|
|
|
|
@Override
|
|
public PacketType<ClientboundContainerSetContentPacket> type() {
|
|
return GamePacketTypes.CLIENTBOUND_CONTAINER_SET_CONTENT;
|
|
}
|
|
|
|
/**
|
|
* Passes this Packet on to the NetHandler for processing.
|
|
*/
|
|
public void handle(ClientGamePacketListener handler) {
|
|
handler.handleContainerContent(this);
|
|
}
|
|
|
|
public int getContainerId() {
|
|
return this.containerId;
|
|
}
|
|
|
|
public List<ItemStack> getItems() {
|
|
return this.items;
|
|
}
|
|
|
|
public ItemStack getCarriedItem() {
|
|
return this.carriedItem;
|
|
}
|
|
|
|
public int getStateId() {
|
|
return this.stateId;
|
|
}
|
|
}
|