Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 144 to +146
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +145 to +146
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

storageContainer.updateStorages(difference);

dataContainer.remove(Key.STORAGE_CONTAINER);
Expand Down