hbar

screenbuilder

Mar 15th, 2014
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.21 KB | None | 0 0
  1. -- Screen building utility
  2. -- Matti Vapa, 2014
  3. -- Place Glowstone Illuminators on the first row of the turtles inventory,
  4. -- Wired Modems on the second row and Networking Cables on the third.
  5.  
  6. local width = 16
  7. local height = 16
  8.  
  9. local lampslot = 1
  10. local modemslot = 5
  11. local cableslot = 9
  12.  
  13. local ascend = turtle.up
  14. local descend = turtle.down
  15. local closer = turtle.forward
  16. local away = turtle.back
  17. local click = turtle.attack
  18. local place = turtle.place
  19.  
  20. -- Use this to build a horizontal display (ceiling).
  21. -- Will be built underneath the turtle.
  22. --[[
  23. local ascend = turtle.forward
  24. local descend = turtle.back
  25. local closer = turtle.down
  26. local away = turtle.up
  27. local click = turtle.attackDown
  28. local place = turtle.placeDown
  29. --]]
  30.  
  31. -- Use this to build a horizontal display (floor).
  32. -- Will be built above the turtle.
  33. --[[
  34. local ascend = turtle.forward
  35. local descend = turtle.back
  36. local closer = turtle.up
  37. local away = turtle.down
  38. local click = turtle.attacUp
  39. local place = turtle.placeUp
  40. ]]--
  41.  
  42.  
  43. local move = function(f)
  44.     if turtle.getFuelLevel() < 1 then
  45.         print("Low on fuel. Please add fuel to my inventory.")
  46.         while turtle.getFuelLevel() < 1 do
  47.             os.sleep(5)
  48.             print("Checking for fuel...")
  49.             shell.run("refuel all")
  50.         end
  51.     end
  52.     while not f() do
  53.         sleep(0.3)
  54.     end
  55.     sleep(0.1)
  56. end
  57.  
  58.  
  59. local assemble = function()
  60.     move(closer)
  61.     while turtle.getItemCount(lampslot) < 1 do
  62.         lampslot = lampslot + 1
  63.         if lampslot > 4 then
  64.             print("Out of Illuminators, please put more on the first row and press return.")
  65.             lampslot = 1
  66.             local e,c = os.pullEvent("key")
  67.             while c ~= 28 do
  68.                 e,c = os.pullEvent("key")
  69.             end
  70.         end
  71.     end
  72.     turtle.select(lampslot)
  73.     place()
  74.     click()
  75.     move(away)
  76.     while turtle.getItemCount(modemslot) < 1 do
  77.         modemslot = modemslot + 1
  78.         if modemslot > 8 then
  79.             print("Out of modems, please put more on the second row and press return.")
  80.             modemslot = 5
  81.             local e,c = os.pullEvent("key")
  82.             while c ~= 28 do
  83.                 e,c = os.pullEvent("key")
  84.             end
  85.         end
  86.     end
  87.     turtle.select(modemslot)
  88.     place()
  89.     while turtle.getItemCount(cableslot) < 1 do
  90.         cableslot = cableslot + 1
  91.         if cableslot > 12 then
  92.             print("Out of cable, please put more on the third row and press return.")
  93.             cableslot = 9
  94.             local e,c = os.pullEvent("key")
  95.             while c ~= 28 do
  96.                 e,c = os.pullEvent("key")
  97.             end
  98.         end
  99.     end
  100.     turtle.select(cableslot)
  101.     place()
  102.     click()
  103. end
  104.  
  105.  
  106.  
  107. local column,row = 1,height
  108.  
  109.  
  110. print("Good to go!")
  111. print(string.format("The process will take around %f minutes to finish.",(2.5*height*width)/60))
  112. print("Press return to begin.")
  113. e,c = os.pullEvent("key")
  114. while c ~= 28 do
  115.     e,c = os.pullEvent("key")
  116. end
  117.  
  118. print("Starting...")
  119.  
  120. turtle.select(1)
  121. while true do
  122.     if column > width then break end
  123.     assemble()
  124.     while row > 1 do
  125.         move(ascend)
  126.         row = row - 1
  127.         assemble()
  128.     end
  129.     turtle.turnLeft()
  130.     move(turtle.forward)
  131.     turtle.turnRight()
  132.     column = column + 1
  133.     if column > width then break end
  134.     assemble()
  135.     while row < height do
  136.         move(descend)
  137.         row = row + 1
  138.         assemble()
  139.     end
  140.     turtle.turnLeft()
  141.     move(turtle.forward)
  142.     turtle.turnRight()
  143.     column = column + 1
  144. end
  145.  
  146. if width % 2 == 1 then
  147.     for i=1,height-1 do
  148.         move(descend)
  149.     end
  150. end
Advertisement
Add Comment
Please, Sign In to add comment