From b3ea58c96b558efd4d8d552addb822db5adb7978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Fri, 18 Apr 2014 14:06:45 +0200 Subject: [PATCH] Fixed NPE in robot.use(). Fixed undirected robot commands leading to unexpected results (in particular place, which can place blocks in "adjacent" blocks if the block is replaceable), always testing into the primary facing direction first now. --- .../scala/li/cil/oc/server/component/robot/Player.scala | 2 +- .../scala/li/cil/oc/server/component/robot/Robot.scala | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/scala/li/cil/oc/server/component/robot/Player.scala b/src/main/scala/li/cil/oc/server/component/robot/Player.scala index 57af9f22b..7a6cb7357 100644 --- a/src/main/scala/li/cil/oc/server/component/robot/Player.scala +++ b/src/main/scala/li/cil/oc/server/component/robot/Player.scala @@ -306,7 +306,7 @@ class Player(val robot: tileentity.Robot) extends EntityPlayer(robot.world, Sett }) } - private def isItemUseAllowed(stack: ItemStack) = { + private def isItemUseAllowed(stack: ItemStack) = stack == null || { (Settings.get.allowUseItemsWithDuration || stack.getMaxItemUseDuration <= 0) && (!PortalGun.isPortalGun(stack) || PortalGun.isStandardPortalGun(stack)) && !stack.isItemEqual(new ItemStack(Item.leash)) diff --git a/src/main/scala/li/cil/oc/server/component/robot/Robot.scala b/src/main/scala/li/cil/oc/server/component/robot/Robot.scala index 882c7ed0d..49af11d60 100644 --- a/src/main/scala/li/cil/oc/server/component/robot/Robot.scala +++ b/src/main/scala/li/cil/oc/server/component/robot/Robot.scala @@ -231,7 +231,8 @@ class Robot(val robot: tileentity.Robot) extends ManagedComponent { Iterable(checkSideForFace(args, 1, facing)) } else { - ForgeDirection.VALID_DIRECTIONS.filter(_ != facing.getOpposite).toIterable + // Always try the direction we're looking first. + Iterable(facing) ++ ForgeDirection.VALID_DIRECTIONS.filter(side => side != facing && side != facing.getOpposite).toIterable } val sneaky = args.isBoolean(2) && args.checkBoolean(2) val stack = player.robotInventory.selectedItemStack @@ -337,7 +338,8 @@ class Robot(val robot: tileentity.Robot) extends ManagedComponent { Iterable(checkSideForFace(args, 1, facing)) } else { - ForgeDirection.VALID_DIRECTIONS.filter(_ != facing.getOpposite).toIterable + // Always try the direction we're looking first. + Iterable(facing) ++ ForgeDirection.VALID_DIRECTIONS.filter(side => side != facing && side != facing.getOpposite).toIterable } val sneaky = args.isBoolean(2) && args.checkBoolean(2) @@ -414,7 +416,8 @@ class Robot(val robot: tileentity.Robot) extends ManagedComponent { Iterable(checkSideForFace(args, 1, facing)) } else { - ForgeDirection.VALID_DIRECTIONS.filter(_ != facing.getOpposite).toIterable + // Always try the direction we're looking first. + Iterable(facing) ++ ForgeDirection.VALID_DIRECTIONS.filter(side => side != facing && side != facing.getOpposite).toIterable } val sneaky = args.isBoolean(2) && args.checkBoolean(2) val duration =