Chests blocks drop items when setType() is used on them?

Discussion in 'Plugin Development' started by Satros, May 14, 2012.

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

    Satros

    When .setType() is used on a chest block to change it to a different type, it causes all of the items inside the chest block to drop all over. It didn't use to do this but somewhere along the way it changed I guess.

    Anyway to stop the chest from dropping all its items when set to a different type?

    Example of what I'm doing to a chest block location:
    Code:
    getServer().getWorld("world").getBlockAt(block.getLocation()).setTypeId(49);
     
  2. It depends. If you don't want the items to remain, just clear the inventory before that. If you still want the inventory, that's some more work.
     
  3. Offline

    Satros

    It used to work by just saving the state with getState(), and then changing it with setType(). Then I could reset it by setting the state back to what it was. Will that not work anymore?
     
  4. Try it?
     
  5. Offline

    Satros

    That doesn't work anymore. Which is what makes no sense to me. Does block state not contain all the data of the block anymore?

    My algorithm is:
    save block state
    turn block at the location to something else (obsidian for example)
    restore the block state at location (reset the type and raw data back to the original)

    It used to work, but now all the stuff drops out when it turns into obsidian and when I restore the block state the chest is empty.
     
  6. Hm... I'm parsing the data and possible contents into a string because I need to save it in a database and then parse it back to restore the original state which works fine.
    Did you check before the restoring part if the saved state is still containing the items or are they already gone?
     
Thread Status:
Not open for further replies.

Share This Page