Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sortInventoryItems(inv, Material.COAL, Material.COAL_BLOCK);
- public void sortInventoryItems(Inventory inv, Material toSort, Material after) {
- ItemStack[] items = inv.getContents();
- int amount = 9;
- for (int i = 0; i < items.length; i++) {
- ItemStack is = items[i];
- if (is != null && is.getType() == toSort) {
- int newamount = is.getAmount() / amount;
- inv.addItem(new ItemStack(after, newamount));
- if (newamount > 0) {
- is.setAmount(newamount);
- break;
- } else {
- items[i] = new ItemStack(Material.AIR);
- amount = -newamount;
- }
- }
- }
- inv.setContents(items);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement