Conversation
There was a problem hiding this comment.
Pull request overview
Adjusts how LunaticStorage updates storage state when a storage container block is broken, aiming to correctly account for items removed from the container at break time.
Changes:
- Add debug logging when a storage container is broken.
- Compute the “removed items” difference based on
BlockDropItemEventdrops rather than the container inventory contents.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| StorageContainer storageContainer = StorageContainer.getStorageContainer(block); | ||
| Map<ItemStack, Integer> difference = Utils.itemStackArrayToMap(storageContainer.getInventory().getContents(), true); | ||
| ItemStack[] contents = event.getItems().stream().map(Item::getItemStack).toArray(ItemStack[]::new); | ||
| Map<ItemStack, Integer> difference = Utils.itemStackArrayToMap(contents, true); |
There was a problem hiding this comment.
contents is derived from event.getItems(), which represents all drops (including the container block item itself) and may be empty/sanitized by gamerules or other plugins. That can cause difference to subtract the wrong items (e.g., remove a CHEST item that was never in the inventory) or fail to subtract anything when drops are suppressed, leaving storage totals inconsistent. Prefer reading the pre-break inventory from event.getBlockState() (cast to Container/Chest and use its inventory snapshot) so the update reflects the container’s actual contents independent of drop behavior.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 10aeeaf447
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ItemStack[] contents = event.getItems().stream().map(Item::getItemStack).toArray(ItemStack[]::new); | ||
| Map<ItemStack, Integer> difference = Utils.itemStackArrayToMap(contents, true); |
There was a problem hiding this comment.
Exclude container block drop when building storage diff
Computing difference from event.getItems() includes every dropped entity from the break, including the storage container block itself, not just the container inventory contents. In updateStorage, that extra item is applied as a negative delta, so breaking a container subtracts one block item (e.g. chest/barrel) from the storage map every time and can even create negative counts when that block type was never stored. This corrupts storage totals and downstream item retrieval behavior for container-break events.
Useful? React with 👍 / 👎.
No description provided.