use of net.minecraft.block.InventoryProvider in project lithium-fabric by CaffeineMC.
the class HopperHelper method vanillaGetBlockInventory.
/**
* Gets the block inventory at the given position, exactly like vanilla gets it.
* Needed because we don't want to search for entity inventories like the vanilla method does.
*
* @param world world we are searching in
* @param blockPos position of the block inventory
* @return the block inventory at the given position
*/
@Nullable
public static Inventory vanillaGetBlockInventory(World world, BlockPos blockPos) {
// [VanillaCopy]
Inventory inventory = null;
BlockState blockState = world.getBlockState(blockPos);
Block block = blockState.getBlock();
if (block instanceof InventoryProvider) {
inventory = ((InventoryProvider) block).getInventory(blockState, world, blockPos);
} else if (blockState.hasBlockEntity()) {
BlockEntity blockEntity = world.getBlockEntity(blockPos);
if (blockEntity instanceof Inventory) {
inventory = (Inventory) blockEntity;
if (inventory instanceof ChestBlockEntity && block instanceof ChestBlock) {
inventory = ChestBlock.getInventory((ChestBlock) block, blockState, world, blockPos, true);
}
}
}
return inventory;
}
Aggregations