Advertisement
Yourdoom

Build Quarry frame

May 18th, 2013
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.68 KB | None | 0 0
  1. local tArgs = {...}
  2.  
  3. local coord = { 0, 0, 0 }
  4. local dir = 0
  5.  
  6. if not startDir then coord[3] = -coord[3] end
  7.  
  8. function curMoveAxis()
  9.    if dir % 2 == 0 then
  10.       return 1
  11.    else
  12.       return 3
  13.    end
  14. end
  15. function curMoveDir()
  16.    if math.floor( dir / 2 ) % 2 == 0 then
  17.       return 1
  18.    else
  19.       return -1
  20.    end
  21. end
  22.  
  23. function forward()
  24.    while not turtle.forward() do sleep( 1 ) end
  25.  
  26.    local axis = curMoveAxis()
  27.    coord[ axis ] = coord[ axis ] + curMoveDir()
  28. end
  29. function backward()
  30.    while not turtle.back() do sleep( 1 ) end
  31.  
  32.    local axis = curMoveAxis()
  33.    coord[ axis ] = coord[ axis ] - curMoveDir()
  34. end
  35. function up()
  36.    while not turtle.up() do sleep( 1 ) end
  37.    coord[ 2 ] = coord[ 2 ] + 1
  38. end
  39. function down()
  40.    while not turtle.down() do sleep( 1 ) end
  41.    coord[ 2 ] = coord[ 2 ] - 1
  42. end
  43. function turnLeft()
  44.    turtle.turnLeft()
  45.    dir = ( dir + 1 ) % 4
  46. end
  47. function turnRight()
  48.    turtle.turnRight()
  49.    dir = ( dir - 1 ) % 4
  50. end
  51. function turn( _dir )
  52.    if _dir then
  53.       turnLeft()
  54.    else
  55.       turnRight()
  56.    end
  57. end
  58.  
  59. function moveToSlot( to, fromMin, fromMax )
  60.    if not fromMax then fromMax = 16 end
  61.  
  62.    for i = fromMin, fromMax do
  63.       if turtle.getItemCount( to ) == 64 then break end
  64.  
  65.       if ( not i == to ) and turtle.getItemCount( i ) > 0 then
  66.          turtle.select( i )
  67.          turtle.transferTo( to, 64 )
  68.       end
  69.    end
  70.  
  71.    turtle.select( to )
  72. end
  73.  
  74. function stepsToPos( newCoord )
  75.    local axis = curMoveAxis()
  76.  
  77.    return ( coord[ axis ] - newCoord[ axis ] ) * curMoveDir()
  78. end
  79. function moveTo( newCoord, callback )
  80.    function callCallback()
  81.       if callback ~= nil then callback( newCoord ) end
  82.    end
  83.  
  84.    while newCoord[ 2 ] > coord[ 2 ] do
  85.       up()
  86.       callCallback()
  87.    end
  88.  
  89.    for i = 1, 2 do
  90.       local axis = curMoveAxis()
  91.  
  92.       while stepsToPos( newCoord ) > 0 do
  93.          backward()
  94.          callCallback()
  95.       end
  96.       while stepsToPos( newCoord ) < 0 do
  97.          forward()
  98.          callCallback()
  99.       end
  100.  
  101.       turn(true)
  102.    end
  103.  
  104.    while newCoord[ 2 ] < coord[ 2 ] do
  105.       down()
  106.       callCallback()
  107.    end
  108. end
  109.  
  110. local height = tArgs[1]
  111. if height then height = tonumber( height ) else height = 40 end
  112.  
  113. function placeBlock( c )
  114.    moveToSlot( 1, 2, 15 )
  115. end
  116. function placeMarker()
  117.    turtle.select( 16 )
  118.    turtle.placeDown()
  119.    turtle.select( 1 )
  120. end
  121.  
  122. moveTo( { 0, height, 0 }, placeBlock )
  123.  
  124. moveTo( { 64, height, 0 }, placeBlock )
  125.  
  126. up()
  127. placeMarker()
  128. moveTo( { 0, height + 1, 0 } )
  129.  
  130. placeMarker()
  131. turnRight()
  132.  
  133. forward()
  134. down()
  135. placeBlock()
  136.  
  137. moveTo( { 0, height, 64 }, placeBlock )
  138.  
  139. up()
  140. placeMarker()
  141. moveTo( { 0, height + 1, 0 } )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement