Skip to content

Incorrect null contracts in SidedInvWrapper #1840

@Shadows-of-Fire

Description

@Shadows-of-Fire

SidedInvWrapper is a capability wrapper for WorldlyContainer, a vanilla interface with the following definition:

public interface WorldlyContainer extends Container {
    int[] getSlotsForFace(Direction side);

    boolean canPlaceItemThroughFace(int index, ItemStack itemStack, @Nullable Direction direction);

    boolean canTakeItemThroughFace(int index, ItemStack stack, Direction direction);
}

As a capability wrapper for the IItemHandler capability, SidedInvWrapper directly accepts a null Direction and passes it through to these methods, which is illegal in two of three cases.

These erroneous calls are in SidedInvWrapper.getSlot and SidedInvWrapper#extractItem. In both cases, SidedInvWrapper needs to fallback to the equivalent behavior from InvWrapper when the direction is null.

This behavior has gone unnoticed for quite a while, simply because none of the vanilla implementation crash when passed null values. This does not change the fact that this is a bug in SidedInvWrapper.

Metadata

Metadata

Assignees

No one assigned

    Labels

    1.20.1Targeted at Minecraft 1.20.11.21.1Targeted at Minecraft 1.21.11.21.4Targeted at Minecraft 1.21.4bugA bug or error

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions