Advertisement
Parg60

server80

Dec 21st, 2020 (edited)
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.01 KB | None | 0 0
  1. modem = peripheral.wrap("left")
  2. modem.open(5555)
  3.  
  4. function setup()
  5.     modem.open(403)
  6.  
  7.     accepted = false
  8.     fullSlotCounter = 0
  9.     temp = 0
  10.     awaitVar = true
  11. end
  12.  
  13.  
  14. function await(x)
  15.     awaitVar = true
  16.     while awaitVar == true do
  17.         event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  18.         if message == x then
  19.             awaitVar = false
  20.         end
  21.     end
  22. end
  23.  
  24.  
  25. function getValues()  
  26.     event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  27.     width = tonumber(message)
  28.  
  29.     event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  30.     height = tonumber(message)
  31.  
  32.     event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  33.     depth = tonumber(message)
  34. end
  35.  
  36.  
  37. function calculateWidth()
  38.     print("calculating")
  39.  
  40.     if width % 80 == 0 then
  41.         slaveWidth = width / 80
  42.         lastSlaveWidth = slaveWidth
  43.         slaveAmount = 80
  44.     elseif width < 81 then
  45.         slaveWidth = 1
  46.         lastSlaveWidth = slaveWidth
  47.         slaveAmount = width
  48.     else
  49.  
  50.         slaveWidth = (width - (width % i)) / i
  51.         lastSlaveWidth = slaveWidth + width % i
  52.         if slaveWidth > lastSlaveWidth then
  53.             temp = slaveWidth
  54.         end
  55.  
  56.         for i = 1, slaveAmount, 1 do
  57.            
  58.             slaveWidth = (width - (width % i)) / i
  59.             lastSlaveWidth = slaveWidth + width % i
  60.  
  61.             if slaveWidth > lastSlaveWidth then
  62.                 temp = slaveWidth
  63.             end
  64.            
  65.            
  66.            
  67.             if width - (width % i) / i < temp then
  68.                 slaveWidth = (width - (width % i)) / i
  69.                 lastSlaveWidth = slaveWidth + width % i
  70.  
  71.                 if slaveWidth > lastSlaveWidth then
  72.                     temp = slaveWidth
  73.                 else
  74.                     temp = lastSlaveWidth
  75.                 end
  76.             end
  77.            
  78.  
  79.         end
  80.  
  81.  
  82.     end
  83.  
  84.     print(slaveAmount)
  85.     print(slaveWidth)
  86.     print(lastSlaveWidth)
  87.  
  88.     for i = 1, slaveAmount, 1 do
  89.         modem.open(100 + i)
  90.     end
  91. end
  92.  
  93.  
  94. function approximitTime()
  95.     approximitTime = (((width * height * depth) * 0.75) / slaveAmount) + (slaveAmount + width * 1)
  96.     modem.transmit(5555, 5555, "Mining started, approximitly "..approximitTime.." seconds left...")
  97. end
  98.  
  99.  
  100. function checkFuel()
  101.     if turtle.getFuelLevel() < 801 then
  102.         turtle.select(14)
  103.         turtle.refuel(16)
  104.         turtle.select(1)
  105.     end
  106. end
  107.  
  108.  
  109. function checkInv()
  110.     if turtle.getItemCount(14) < 8 then
  111.         enderChests()
  112.     elseif turtle.getItemCount(8) > 0 then
  113.         enderChests()
  114.     end
  115.        
  116.        
  117.     fullSlotCounter = 0
  118.     checkFuel()
  119. end
  120.  
  121.  
  122.  
  123. function enderChests()
  124.     -- Unload slot 1 - 10
  125.     turtle.dig()
  126.     turtle.select(15)
  127.     turtle.place()
  128.     for i = 1, 10 , 1 do
  129.         turtle.select(i)
  130.         turtle.drop()
  131.     end
  132.     turtle.select(15)
  133.     turtle.dig()
  134.  
  135.     -- Load Slot 14 with coal
  136.     turtle.select(16)
  137.     turtle.place()
  138.    
  139.     if turtle.getItemCount(14) < 64 then
  140.         turtle.select(14)
  141.         turtle.suck(64 - turtle.getItemCount(14))
  142.     end
  143.    
  144.     turtle.select(16)
  145.     turtle.dig()
  146. end
  147.  
  148.  
  149. function buildSpwan()
  150.     print("building spawn...")
  151.     turtle.select(1)
  152.     turtle.turnLeft()
  153.     turtle.dig()
  154.     turtle.forward()
  155.     turtle.turnRight()
  156.     turtle.turnRight()
  157.     turtle.digUp()
  158.     turtle.digDown()
  159.     turtle.select(12)
  160.     turtle.placeDown()
  161.     turtle.select(11)
  162.     turtle.dropDown()
  163.     turtle.up()
  164. end
  165.  
  166.  
  167. function summonSlaves()
  168.     print("summoning slaves...")
  169.     print(slaveAmount)
  170.  
  171.     for i = 1, slaveAmount, 1 do
  172.         turtle.select(13)
  173.         turtle.placeDown()
  174.  
  175.         print("slave summoned")
  176.  
  177.         peripheral.call('bottom','turnOn')
  178.  
  179.         sleep(1.5)
  180.         turtle.select(15)
  181.         turtle.dropDown(1)
  182.         sleep(.5)
  183.         turtle.select(16)
  184.         turtle.dropDown(1)
  185.         sleep(.5)
  186.         turtle.select(14)
  187.         turtle.dropDown(4)
  188.        
  189.  
  190.         await("listening-port")
  191.         print("accept")
  192.         modem.transmit(403, 403, 100 + i)
  193.  
  194.         if i == 1 then
  195.             distanceToGo = width - lastSlaveWidth
  196.         else
  197.             distanceToGo = width - lastSlaveWidth - (slaveWidth * (i - 1))
  198.         end
  199.  
  200.         print(distanceToGo)
  201.  
  202.         await("listening-position")
  203.         modem.transmit(100 + i, 100 + i, distanceToGo)
  204.        
  205.         if i == 1 then
  206.             sleep(width)
  207.         end
  208.        
  209.         sleep(2)
  210.     end
  211.  
  212.     sleep(width + 3)
  213. end
  214.  
  215.  
  216. function destroySpawn()
  217.     print("destroying spawn...")
  218.     turtle.down()
  219.     turtle.select(11)
  220.     turtle.suckDown()
  221.     turtle.select(12)
  222.     turtle.digDown()
  223.     checkInv()
  224. end
  225.  
  226.  
  227. function giveOrder()
  228.     print("sending parameters")
  229.     for i = 1, slaveAmount, 1 do
  230.         modem.transmit(100 + i, 100 + i, "values-incoming")
  231.        
  232.         if i == 1 then
  233.             modem.transmit(100 + i, 100 + i, lastSlaveWidth)
  234.             modem.transmit(100 + i, 100 + i, height)
  235.             modem.transmit(100 + i, 100 + i, depth)
  236.         else
  237.             modem.transmit(100 + i, 100 + i, slaveWidth)
  238.             modem.transmit(100 + i, 100 + i, height)
  239.             modem.transmit(100 + i, 100 + i, depth)
  240.         end
  241.     end
  242. end
  243.  
  244. function eatSlaves()
  245.     for i = 1, slaveAmount, 1 do
  246.         await("arrived-home")
  247.     end
  248.    
  249.     for i = 1, width, 1 do
  250.         turtle.forward()
  251.         turtle.dig()
  252.     end
  253.     turtle.turnRight()
  254.     turtle.turnRight()
  255.     for i = 1, width, 1 do
  256.         turtle.forward()
  257.         turtle.dig()
  258.     end
  259.     turtle.turnRight()
  260. end
  261.  
  262.  
  263.  
  264. -- Actual program
  265.  
  266. await("start-mining")
  267.  
  268. getValues()
  269. calculateWidth()
  270. approximitTime()
  271.  
  272. checkInv()
  273. setup()
  274.  
  275. buildSpwan()
  276. summonSlaves()
  277.    
  278. giveOrder()
  279. sleep(15)
  280. destroySpawn()
  281.  
  282.  
  283. eatSlaves()
  284. checkInv()
  285. sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement