Search in sources :

Example 1 with VirtualStack

use of com.almuradev.almura.shared.item.VirtualStack in project Almura by AlmuraDev.

the class ServerboundListItemsRequestPacket method writeTo.

@Override
public void writeTo(final ChannelBuf buf) {
    checkNotNull(this.id);
    checkNotNull(this.actions);
    checkState(!this.actions.isEmpty());
    buf.writeString(this.id);
    buf.writeInteger(this.actions.size());
    for (final InventoryAction action : this.actions) {
        final VirtualStack stack = action.getStack();
        final ResourceLocation location = stack.getItem().getRegistryName();
        if (location == null) {
            new IOException("Malformed resource location for Item '" + stack + "' when sending list item!").printStackTrace();
            continue;
        }
        final NBTTagCompound compound = stack.getCompound();
        byte[] compoundData = null;
        if (compound != null) {
            try {
                compoundData = SerializationUtil.toBytes(compound);
            } catch (IOException e) {
                e.printStackTrace();
                continue;
            }
        }
        buf.writeString(action.getDirection().name().toUpperCase());
        buf.writeString(location.getNamespace());
        buf.writeString(location.getPath());
        buf.writeInteger(stack.getQuantity());
        buf.writeInteger(stack.getMetadata());
        if (compoundData == null) {
            buf.writeInteger(0);
        } else {
            buf.writeInteger(compoundData.length);
            buf.writeBytes(compoundData);
        }
    }
}
Also used : VirtualStack(com.almuradev.almura.shared.item.VirtualStack) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException) InventoryAction(com.almuradev.almura.feature.exchange.InventoryAction)

Aggregations

InventoryAction (com.almuradev.almura.feature.exchange.InventoryAction)1 VirtualStack (com.almuradev.almura.shared.item.VirtualStack)1 IOException (java.io.IOException)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 ResourceLocation (net.minecraft.util.ResourceLocation)1