Clearing Items in a chest, then re-setting them

Discussion in 'Plugin Development' started by orange451, Jan 7, 2013.

Thread Status:
Not open for further replies.
  1. Offline


    I've been trying to clear a chest's items, then restock the chest with new items. Now this creates a problem. I can clear the chest fine, but if I set the chests items RIGHT after clearing it, all of the previous items fly out of the chest as if someone had broken it.

    I use these two methods for clearing the chest (both create the same problem):
    ItemStack[] contents = new ItemStack[chest.getInventory().getSize()];
    I don't think the clearing is the problem. I believe that craftbukkit doesn't realize the chest was cleared when I add items to the chest after clearing.

    What do you think the problem is?
  2. Offline


    add chest.update() after you clear the inventories. If that method doesn't exist then it would be block.getState().update() but I think chest is a BlockState so you should be fine with it.
  3. Offline


    Chest extends BlockState, so it definitely has the update() method ;3. Besides, block.getState().update() might not update it correctly (as you edited the BlockState chest)
  4. Offline


    Even when using .update, or when using .update(true) the items still fly out as if it did nothing.
  5. Offline


    I still haven't solved the problem. Anyone?
  6. Offline


    Turns out I overlooked your hypothesis. I was just using the BlockState object, and updating that. Once casted to a chest (and using .update), the problem went away. Thank you.
Thread Status:
Not open for further replies.

Share This Page