Skip to content

Respect WorldlyContainer nullability contracts in SidedInvWrapper #1847

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

Merged
merged 4 commits into from
Apr 26, 2025
Merged
Show file tree
Hide file tree
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 @@ -75,20 +75,14 @@ public static void registerVanillaProviders(RegisterCapabilitiesEvent event) {
return new VanillaHopperItemHandler(hopper);
});

event.registerBlockEntity(Capabilities.ItemHandler.BLOCK, BlockEntityType.SHULKER_BOX, (shulkerBox, side) -> {
// Always use sided wrapper for shulker boxes, even for null direction, to call its `canPlaceItemThroughFace` override.
return new SidedInvWrapper(shulkerBox, null);
});

var sidedVanillaContainers = List.of(
BlockEntityType.BLAST_FURNACE,
BlockEntityType.BREWING_STAND,
BlockEntityType.FURNACE,
BlockEntityType.SMOKER);
BlockEntityType.SMOKER,
BlockEntityType.SHULKER_BOX);
for (var type : sidedVanillaContainers) {
event.registerBlockEntity(Capabilities.ItemHandler.BLOCK, type, (sidedContainer, side) -> {
return side == null ? new InvWrapper(sidedContainer) : new SidedInvWrapper(sidedContainer, side);
});
event.registerBlockEntity(Capabilities.ItemHandler.BLOCK, type, SidedInvWrapper::new);
}

var nonSidedVanillaContainers = List.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public SidedInvWrapper(WorldlyContainer inv, @Nullable Direction side) {
}

public static int getSlot(WorldlyContainer inv, int slot, @Nullable Direction side) {
if (side == null) {
return slot;
}
int[] slots = inv.getSlotsForFace(side);
if (slot < slots.length)
return slots[slot];
Expand Down Expand Up @@ -74,6 +77,9 @@ public int hashCode() {

@Override
public int getSlots() {
if (side == null) {
return inv.getContainerSize();
}
return inv.getSlotsForFace(side).length;
}

Expand Down Expand Up @@ -181,7 +187,7 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) {
if (stackInSlot.isEmpty())
return ItemStack.EMPTY;

if (!inv.canTakeItemThroughFace(slot1, stackInSlot, side))
if (side != null && !inv.canTakeItemThroughFace(slot1, stackInSlot, side))
return ItemStack.EMPTY;

if (simulate) {
Expand Down