Im currently creating a plugin which utilizes dispensers. I have a while loop during a listener that should remove one piece of coal from the inventory of the dispenser until there is none left on which the loop will break. It loops fine and registers the counting down of a integer used to reprosent the coal quatity. However the inventory of the dispenser doesnt not update and any help would be much appreciated. Here is the code contained in the while loop
Block temp;
int coal;
BlockState state = block.getState();
Inventory sourceInv = ((InventoryHolder) state).getInventory();
while (sourceInv.contains(Material.COAL))
{
state.update();
temp = drillSpenser.getBlock().getRelative(BlockFace.DOWN);
temp.breakNaturally();
int index = sourceInv.first(Material.COAL);
ItemStack stack = sourceInv.getItem(index);
coal = stack.getAmount();
System.out.println(coal);
if (coal == 0)
{
sourceInv.remove(Material.COAL);
break;
}
coal--;
ItemStack newItem = new ItemStack(Material.COAL, coal);
sourceInv.remove(Material.COAL);
sourceInv.addItem(newItem);
state.update();
block.getState().update();
}
}