Commits
md_5 authored a02758acdb5
14 14 | +import org.bukkit.craftbukkit.inventory.CraftItemStack; |
15 15 | +import org.bukkit.event.Event.Result; |
16 16 | +import org.bukkit.event.inventory.InventoryDragEvent; |
17 17 | +import org.bukkit.event.inventory.InventoryType; |
18 18 | +import org.bukkit.inventory.InventoryView; |
19 19 | +// CraftBukkit end |
20 20 | + |
21 21 | public abstract class Container { |
22 22 | |
23 23 | private static final Logger LOGGER = LogUtils.getLogger(); |
24 - | |
24 + | |
25 25 | private ContainerSynchronizer synchronizer; |
26 26 | private boolean suppressRemoteUpdates; |
27 27 | |
28 28 | + // CraftBukkit start |
29 29 | + public boolean checkReachable = true; |
30 30 | + public abstract InventoryView getBukkitView(); |
31 31 | + public void transferTo(Container other, org.bukkit.craftbukkit.entity.CraftHumanEntity player) { |
32 32 | + InventoryView source = this.getBukkitView(), destination = other.getBukkitView(); |
33 33 | + ((CraftInventory) source.getTopInventory()).getInventory().onClose(player); |
34 34 | + ((CraftInventory) source.getBottomInventory()).getInventory().onClose(player); |
37 37 | + } |
38 38 | + private IChatBaseComponent title; |
39 39 | + public final IChatBaseComponent getTitle() { |
40 40 | + Preconditions.checkState(this.title != null, "Title not set"); |
41 41 | + return this.title; |
42 42 | + } |
43 43 | + public final void setTitle(IChatBaseComponent title) { |
44 44 | + Preconditions.checkState(this.title == null, "Title already set"); |
45 45 | + this.title = title; |
46 46 | + } |
47 - | + public void startOpen() {} |
47 + | + protected boolean opened; |
48 + | + public void startOpen() { |
49 + | + this.opened = true; |
50 + | + } |
48 51 | + // CraftBukkit end |
49 52 | + |
50 53 | protected Container(@Nullable Containers<?> containers, int i) { |
51 54 | this.carried = ItemStack.EMPTY; |
52 55 | this.remoteSlots = NonNullList.create(); |
53 - | |
56 + | |
54 57 | |
55 58 | } |
56 59 | |
57 60 | + // CraftBukkit start |
58 61 | + public void broadcastCarriedItem() { |
59 62 | + this.remoteCarried = this.getCarried().copy(); |
60 63 | + if (this.synchronizer != null) { |
61 64 | + this.synchronizer.sendCarriedChange(this, this.remoteCarried); |
62 65 | + } |
63 66 | + } |
64 67 | + // CraftBukkit end |
65 68 | + |
66 69 | public void removeSlotListener(ICrafting icrafting) { |
67 70 | this.containerListeners.remove(icrafting); |
68 71 | } |
69 - | |
72 + | |
70 73 | } |
71 74 | } else if (this.quickcraftStatus == 2) { |
72 75 | if (!this.quickcraftSlots.isEmpty()) { |
73 76 | - if (this.quickcraftSlots.size() == 1) { |
74 77 | + if (false && this.quickcraftSlots.size() == 1) { // CraftBukkit - treat everything as a drag since we are unable to easily call InventoryClickEvent instead |
75 78 | k = ((Slot) this.quickcraftSlots.iterator().next()).index; |
76 79 | this.resetQuickCraft(); |
77 80 | this.doClick(k, this.quickcraftType, InventoryClickType.PICKUP, entityhuman); |
78 - | |
81 + | |
79 82 | l = this.getCarried().getCount(); |
80 83 | Iterator iterator = this.quickcraftSlots.iterator(); |
81 84 | |
82 85 | + Map<Integer, ItemStack> draggedSlots = new HashMap<Integer, ItemStack>(); // CraftBukkit - Store slots from drag in map (raw slot id -> new stack) |
83 86 | while (iterator.hasNext()) { |
84 87 | Slot slot1 = (Slot) iterator.next(); |
85 88 | ItemStack itemstack2 = this.getCarried(); |
86 - | |
89 + | |
87 90 | int l1 = Math.min(getQuickCraftPlaceCount(this.quickcraftSlots, this.quickcraftType, itemstack1) + j1, k1); |
88 91 | |
89 92 | l -= l1 - j1; |
90 93 | - slot1.setByPlayer(itemstack1.copyWithCount(l1)); |
91 94 | + // slot1.setByPlayer(itemstack1.copyWithCount(l1)); |
92 95 | + draggedSlots.put(slot1.index, itemstack1.copyWithCount(l1)); // CraftBukkit - Put in map instead of setting |
93 96 | } |
94 97 | } |
95 98 | |
96 99 | - itemstack1.setCount(l); |
128 131 | + this.setCarried(oldCursor); |
129 132 | + } |
130 133 | + |
131 134 | + if (needsUpdate && entityhuman instanceof EntityPlayer) { |
132 135 | + this.sendAllDataToRemote(); |
133 136 | + } |
134 137 | + // CraftBukkit end |
135 138 | } |
136 139 | |
137 140 | this.resetQuickCraft(); |
138 - | |
141 + | |
139 142 | if (i == -999) { |
140 143 | if (!this.getCarried().isEmpty()) { |
141 144 | if (clickaction == ClickAction.PRIMARY) { |
142 145 | - entityhuman.drop(this.getCarried(), true); |
143 146 | + // CraftBukkit start |
144 147 | + ItemStack carried = this.getCarried(); |
145 148 | this.setCarried(ItemStack.EMPTY); |
146 149 | + entityhuman.drop(carried, true); |
147 150 | + // CraftBukkit start |
148 151 | } else { |
149 152 | entityhuman.drop(this.getCarried().split(1), true); |
150 153 | } |
151 - | |
154 + | |
152 155 | } |
153 156 | |
154 157 | slot.setChanged(); |
155 158 | + // CraftBukkit start - Make sure the client has the right slot contents |
156 159 | + if (entityhuman instanceof EntityPlayer && slot.getMaxStackSize() != IInventory.MAX_STACK) { |
157 160 | + ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutSetSlot(this.containerId, this.incrementStateId(), slot.index, slot.getItem())); |
158 161 | + // Updating a crafting inventory makes the client reset the result slot, have to send it again |
159 162 | + if (this.getBukkitView().getType() == InventoryType.WORKBENCH || this.getBukkitView().getType() == InventoryType.CRAFTING) { |
160 163 | + ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutSetSlot(this.containerId, this.incrementStateId(), 0, this.getSlot(0).getItem())); |
161 164 | + } |
162 165 | + } |
163 166 | + // CraftBukkit end |
164 167 | } |
165 168 | } else { |
166 169 | int j2; |
167 - | |
170 + | |
168 171 | ItemStack itemstack = this.getCarried(); |
169 172 | |
170 173 | if (!itemstack.isEmpty()) { |
171 174 | + this.setCarried(ItemStack.EMPTY); // CraftBukkit - SPIGOT-4556 - from below |
172 175 | dropOrPlaceInInventory(entityhuman, itemstack); |
173 176 | - this.setCarried(ItemStack.EMPTY); |
174 177 | + // this.setCarried(ItemStack.EMPTY); // CraftBukkit - moved up |
175 178 | } |
176 179 | |
177 180 | } |
178 - | |
181 + | |
179 182 | } |
180 183 | |
181 184 | public ItemStack getCarried() { |
182 185 | + // CraftBukkit start |
183 186 | + if (this.carried.isEmpty()) { |
184 187 | + this.setCarried(ItemStack.EMPTY); |
185 188 | + } |
186 189 | + // CraftBukkit end |
187 190 | return this.carried; |
188 191 | } |
189 192 |