From 7b3537761b54442792e7ce6adbcd0baada2b1a4a Mon Sep 17 00:00:00 2001 From: Toad-Dev <748280+Toad-Dev@users.noreply.github.com> Date: Thu, 16 Dec 2021 18:52:22 -0800 Subject: [PATCH] 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. --- .../shared/util/InventoryUtil.java | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java b/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java index 5b39ffbdb..36cd0a2be 100644 --- a/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java @@ -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; }