Guest User

bdig.lua

a guest
Nov 7th, 2015
1,414
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local bdig_version = "0.0.1"
  2. local author = "deFENCE"
  3. local site = "http://pls.bounceme.net/oc/programs/"
  4.  
  5. print("BDig version "..bdig_version.." by "..author)
  6. print("Website: "..site)
  7.  
  8. local component = require("component")
  9. local shell = require("shell")
  10. local robot = require("robot")
  11.  
  12. if not component.isAvailable("robot") then
  13.   print("This program must be run on a robot!")
  14. end
  15.  
  16. local args, options = shell.parse(...)
  17. local left = options.l or false
  18. local leftorg = left
  19. local up = options.u or false
  20. local noItems = options.k or false
  21. noItems = not noItems
  22.  
  23. function dig()
  24.   while robot.detect() do
  25.     robot.swing()
  26.   end
  27. end
  28.  
  29. function digUp()
  30.   while robot.detectUp() do
  31.     robot.swingUp()
  32.   end
  33. end
  34.  
  35. function digDown()
  36.   while robot.detectDown() do
  37.     robot.swingDown()
  38.   end
  39. end
  40.  
  41. if #args < 3 then
  42.   print("Syntax: bdig [-luk] <up/down> <fwd> <side>")
  43.   print("  -l")
  44.   print("     Makes the robot go left instead of right")
  45.   print("")
  46.   print("  -u")
  47.   print("     Makes the robot go up instead of down")
  48.   print("")
  49.   print("  -k")
  50.   print("     NOT IMPLEMENTED Makes the robot keep items instead of throwing them out")
  51.   exit(1)
  52. end
  53.  
  54. local blockY = args[1]
  55. local blockX = args[2]
  56. local blockZ = args[3]
  57.  
  58. print(blockY)
  59. print(blockX)
  60. print(blockZ)
  61.  
  62. --exit(0)
  63.  
  64. function digXZ()
  65.   for zm = 0, blockZ - 2 do
  66.     for xm = 0, blockX - 2 do
  67.       dig()
  68.       robot.forward()
  69.     end
  70.     if left then
  71.       robot.turnLeft()
  72.       dig()
  73.       robot.forward()
  74.       robot.turnLeft()
  75.     else
  76.       robot.turnRight()
  77.       dig()
  78.       robot.forward()
  79.       robot.turnRight()
  80.     end
  81.     left = not left
  82.   end
  83.   for xm = 0, blockX - 2 do
  84.     dig()
  85.     robot.forward()
  86.   end
  87.   if left == leftorg then
  88.     robot.turnRight()
  89.     robot.turnRight()
  90.     for xm = 0, blockX - 2 do
  91.       dig()
  92.       robot.forward()
  93.     end
  94.   end
  95.   if leftorg then
  96.     robot.turnLeft()
  97.   else
  98.     robot.turnRight()
  99.   end
  100.   for zm = 0, blockZ - 2 do
  101.     dig()
  102.     robot.forward()
  103.   end
  104.   if leftorg then
  105.     robot.turnLeft()
  106.   else
  107.     robot.turnRight()
  108.   end
  109.   left = leftorg
  110. end
  111.  
  112. for ym = 0, blockY - 2 do
  113.   digXZ()
  114.   if up then
  115.     digUp()
  116.     robot.up()
  117.   else
  118.     digDown()
  119.     robot.down()
  120.   end
  121. end
  122. digXZ()
RAW Paste Data