@Override
  public GamePacket encode(UpdateSlottedItemsEvent event) {
    GamePacketBuilder builder = new GamePacketBuilder(134, PacketType.VARIABLE_SHORT);
    SlottedItem[] items = event.getSlottedItems();

    builder.put(DataType.SHORT, event.getInterfaceId());

    for (SlottedItem slottedItem : items) {
      builder.putSmart(slottedItem.getSlot());

      Item item = slottedItem.getItem();
      int id = item == null ? -1 : item.getId();
      int amount = item == null ? 0 : item.getAmount();

      builder.put(DataType.SHORT, id + 1);

      if (amount > 254) {
        builder.put(DataType.BYTE, 255);
        builder.put(DataType.INT, amount);
      } else {
        builder.put(DataType.BYTE, amount);
      }
    }

    return builder.toGamePacket();
  }
Exemplo n.º 2
0
 /**
  * Gets the amount of the item.
  *
  * @return The amount.
  */
 public int getAmount() {
   return item.getAmount();
 }