added sneaky parameter to robot.swing, as discussed in #13

This commit is contained in:
Florian Nücke 2013-12-23 19:17:01 +01:00
parent c0adb97603
commit 28c504d342
2 changed files with 11 additions and 6 deletions

View File

@ -117,19 +117,19 @@ function robot.durability()
end
function robot.swing(side)
function robot.swing(side, sneaky)
checkArg(1, side, "nil", "number")
return component.computer.swing(sides.front, side)
return component.computer.swing(sides.front, side, sneaky ~= nil and sneaky ~= false)
end
function robot.swingUp(side)
function robot.swingUp(side, sneaky)
checkArg(1, side, "nil", "number")
return component.computer.swing(sides.up, side)
return component.computer.swing(sides.up, side, sneaky ~= nil and sneaky ~= false)
end
function robot.swingDown(side)
function robot.swingDown(side, sneaky)
checkArg(1, side, "nil", "number")
return component.computer.swing(sides.down, side)
return component.computer.swing(sides.down, side, sneaky ~= nil and sneaky ~= false)
end
function robot.use(side, sneaky, duration)

View File

@ -324,6 +324,7 @@ class Robot(val robot: tileentity.Robot) extends Computer(robot) with RobotConte
else {
ForgeDirection.VALID_DIRECTIONS.filter(_ != facing.getOpposite).toIterable
}
val sneaky = args.isBoolean(2) && args.checkBoolean(2)
def triggerDelay(delay: Double = Settings.get.swingDelay) = {
context.pause(delay)
@ -358,6 +359,8 @@ class Robot(val robot: tileentity.Robot) extends Computer(robot) with RobotConte
for (side <- sides) {
val player = robot.player(facing, side)
player.setSneaking(sneaky)
val (success, what) = Option(pick(player, Settings.get.swingRange)) match {
case Some(hit) =>
hit.typeOfHit match {
@ -378,6 +381,8 @@ class Robot(val robot: tileentity.Robot) extends Computer(robot) with RobotConte
else (false, "air")
}
}
player.setSneaking(false)
if (success) {
return result(true, what)
}