Removing ItemStack from chest

Hello. I need to remove specific amount of item stack with specific type from a chest.

Given: ItemStack and chest location (already checked for errors).

I wrote that code but now I am stuck:

Chest chest = (Chest) location.getTileEntity().get();

ItemStack stack = ItemStack.builder().itemType(type).quantity(amount).build();

Now I need to remove stack from chest and save the block state with new inventory contents.

I migrated from Bukkit, where I could just do:

inventory.remove(stack);

Seems that there is no such method in Sponge. How should I do? Also, I would really appreciate if someone had given me a tip how to correctly update the block state with new inventory.

Regards,
MrOnlineCoder

Try inventory.query(QueryOperationTypes.ITEM_STACK_IGNORE_QUANTITY.of(stack)).poll(amount).

1 Like

Thanks. Now how I can apply theese updates to a block state (chest)?

Hah, I discovered that your code directly changes inventory, no need to change block state!