-
Notifications
You must be signed in to change notification settings - Fork 2
Fix container break #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
|
|
||
| import java.util.*; | ||
|
|
||
| import static de.janschuri.lunaticstorage.LunaticStorage.sendDebugMessage; | ||
| import static de.janschuri.lunaticstorage.config.LanguageConfig.getShutdownMessage; | ||
|
|
||
| public class BlockBreakListener implements Listener { | ||
|
|
@@ -137,10 +138,12 @@ public void onBlockDrop(BlockDropItemEvent event) { | |
| } | ||
|
|
||
| if (Utils.isStorageContainer(block)) { | ||
| sendDebugMessage(block.getLocation(), "Storage container broken at " + block.getLocation().getX() + " " + block.getLocation().getY() + " " + block.getLocation().getZ()); | ||
| PersistentDataContainer dataContainer = new CustomBlockData(block, LunaticStorage.getInstance()); | ||
|
|
||
| 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); | ||
|
Comment on lines
+145
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Computing Useful? React with 👍 / 👎. |
||
| storageContainer.updateStorages(difference); | ||
|
|
||
| dataContainer.remove(Key.STORAGE_CONTAINER); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contentsis derived fromevent.getItems(), which represents all drops (including the container block item itself) and may be empty/sanitized by gamerules or other plugins. That can causedifferenceto 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 fromevent.getBlockState()(cast toContainer/Chestand use its inventory snapshot) so the update reflects the container’s actual contents independent of drop behavior.