Commits
pokechu22 authored and md_5 committed 17ec944682d
1 1 | package org.bukkit.inventory; |
2 2 | |
3 - | import org.bukkit.GameMode; |
4 3 | import org.bukkit.entity.HumanEntity; |
5 4 | import org.bukkit.event.inventory.InventoryType; |
6 5 | |
7 6 | /** |
8 7 | * Represents a view linking two inventories and a single player (whose |
9 8 | * inventory may or may not be one of the two). |
10 9 | * <p> |
11 10 | * Note: If you implement this interface but fail to satisfy the expected |
12 11 | * contracts of certain methods, there's no guarantee that the game will work |
13 12 | * as it should. |
221 220 | public final int convertSlot(int rawSlot) { |
222 221 | int numInTop = getTopInventory().getSize(); |
223 222 | // Index from the top inventory as having slots from [0,size] |
224 223 | if (rawSlot < numInTop) { |
225 224 | return rawSlot; |
226 225 | } |
227 226 | |
228 227 | // Move down the slot index by the top size |
229 228 | int slot = rawSlot - numInTop; |
230 229 | |
231 - | // Creative mode players have one contiguous inventory dictated by the client |
232 - | if (getPlayer().getGameMode() == GameMode.CREATIVE && getType() == InventoryType.PLAYER) { |
233 - | return slot; |
234 - | } |
235 - | |
236 230 | // Player crafting slots are indexed differently. The matrix is caught by the first return. |
237 - | if (getType() == InventoryType.CRAFTING) { |
231 + | // Creative mode is the same, except that you can't see the crafting slots (but the IDs are still used) |
232 + | if (getType() == InventoryType.CRAFTING || getType() == InventoryType.CREATIVE) { |
238 233 | /** |
239 234 | * Raw Slots: |
240 235 | * |
241 236 | * 5 1 2 0 |
242 237 | * 6 3 4 |
243 238 | * 7 |
244 239 | * 8 45 |
245 240 | * 9 10 11 12 13 14 15 16 17 |
246 241 | * 18 19 20 21 22 23 24 25 26 |
247 242 | * 27 28 29 30 31 32 33 34 35 |
248 243 | * 36 37 38 39 40 41 42 43 44 |
249 244 | */ |
250 - | |
245 + | |
251 246 | /** |
252 247 | * Converted Slots: |
253 248 | * |
254 249 | * 39 1 2 0 |
255 250 | * 38 3 4 |
256 251 | * 37 |
257 252 | * 36 40 |
258 253 | * 9 10 11 12 13 14 15 16 17 |
259 254 | * 18 19 20 21 22 23 24 25 26 |
260 255 | * 27 28 29 30 31 32 33 34 35 |