From e0d95dcac3e1cb4a31d878366918ed4ceb1c8555 Mon Sep 17 00:00:00 2001 From: Shad0wlife Date: Wed, 30 Oct 2019 16:30:12 +0100 Subject: [PATCH] Change height checks to integrated MC method This effectively still checks if its 0<=y<256, just as separate checks for 0 and world.getHeight() would do. But by using this, mods like CubicChunks which modify the height limits can change the result of the world.isOutsideBuildHeight() for easy compatibility. --- .../shared/turtle/core/TurtleMoveCommand.java | 8 ++------ .../dan200/computercraft/shared/util/InventoryUtil.java | 3 +-- .../java/dan200/computercraft/shared/util/WorldUtil.java | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleMoveCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleMoveCommand.java index cadc8b73ec..366e90d115 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleMoveCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleMoveCommand.java @@ -150,13 +150,9 @@ public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) private TurtleCommandResult canEnter( TurtlePlayer turtlePlayer, World world, BlockPos position ) { - if( position.getY() < 0 ) + if( world.isOutsideBuildHeight( position ) ) { - return TurtleCommandResult.failure( "Too low to move" ); - } - else if( position.getY() > world.getHeight() - 1 ) - { - return TurtleCommandResult.failure( "Too high to move" ); + return TurtleCommandResult.failure( "Move would be outside world height." ); } if( ComputerCraft.turtlesObeyBlockProtection ) { diff --git a/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java b/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java index f7e808a449..8a4daa1dff 100644 --- a/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java @@ -49,8 +49,7 @@ public static ItemStack copyItem( @Nonnull ItemStack a ) public static IItemHandler getInventory( World world, BlockPos pos, EnumFacing side ) { // Look for tile with inventory - int y = pos.getY(); - if( y >= 0 && y < world.getHeight() ) + if( !world.isOutsideBuildHeight( pos ) ) { TileEntity tileEntity = world.getTileEntity( pos ); if( tileEntity != null ) diff --git a/src/main/java/dan200/computercraft/shared/util/WorldUtil.java b/src/main/java/dan200/computercraft/shared/util/WorldUtil.java index ff7289a4df..a84483ff84 100644 --- a/src/main/java/dan200/computercraft/shared/util/WorldUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/WorldUtil.java @@ -21,7 +21,7 @@ public class WorldUtil { public static boolean isBlockInWorld( World world, BlockPos pos ) { - return pos.getY() >= 0 && pos.getY() < world.getHeight(); + return !world.isOutsideBuildHeight( pos ); } public static boolean isLiquidBlock( World world, BlockPos pos )