From e266ccbcc3800f19024611a562eb982d4a875898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Mon, 6 Jan 2014 01:00:51 +0100 Subject: [PATCH] added checks for invalid coordinates when fetching tile entities for neighbors, fixes #63 --- li/cil/oc/common/block/Cable.scala | 3 ++- li/cil/oc/common/block/RobotAfterimage.scala | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/li/cil/oc/common/block/Cable.scala b/li/cil/oc/common/block/Cable.scala index 774dcc772..7432fc5e9 100644 --- a/li/cil/oc/common/block/Cable.scala +++ b/li/cil/oc/common/block/Cable.scala @@ -91,7 +91,8 @@ object Cable { def neighbors(world: IBlockAccess, x: Int, y: Int, z: Int) = { var result = 0 for (side <- ForgeDirection.VALID_DIRECTIONS) { - world.getBlockTileEntity(x + side.offsetX, y + side.offsetY, z + side.offsetZ) match { + val (tx, ty, tz) = (x + side.offsetX, y + side.offsetY, z + side.offsetZ) + if (world.getBlockId(tx, ty, tz) != 0) world.getBlockTileEntity(tx, ty, tz) match { case robot: tileentity.RobotProxy => case host: SidedEnvironment => val connects = if (host.getWorldObj.isRemote) host.canConnect(side.getOpposite) else host.sidedNode(side.getOpposite) != null diff --git a/li/cil/oc/common/block/RobotAfterimage.scala b/li/cil/oc/common/block/RobotAfterimage.scala index 1e55a8ea9..2424330eb 100644 --- a/li/cil/oc/common/block/RobotAfterimage.scala +++ b/li/cil/oc/common/block/RobotAfterimage.scala @@ -101,7 +101,8 @@ class RobotAfterimage(val parent: SpecialDelegator) extends SpecialDelegate { def findMovingRobot(world: IBlockAccess, x: Int, y: Int, z: Int): Option[tileentity.Robot] = { for (side <- ForgeDirection.VALID_DIRECTIONS) { - world.getBlockTileEntity(x + side.offsetX, y + side.offsetY, z + side.offsetZ) match { + val (tx, ty, tz) = (x + side.offsetX, y + side.offsetY, z + side.offsetZ) + if (world.getBlockId(tx, ty, tz) != 0) world.getBlockTileEntity(tx, ty, tz) match { case proxy: tileentity.RobotProxy if proxy.robot.moveFromX == x && proxy.robot.moveFromY == y && proxy.robot.moveFromZ == z => return Some(proxy.robot) case _ => }