Skip to content

InventoryMoveItemEvent: First stack in an inventory returns amount 1 even if stack is bigger #9028

@SebiTimeWaster

Description

@SebiTimeWaster

Expected behavior

All stack sizes in an inventory are correctly counted.

Observed/Actual behavior

Given an hopper inventory with the following iron stacks: 0 64 0 0 0 - The amount of items in all stacks combined returns 1.
Given an hopper inventory with the following iron stacks: 64 0 0 0 0 - The amount of items in all stacks combined returns 1.
Given an hopper inventory with the following iron stacks: 0 0 0 0 64 - The amount of items in all stacks combined returns 1.
Given an hopper inventory with the following iron stacks: 0 64 0 32 0 - The amount of items in all stacks combined returns 33.
Given an hopper inventory with the following iron stacks: 0 32 0 64 0 - The amount of items in all stacks combined returns 65.

The amount of items in the stack of the first non-empty inventory slot is always counted as 1.

This also affects Inventory.contains, Inventory.containsAtLeast and Inventory.removeItem, since they also count the stack sizes.

This bug probably only happens in an InventoryMoveItemEvent, i did not test it outside of this event.

Steps/models to reproduce

Count the inventory of a hopper in an InventoryMoveItemEvent:

ItemStack[] stacks = YOUR_INVENTORY.getContents();
Integer amount = 0;

for (Integer j = 0; j < stacks.length; j++) {
    if (stacks[j] != null) amount += stacks[j].getAmount();
}

System.out.println(amount);

Plugin and Datapack List

none, fresh install (my plugin)

Paper version

This server is running Paper version git-Paper-466 (MC: 1.19.4) (Implementing API version 1.19.4-R0.1-SNAPSHOT) (Git: 7af4cd3)
You are running the latest version

Other

i think this bug report is related, but i may be wrong on that account: #8806

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: acceptedDisputed bug is accepted as valid or Feature accepted as desired to be added.type: bugSomething doesn't work as it was intended to.version: 1.19Game version 1.19

    Type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions