Advertisement
Parg60

slave80

Dec 21st, 2020 (edited)
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.40 KB | None | 0 0
  1. modem = peripheral.wrap("left")
  2. modem.open(403)
  3.  
  4. modem.transmit(403, 403, "listening-port")
  5. print("listening for port")
  6. event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  7. port = message
  8. modem.open(port)
  9. print("opened port")
  10. modem.close(403)
  11.  
  12. modem.transmit(port, port, "listening-position")
  13. event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  14. distanceToGo = message
  15.  
  16. print(distanceToGo)
  17.  
  18. fullSlotCounter = 0
  19.  
  20.  
  21.  
  22. function await(x)
  23.     awaitVar = true
  24.     while awaitVar == true do
  25.         event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  26.         if message == x then
  27.             awaitVar = false
  28.         end
  29.     end
  30. end
  31.  
  32.  
  33. function checkFuel()
  34.     if turtle.getFuelLevel() < 401 then
  35.         turtle.select(14)
  36.         turtle.refuel(8)
  37.         turtle.select(1)
  38.     end
  39. end
  40.  
  41. function enderChests()
  42.     -- Unload slot 1 - 13
  43.     turtle.dig()
  44.     turtle.select(15)
  45.     turtle.place()
  46.     for i = 1, 13 , 1 do
  47.         turtle.select(i)
  48.         turtle.drop()
  49.     end
  50.     turtle.select(15)
  51.     turtle.dig()
  52.  
  53.     -- Load Slot 14 with coal
  54.     turtle.select(16)
  55.     turtle.place()
  56.    
  57.     if turtle.getItemCount(14) < 64 then
  58.         turtle.select(14)
  59.         turtle.suck(64 - turtle.getItemCount(14))
  60.     end
  61.    
  62.     turtle.select(16)
  63.     turtle.dig()
  64. end
  65.  
  66.  
  67. function checkInv()
  68.     if turtle.getItemCount(14) < 2 then
  69.         enderChests()
  70.     else
  71.         for i = 1, 13, 1 do
  72.             if turtle.getItemCount(i) > 0 then
  73.                 fullSlotCounter = fullSlotCounter + 1
  74.             end
  75.         end
  76.         if fullSlotCounter > 10 then
  77.             enderChests()
  78.         end
  79.     end
  80.     fullSlotCounter = 0
  81.  
  82.     checkFuel()
  83. end
  84.  
  85.  
  86. function getInPostion()
  87.     for i = 1, distanceToGo, 1 do
  88.         turtle.dig()
  89.         turtle.forward()
  90.         print(i)
  91.     end
  92.     turtle.turnLeft()
  93.     print("aqquired position")
  94. end
  95.  
  96.  
  97. function acceptOrder()
  98.     print("ready for parameters")
  99.  
  100.     await("values-incoming")
  101.  
  102.     event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  103.     width = message
  104.     event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  105.     height = message
  106.     event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  107.     depth = message
  108. end
  109.  
  110.  
  111. function executeOrder()
  112.     checkInv()
  113.  
  114.     for z = 1, depth, 1 do
  115.         checkInv()
  116.  
  117.         if  z % 2 == 0 then
  118.             turtle.dig()
  119.             turtle.forward()
  120.             for y = 1, height, 1 do
  121.                     turtle.digUp()
  122.                     turtle.up()
  123.                     checkInv()
  124.             end
  125.  
  126.         else
  127.  
  128.             turtle.dig()
  129.             turtle.forward()
  130.             for i = 1, height, 1 do
  131.                 turtle.digDown()
  132.                 turtle.down()
  133.                 checkInv()
  134.             end
  135.         end
  136.     end
  137. end
  138.  
  139.  
  140. function goHome()
  141.     for i = 1, depth - 1, 1 do
  142.         checkInv()
  143.         turtle.dig()
  144.         turtle.forward()
  145.     end
  146.     turtle.turnLeft()
  147.     modem.transmit(port, port, "arrived-home")
  148. end
  149.  
  150.  
  151. -- Actual program
  152. turtle.turnLeft()
  153. checkInv()
  154. turtle.turnRight()
  155.  
  156. getInPostion()
  157. acceptOrder()
  158. executeOrder()
  159.  
  160. goHome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement