Remove chest without releasing its content

Hi guys,

I have a chest containing items in a some Location<World> loc and I’d like to remove it without releasing its content. I’ve tried loc.setBlockType(BlockTypes.AIR) but it seems to make the chest “explode”, releasing its content.

That was a little time ago so I’m not sure if it’s still relevant.

Does anyone know a little more about that ?

Try #setBlock(BlockTypes.AIR.getDefaultState())

Your best bet would be to listen for and cancel the DropItemEvents (you’ll probably want to use .Destruct) which will be fired by the chest when it’s broken.

Not sure if this works in Sponge, but in Bukkit i had the same problem. How i got around the issue was checking that the block (in Sponge its location) is a instance of a containerBlock (so, chest, doublechest, furnace, etc.) and then cleared the inventory of that block, after that i set the block to air.

Oh right, I didn’t think about clearing its inventory before removing it ! Although listening to the DropItemEvent would be a good fix, clearing the chest would probably do the job better.

Btw, is there a quick way to see what’s implemented and what’s not in the Inventory API ?

not to my knowledge, however i belive it is just the following (i could be very wrong)

  • CustomInventory
  • Hotbar
  • SidedSlot
  • FuelSlot
  • EquipmentSlot
  • EquipmentInventory
  • CraftingInventory
  • CraftingOutput
1 Like