1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-27 16:02:17 +00:00

Fix finding inventories below y=0.

Thankfully, the surface level of redstone ready flat worlds is now below
y=0 or, I wouldn't have noticed.

I reformatted some things to keep the diffs down against CC-Tweaked.
It might be nicer to make this return an ItemStorage as most
places we grab the Container and immediately wrap it.
This commit is contained in:
Toad-Dev 2021-12-16 18:52:22 -08:00
parent 6ad2cdaf62
commit 7b3537761b

View File

@ -42,27 +42,20 @@ public final class InventoryUtil
public static Container getInventory( Level world, BlockPos pos, Direction side )
{
// Look for tile with inventory
int y = pos.getY();
if( y >= 0 && y < world.getHeight() )
BlockEntity tileEntity = world.getBlockEntity( pos );
if( tileEntity != null )
{
// Check if block is InventoryProvider
BlockState blockState = world.getBlockState( pos );
Block block = blockState.getBlock();
if( block instanceof WorldlyContainerHolder containerHolder )
Container inventory = getInventory( tileEntity );
if( inventory != null )
{
return containerHolder.getContainer( blockState, world, pos );
return inventory;
}
// Check if block is BlockEntity w/ Inventory
if( blockState.hasBlockEntity() )
{
BlockEntity tileEntity = world.getBlockEntity( pos );
}
Container inventory = getInventory( tileEntity );
if( inventory != null )
{
return inventory;
}
}
BlockState block = world.getBlockState( pos );
if( block.getBlock() instanceof WorldlyContainerHolder containerHolder )
{
return containerHolder.getContainer( block, world, pos );
}
// Look for entity with inventory
@ -97,9 +90,9 @@ public final class InventoryUtil
if( tileEntity instanceof Container )
{
Container inventory = (Container) tileEntity;
if( inventory instanceof ChestBlockEntity && block instanceof ChestBlock )
if( inventory instanceof ChestBlockEntity && block instanceof ChestBlock chestBlock )
{
return ChestBlock.getContainer( (ChestBlock) block, blockState, world, pos, true );
return ChestBlock.getContainer( chestBlock, blockState, world, pos, true );
}
return inventory;
}