SHARE
TWEET

Untitled

a guest May 26th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sortInventoryItems(inv, Material.COAL, Material.COAL_BLOCK);
  2.  
  3. public void sortInventoryItems(Inventory inv, Material toSort, Material after) {
  4.         ItemStack[] items = inv.getContents();
  5.         int amount = 9;
  6.         for (int i = 0; i < items.length; i++) {
  7.             ItemStack is = items[i];
  8.             if (is != null && is.getType() == toSort) {
  9.                 int newamount = is.getAmount() / amount;
  10.                 inv.addItem(new ItemStack(after, newamount));
  11.                 if (newamount > 0) {
  12.                     is.setAmount(newamount);
  13.                     break;
  14.                 } else {
  15.                     items[i] = new ItemStack(Material.AIR);
  16.                     amount = -newamount;
  17.                 }
  18.             }
  19.         }
  20.         inv.setContents(items);
  21.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top