Advertisement
hoblin

Railroad busterizer

Jan 1st, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.86 KB | None | 0 0
  1. -- -----------------------------
  2. -- Railroad busterizer
  3. -- pastebin get puUKhwXm bust
  4. -- -----------------------------
  5. function checkFuel()
  6.   if turtle.getFuelLevel() < 10 then
  7.     print('Refuel')
  8.     selectItem('fuel')
  9.     while not turtle.refuel(1) do sleep(5) end
  10.   end
  11. end
  12.  
  13. function clearUp()
  14.   if turtle.detectUp() then
  15.     turtle.select(16)
  16.     while not turtle.digUp() do turtle.attackUp() end
  17.     turtle.drop()
  18.   else
  19.     turtle.attackUp()
  20.   end
  21. end
  22.  
  23. function clearDown()
  24.   if turtle.detectDown() then
  25.     turtle.select(16)
  26.     while not turtle.digDown() do turtle.attackDown() end
  27.     turtle.drop()
  28.   else
  29.     turtle.attackDown()
  30.   end
  31. end
  32.  
  33. function clearFront()
  34.   if turtle.detect() then
  35.     turtle.select(16)
  36.     while not turtle.dig() do turtle.attack() end
  37.     turtle.drop()
  38.   else
  39.     turtle.attack()
  40.   end
  41. end
  42.  
  43. function clearBack()
  44.   turtle.turnRight()
  45.   turtle.turnRight()
  46.   clearFront()
  47.   turtle.turnRight()
  48.   turtle.turnRight()
  49. end
  50.  
  51. function goForward()
  52.   while not turtle.forward() do clearFront() end
  53. end
  54.  
  55. function goBack()
  56.   while not turtle.back() do clearBack() end
  57. end
  58.  
  59. function goUp()
  60.   while not turtle.up() do clearUp() end
  61. end
  62.  
  63. function goDown()
  64.   while not turtle.down() do clearDown() end
  65. end
  66.  
  67. function placeBlock(item)
  68.   selectItem( item )
  69.   while not turtle.placeDown() do clearDown() end
  70. end
  71.  
  72. function placeFrontBlock(item)
  73.   selectItem( item )
  74.   while not turtle.place() do
  75.     clearFront()
  76.     selectItem( item )
  77.   end
  78. end
  79.  
  80. function placeBooster()
  81.   clearDown()
  82.   goDown()
  83.   selectItem( 'floor' )
  84.   turtle.digDown()
  85.   goDown()
  86.   clearDown()
  87.   goDown()
  88.   clearDown()
  89.   placeBlock('floor')
  90.   placeFrontBlock('floor')
  91.   turtle.turnRight()
  92.   placeFrontBlock('floor')
  93.   turtle.turnRight()
  94.   placeFrontBlock('floor')
  95.   turtle.turnRight()
  96.   placeFrontBlock('floor')
  97.   turtle.turnRight()
  98.   goUp()
  99.   placeBlock('red_torch')
  100.   goUp()
  101.   placeBlock('floor')
  102.   goUp()
  103.   placeBlock('booster')
  104. end
  105.  
  106. function selectFrom( slots )
  107.   selected = false
  108.   while not selected do
  109.     for _, slot_num in ipairs(slots) do
  110.       if turtle.getItemCount(slot_num) > 1 then
  111.         turtle.select(slot_num)
  112.         selected = true
  113.         return
  114.       end
  115.     end
  116.     if not selected then
  117.       sleep(5)
  118.     end
  119.   end
  120. end
  121.  
  122. function selectItem( item )
  123.   inventory = {fuel = {1}, floor = {2, 3, 4, 5, 6}, booster = {7, 8}, red_torch = {9, 10}}
  124.   selectFrom(inventory[item])
  125. end
  126.  
  127. local lenth = 0
  128. term.clear()
  129. term.setCursorPos(1,1)
  130. print("1: fuel, 2, 3, 4, 5, 6: floor material")
  131. print("7, 8: boosters, 9, 10: red torches")
  132.  
  133. write("How long the road is? ")
  134. lenth = read()
  135. checkFuel()
  136. steps_to_booster = 7
  137. for a = 0, lenth do
  138.   steps_to_booster = steps_to_booster - 1
  139.   checkFuel()
  140.   goForward()
  141.   if steps_to_booster == 0 then
  142.     placeBooster()
  143.     steps_to_booster = 7
  144.   end
  145. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement