int x = b.getX();
int y = b.getY() + 1;
int z = b.getZ();
Block bl = BukkitUtil.toSign(getSign()).getBlock().getWorld().getBlockAt(x, y, z);
if (InventoryUtil.doesBlockHaveInventory(bl)) {
InventoryHolder c = (InventoryHolder) bl.getState();
for (int i = 0; i < c.getInventory().getSize(); i++) {
ItemStack it = c.getInventory().getItem(i);
if (ItemUtil.isStackValid(it)) {
if(((Factory)getFactory()).blacklist.contains(new ItemInfo(it)))
continue;
int amount = it.getAmount();
if (it.getAmount() < 64) {
int missing = 0;
for (int ii = 0; ii < c.getInventory().getSize(); ii++) {
if (ii == i)
continue;
ItemStack itt = c.getInventory().getItem(ii);
if (ItemUtil.isStackValid(itt) && ItemUtil.areItemsIdentical(it, itt) && it.getEnchantments().isEmpty() && !itt.getEnchantments().isEmpty() && !it.hasItemMeta() && !itt.hasItemMeta()) {
if (amount + itt.getAmount() <= 64) {
amount += itt.getAmount();
} else {
missing = amount + itt.getAmount() - 64;
amount = 64;
}
c.getInventory().remove(itt);
}
}
if (amount != it.getAmount()) {
it.setAmount(amount);
c.getInventory().setItem(i, it);
break;
}
if(missing > 0) {
ItemStack miss = new ItemStack(it);
miss.setAmount(missing);
c.getInventory().addItem(miss);
}
}
}
}
}