mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-08-30 00:57:55 +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:
@@ -42,27 +42,20 @@ public final class InventoryUtil
|
|||||||
public static Container getInventory( Level world, BlockPos pos, Direction side )
|
public static Container getInventory( Level world, BlockPos pos, Direction side )
|
||||||
{
|
{
|
||||||
// Look for tile with inventory
|
// Look for tile with inventory
|
||||||
int y = pos.getY();
|
BlockEntity tileEntity = world.getBlockEntity( pos );
|
||||||
if( y >= 0 && y < world.getHeight() )
|
if( tileEntity != null )
|
||||||
{
|
{
|
||||||
// Check if block is InventoryProvider
|
Container inventory = getInventory( tileEntity );
|
||||||
BlockState blockState = world.getBlockState( pos );
|
if( inventory != null )
|
||||||
Block block = blockState.getBlock();
|
|
||||||
if( block instanceof WorldlyContainerHolder containerHolder )
|
|
||||||
{
|
{
|
||||||
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 );
|
BlockState block = world.getBlockState( pos );
|
||||||
if( inventory != null )
|
if( block.getBlock() instanceof WorldlyContainerHolder containerHolder )
|
||||||
{
|
{
|
||||||
return inventory;
|
return containerHolder.getContainer( block, world, pos );
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for entity with inventory
|
// Look for entity with inventory
|
||||||
@@ -97,9 +90,9 @@ public final class InventoryUtil
|
|||||||
if( tileEntity instanceof Container )
|
if( tileEntity instanceof Container )
|
||||||
{
|
{
|
||||||
Container inventory = (Container) tileEntity;
|
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;
|
return inventory;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user