RuneHive-Game
Loading...
Searching...
No Matches
SendItemOnInterface.java
Go to the documentation of this file.
1package com.runehive.net.packet.out;
2
3import com.runehive.game.world.InterfaceConstants;
4import com.runehive.game.world.entity.mob.player.Player;
5import com.runehive.game.world.items.Item;
6import com.runehive.net.packet.OutgoingPacket;
7import com.runehive.net.packet.PacketType;
8
9public class SendItemOnInterface extends OutgoingPacket {
10
11 private final int id;
12 private final Item[] items;
13 private final int[] tabAmounts;
14
15 public SendItemOnInterface(int id) {
16 this(id, null, new Item[]{});
17 }
18
19 public SendItemOnInterface(int id, Item... items) {
20 this(id, null, items);
21 }
22
23 public SendItemOnInterface(int id, int[] tabAmounts, Item... items) {
24 super(53, PacketType.VAR_SHORT);
25 this.id = id;
26 this.items = items;
27 this.tabAmounts = tabAmounts;
28 }
29
30 @Override
31 public boolean encode(Player player) {
32 final boolean sendTabs = id == InterfaceConstants.WITHDRAW_BANK && tabAmounts != null;
33 builder.writeInt(id)
34 .writeShort(items.length)
35 .writeShort(sendTabs ? tabAmounts.length : 0);
36 for (final Item item : items) {
37 if (item != null) {
38 final int amount = item.getAmount();
39 if (amount > 254) {
40 builder.writeByte(255)
41 .writeInt(amount);
42 } else {
43 builder.writeByte(amount);
44 }
45 builder.writeShort(item.getId() + 1);
46 } else {
47 builder.writeByte(0)
48 .writeShort(0);
49 }
50 }
51
52 if (sendTabs) {
53 for (final int amount : tabAmounts) {
54 builder.writeInt(amount);
55 }
56 }
57 return true;
58 }
59}
This class represents a character controlled by a player.
Definition Player.java:125
The container class that represents an item that can be interacted with.
Definition Item.java:21
OutgoingPacket(int opcode, int capacity)
SendItemOnInterface(int id, int[] tabAmounts, Item... items)
Represents a type of packet.
VAR_SHORT
A variable packet where the size is indicated by a short.