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.
This commit is contained in:
Florian Nücke 2014-04-18 14:06:45 +02:00
parent 1bb2c76bd5
commit b3ea58c96b
2 changed files with 7 additions and 4 deletions

View File

@ -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) && (Settings.get.allowUseItemsWithDuration || stack.getMaxItemUseDuration <= 0) &&
(!PortalGun.isPortalGun(stack) || PortalGun.isStandardPortalGun(stack)) && (!PortalGun.isPortalGun(stack) || PortalGun.isStandardPortalGun(stack)) &&
!stack.isItemEqual(new ItemStack(Item.leash)) !stack.isItemEqual(new ItemStack(Item.leash))

View File

@ -231,7 +231,8 @@ class Robot(val robot: tileentity.Robot) extends ManagedComponent {
Iterable(checkSideForFace(args, 1, facing)) Iterable(checkSideForFace(args, 1, facing))
} }
else { 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 sneaky = args.isBoolean(2) && args.checkBoolean(2)
val stack = player.robotInventory.selectedItemStack val stack = player.robotInventory.selectedItemStack
@ -337,7 +338,8 @@ class Robot(val robot: tileentity.Robot) extends ManagedComponent {
Iterable(checkSideForFace(args, 1, facing)) Iterable(checkSideForFace(args, 1, facing))
} }
else { 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 sneaky = args.isBoolean(2) && args.checkBoolean(2)
@ -414,7 +416,8 @@ class Robot(val robot: tileentity.Robot) extends ManagedComponent {
Iterable(checkSideForFace(args, 1, facing)) Iterable(checkSideForFace(args, 1, facing))
} }
else { 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 sneaky = args.isBoolean(2) && args.checkBoolean(2)
val duration = val duration =