RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
SendItemOnInterface.java
1package com.osroyale.net.packet.out;
2
3import com.osroyale.game.world.InterfaceConstants;
4import com.osroyale.game.world.entity.mob.player.Player;
5import com.osroyale.game.world.items.Item;
6import com.osroyale.net.packet.OutgoingPacket;
7import com.osroyale.net.packet.PacketType;
8
32
33public class SendItemOnInterface extends OutgoingPacket {
34
35 private final int id;
36 private final Item[] items;
37 private final int[] tabAmounts;
38
39 public SendItemOnInterface(int id) {
40 this(id, null, new Item[]{});
41 }
42
43 public SendItemOnInterface(int id, Item... items) {
44 this(id, null, items);
45 }
46
47 public SendItemOnInterface(int id, int[] tabAmounts, Item... items) {
48 super(53, PacketType.VAR_SHORT);
49 this.id = id;
50 this.items = items;
51 this.tabAmounts = tabAmounts;
52 }
53
54 @Override
55 public boolean encode(Player player) {
56 final boolean sendTabs = id == InterfaceConstants.WITHDRAW_BANK && tabAmounts != null;
57 builder.writeInt(id)
58 .writeShort(items.length)
59 .writeShort(sendTabs ? tabAmounts.length : 0);
60 for (final Item item : items) {
61 if (item != null) {
62 final int amount = item.getAmount();
63 if (amount > 254) {
64 builder.writeByte(255)
65 .writeInt(amount);
66 } else {
67 builder.writeByte(amount);
68 }
69 builder.writeShort(item.getId() + 1);
70 } else {
71 builder.writeByte(0)
72 .writeShort(0);
73 }
74 }
75
76 if (sendTabs) {
77 for (final int amount : tabAmounts) {
78 builder.writeInt(amount);
79 }
80 }
81 return true;
82 }
83}