Advertisement
cing5000

moveBlocks

Apr 12th, 2015
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.27 KB | None | 0 0
  1. local tArgs = {...}
  2. local args1 = tonumber(tArgs[1])
  3. local args2 = tonumber(tArgs[2])
  4. local args3 = tonumber(tArgs[3])
  5.  
  6. local cDir = "north"
  7. local cX = 0
  8. local cY = 0
  9. local cZ = 0
  10. local home = {cY,cX,cZ}
  11. local blocks = "blocks"
  12.  
  13. function turnRight()
  14.   if cDir == "north" then
  15.     cDir = "east"
  16.   elseif cDir == "east" then
  17.     cDir = "south"
  18.   elseif cDir == "south" then
  19.     cDir = "west"
  20.   elseif cDir == "west" then
  21.     cDir = "north"
  22.   else
  23.     print("Error!!")
  24.     error()
  25.   end
  26.   turtle.turnRight()
  27. end
  28.  
  29.  
  30. function turnTo(dir)
  31.   if cDir ~= dir then
  32.     repeat
  33.      turnRight()
  34.     until cDir == dir
  35.   end
  36. end
  37.  
  38. function moveForward()
  39.   if cDir == "north" then
  40.     cX = cX+1
  41.   elseif cDir == "east" then
  42.     cZ = cZ+1
  43.   elseif cDir == "south" then
  44.     cX = cX-1
  45.   elseif cDir == "west" then
  46.     cZ = cZ-1
  47.   else
  48.     print("Error!!")
  49.     error()
  50.   end
  51.   while not turtle.forward() do
  52.     turtle.dig()
  53.   end
  54. end
  55.  
  56. function moveUp()
  57.   cY = cY+1
  58.   while not turtle.up() do
  59.     turtle.digUp()
  60.   end
  61. end
  62.  
  63. function moveDown()
  64.   cY = cY-1
  65.   while not turtle.down() do
  66.     turtle.digDown()
  67.   end
  68. end
  69.    
  70. function moveToX(x)
  71.   if cX < x then
  72.     turnTo("north")
  73.     repeat
  74.       moveForward()
  75.     until cX == x
  76.   elseif cX > x then
  77.     turnTo("south")
  78.     repeat
  79.       moveForward()
  80.     until cX == x
  81.   else
  82.     --print("already there")
  83.   end
  84. end
  85.  
  86. function moveToZ(z)
  87.   if cZ < z then
  88.     turnTo("east")
  89.     repeat
  90.       moveForward()
  91.     until cZ == z
  92.   elseif cZ > z then
  93.     turnTo("west")
  94.     repeat
  95.       moveForward()
  96.     until cZ == z
  97.   else
  98.    --print("already there")
  99.   end
  100. end    
  101.  
  102. function moveToY(y)
  103.   if cY < y then
  104.     repeat
  105.       moveUp()
  106.     until cY == y
  107.   elseif cY > y then
  108.     repeat
  109.       moveDown()
  110.     until cY == y
  111.   else
  112.    --print("already there")
  113.   end
  114. end
  115.  
  116. function goTo(x, y, z)
  117.   moveToX(x)  
  118.   moveToY(tonumber(y))
  119.   moveToZ(tonumber(z))
  120.   turnTo("north")
  121. end
  122.  
  123. function sayMoveX()
  124.   if args1 == 1 or args1 == -1 then
  125.     blocks = "block"
  126.   else
  127.     blocks = "blocks"
  128.   end
  129.   if args1 > 0 then
  130.     print("I have moved "..tArgs[1].." "..blocks.." forward.")
  131.   elseif args1 < 0 then
  132.   local x = args1*-1
  133.     print("I have moved "..x.." "..blocks.." backwards.")
  134.   else
  135.     print("I haven't moved forward or backwards.")
  136.   end
  137. end
  138.  
  139. function sayMoveY()
  140.   if args2 == 1 or args2 == -1 then
  141.     blocks = "block"
  142.   else
  143.     blocks = "blocks"  
  144.   end
  145.   if args2 > 0 then
  146.     print("I have moved "..args2.." "..blocks.." up.")
  147.   elseif args2 < 0  then
  148.   local y = args2*-1
  149.     print("I have moved "..y.." "..blocks.." down.")
  150.   else
  151.     print("I haven't moved up or down.")          
  152.   end
  153. end
  154.  
  155. function sayMoveZ()
  156.   if args3 == 1 or args3 == -1 then
  157.     blocks = "block"
  158.   else
  159.     blcoks = "blocks"
  160.   end
  161.   if args3 > 0 then
  162.     print("I have moved "..args3.." "..blocks.." to the right.")
  163.   elseif args3 < 0 then
  164.   local z = args3*-1
  165.     print("I have moved "..z.." "..blocks.." to the left.")
  166.   else
  167.     print("I haven't moved to the right or left.")
  168.   end
  169. end
  170.  
  171. function sayMoves()
  172.   sayMoveX()
  173.   sayMoveY()
  174.   sayMoveZ()
  175. end      
  176.                                  
  177. goTo(args1,args2,args3)
  178. sayMoves()
  179. --sleep(5)
  180. --goTo(home[1],home[2],home[3])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement