RuneHive-Game
Loading...
Searching...
No Matches
SendItemOnInterfaceSlot.java
Go to the documentation of this file.
1package com.runehive.net.packet.out;
2
3import com.runehive.game.world.entity.mob.player.Player;
4import com.runehive.game.world.items.Item;
5import com.runehive.net.packet.OutgoingPacket;
6import com.runehive.net.packet.PacketType;
7
9 private final int interfaceId;
10 private final Item item;
11 private final int slot;
12
14 this(interfaceId, new Item(item, 1), slot);
15 }
16
17 public SendItemOnInterfaceSlot(int interfaceId, int item, int amount, int slot) {
18 this(interfaceId, new Item(item, amount), slot);
19 }
20
22 super(34, PacketType.VAR_SHORT);
23 this.interfaceId = interfaceId;
24 this.item = item;
25 this.slot = slot;
26 }
27
28 @Override
29 public boolean encode(Player player) {
30 builder.writeShort(interfaceId);
31 builder.writeShort(slot);
32 if (item == null) {
33 builder.writeShort(0);
34 builder.writeByte(0);
35 } else {
36 builder.writeShort(item.getId() + 1);
37 final int amount = item.getAmount();
38 if (amount > 254) {
39 builder.writeByte(255);
40 builder.writeInt(amount);
41 } else {
42 builder.writeByte(amount);
43 }
44 }
45 return true;
46 }
47
48}
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)
SendItemOnInterfaceSlot(int interfaceId, int item, int amount, int slot)
SendItemOnInterfaceSlot(int interfaceId, int item, int slot)
SendItemOnInterfaceSlot(int interfaceId, Item item, int slot)
Represents a type of packet.
VAR_SHORT
A variable packet where the size is indicated by a short.