Advertisement
kazenotachi

extrude

Sep 10th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.24 KB | None | 0 0
  1. --[[ extrude - KazeNoTachi ]]--
  2. --[[http://pastebin.com/1sR4CKT4]]--
  3.  
  4. name= os.getComputerLabel()
  5.  
  6. tArgs= { ... }
  7.  
  8. height = tArgs[1]
  9. tempMatSlot= 0
  10. --tempMatSlot = tArgs[2] or 15
  11.  
  12.  
  13. function openRednet()
  14.     local listOfSides = rs.getSides()
  15.     local listofPossibles = {}
  16.     local counter1 = 0
  17.     while true do
  18.         counter1 = counter1 +1
  19.  
  20.         if peripheral.isPresent(tostring(listOfSides[counter1])) and peripheral.getType(listOfSides[counter1]) == "modem" then
  21.             table.insert(listofPossibles,tostring(listOfSides[counter1]))
  22.         end
  23.  
  24.         if counter1 == 6 and table.maxn(listofPossibles) == 0 then
  25.             print("no wifi present")
  26.             return nil
  27.         end
  28.  
  29.         if counter1 == 6 and table.maxn(listofPossibles) ~= 0 then
  30.             rednet.open(listofPossibles[1])
  31.             return listofPossibles[1]
  32.         end
  33.     end
  34. end
  35.  
  36.  
  37. function message(mess)
  38.     modemOn = openRednet()
  39.     if modemOn == nil then
  40.         print("localonly: "..mess)
  41.     else
  42.         rednet.broadcast(name..": "..mess)
  43.         print("network: "..mess)
  44.  
  45.     end
  46. end
  47.  
  48.  
  49.  
  50. function init( ... )
  51.  
  52.     checkfuel()
  53.     message(name.." is Booting up...\n")
  54.     --write(tempMatSlot.." "..height)
  55. end
  56.  
  57. function checkfuel()
  58.     if turtle.getFuelLevel() <10 then
  59.         turtle.select(16)
  60.         while turtle.refuel(1) ==false do
  61.             sleep(5)
  62.         end
  63.  
  64.     end
  65.     --rednet.broadcast(name.." Refuelled: "..turtle.getFuelLevel())
  66. end
  67. function checkInv()
  68.     if checkInv2()==false then
  69.         message(name.." needs more Materials")
  70.     end
  71.     while checkInv2()==false do
  72.         sleep(5)   
  73.     end
  74. end
  75.  
  76.  
  77. function checkInv2()
  78.     for slot=1,14 do
  79.         if turtle.getItemCount(slot)>0 then
  80.             turtle.select(slot)
  81.             return true
  82.         end
  83.     end
  84.     return false
  85.  
  86. end
  87.  
  88. function buildcheck()
  89.     partOfTemp=false
  90.     selected=turtle.getSelectedSlot()
  91.     turtle.select(15)
  92.     if turtle.compareDown() then
  93.         partOfTemp = true
  94.     end
  95.  
  96.     turtle.select(selected)
  97.     return partOfTemp
  98. end
  99.  
  100. function checkForNextBlock()
  101.     direction={}  
  102.     direction[1]=false
  103.     direction[2]=false
  104.     direction[3]=false
  105.     checkfuel()
  106.  
  107.     if turtle.forward() then
  108.         direction[2]=buildcheck()
  109.         turtle.back()
  110.         if direction[2]==true then
  111.             return "forward"
  112.         --write(" nextblock found right")
  113.     end
  114. end
  115.  
  116. turtle.turnRight()
  117. if turtle.forward() then
  118.     direction[1]=buildcheck()
  119.     turtle.back()
  120.     turtle.turnLeft()
  121.     if direction[1]==true then
  122.         return "right"
  123.         --write(" nextblock found right")
  124.     end
  125. end
  126.  
  127. turtle.turnLeft()
  128.  
  129. if turtle.forward() then
  130.     direction[3]=buildcheck()
  131.     turtle.back()
  132.     turtle.turnRight()
  133.     if direction[3]==true then
  134.         return "left"
  135.             --write(" nextblock found right")
  136.         end
  137.     end
  138.     message("No direct route found - Checking for diagonals")
  139.     return checkFordiag()
  140. end
  141.  
  142. function checkFordiag()
  143.     direction={}  
  144.     direction[1]=false
  145.     direction[2]=false
  146.     checkfuel()
  147.  
  148.     if turtle.forward() then
  149.  
  150.         turtle.turnRight()
  151.        
  152.         if turtle.forward() then
  153.             direction[1]=buildcheck()
  154.             turtle.back()
  155.             turtle.turnLeft()
  156.             if direction[1]==true then
  157.             turtle.back()
  158.                 return "diagright"
  159.             --write(" nextblock found right")
  160.             end
  161.         end
  162.    
  163.         turtle.turnLeft()
  164.    
  165.         if turtle.forward() then
  166.             direction[2]=buildcheck()
  167.             turtle.back()
  168.             turtle.turnRight()
  169.             if direction[2]==true then
  170.                 turtle.back()
  171.                 return "diagleft"
  172.                 --write(" nextblock found right")
  173.             end
  174.         end
  175.         turtle.turnRight()
  176.         turtle.back()
  177.     end
  178.     return "none"
  179.  
  180. end
  181.  
  182.  
  183. function buildMove(direction)
  184.     message(direction)
  185.     direction=direction or "none"
  186.     checkfuel()
  187.     --turtle.select(15)
  188.  
  189.  
  190.     for i=1,height do
  191.         checkInv()
  192.         turtle.up()
  193.         turtle.placeDown()
  194.     end
  195.  
  196.     if direction=="forward" then
  197.         turtle.forward()
  198.     end
  199.     if direction=="right" then
  200.         turtle.turnRight()
  201.         turtle.forward()
  202.     end
  203.  
  204.     if direction=="left" then
  205.         turtle.turnLeft()
  206.         turtle.forward()
  207.     end
  208.  
  209.     if direction=="diagright" then
  210.         turtle.forward()
  211.         turtle.turnRight()
  212.         turtle.forward()
  213.     end
  214.  
  215.     if direction=="diagleft" then
  216.         turtle.forward()
  217.         turtle.turnLeft()
  218.         turtle.forward()
  219.     end
  220.     if direction=="none" then
  221.         --rednet.broadcast(name..": I'm Done!")
  222.         return false
  223.     else
  224.         while turtle.down() do end 
  225.         return true
  226.     end
  227.  
  228. end
  229.  
  230. init()
  231. message(name.." is Building...\n")
  232. while buildMove(checkForNextBlock()) == true do
  233.  
  234. end
  235. for i=1,10 do
  236.     turtle.turnRight()
  237. end
  238.  
  239. message("\n"..name.. " is Completed.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement