protected static List<Entry<ItemStack, Integer>> getChangesClick(InventoryClickEvent event) { // Create List<Entry<ItemStack, Integer>> ret = new MassiveList<>(); // Fill final InventoryAlter alter = InventoryUtil.getAlter(event); final InventoryAction action = event.getAction(); ItemStack item; int amount; // Give if (alter.isGiving()) { // Special > MOVE_TO_OTHER_INVENTORY if (action == InventoryAction.MOVE_TO_OTHER_INVENTORY) { item = event.getCurrentItem(); ItemStack compare = item.clone(); compare.setAmount(1); amount = InventoryUtil.roomLeft(event.getInventory(), compare, item.getAmount()); } // Special > HOTBAR_SWAP else if (action == InventoryAction.HOTBAR_SWAP) { item = event.getView().getBottomInventory().getItem(event.getHotbarButton()); amount = item.getAmount(); } // Normal else { item = event.getCursor(); amount = item.getAmount(); if (action == InventoryAction.PLACE_ONE) { amount = 1; } else if (action == InventoryAction.PLACE_SOME) { int max = event.getCurrentItem().getType().getMaxStackSize(); amount = max - event.getCurrentItem().getAmount(); } } amount *= -1; ret.add(new SimpleEntry<ItemStack, Integer>(item, amount)); } // Take if (alter.isTaking()) { item = event.getCurrentItem(); amount = item.getAmount(); if (action == InventoryAction.PICKUP_ONE) amount = 1; if (action == InventoryAction.PICKUP_HALF) amount = (int) Math.ceil(amount / 2.0); ret.add(new SimpleEntry<ItemStack, Integer>(item, amount)); } // Return return ret; }
// Drag events by nature only matters when they affect the top inventory. // What you are holding in the cursor is already yours. // If you drag it into your own inventory you are not really taking anything. // If you drag into the top inventory however, you may both give and take. // You "take" by dragging over an existing item (since we don't do any math). protected static List<Entry<ItemStack, Integer>> getChangesDrag(InventoryDragEvent event) { // Create List<Entry<ItemStack, Integer>> ret = new MassiveList<>(); // Fill final Inventory inventory = event.getInventory(); for (Entry<Integer, ItemStack> entry : event.getNewItems().entrySet()) { int rawSlot = entry.getKey(); if (InventoryUtil.isBottomInventory(rawSlot, inventory)) continue; ItemStack take = inventory.getItem(rawSlot); if (isSomething(take)) ret.add(new SimpleEntry<ItemStack, Integer>(take, +take.getAmount())); ItemStack give = entry.getValue(); if (isSomething(give)) ret.add(new SimpleEntry<ItemStack, Integer>(give, -give.getAmount())); } // Return return ret; }