Advertisement
Parg60

miningServer

Dec 17th, 2020 (edited)
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.07 KB | None | 0 0
  1. modem = peripheral.wrap("back")
  2. modem.open(5555)
  3. accepted = false
  4. fullSlotCounter = 0
  5. waitInput = true
  6.  
  7. while waitInput == true do
  8.     event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  9.     if message == "start-mining" then
  10.         waitInput = false
  11.     end
  12. end
  13.  
  14. function getValues()  
  15.     event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  16.     width = tonumber(message)
  17.  
  18.     event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  19.     height = tonumber(message)
  20.  
  21.     event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  22.     depth = tonumber(message)
  23. end
  24.  
  25. function approximitTime()
  26.     approximitTime = ((width * height * depth) * 0.75) + 5
  27. end
  28.  
  29. function sendConfirm()
  30.     modem.transmit(5555, 5555, "Mining started, approximitly "..approximitTime.." seconds left...")
  31. end
  32.  
  33. function refuel()
  34.     if turtle.getFuelLevel() < 801 then
  35.         turtle.select(14)
  36.         turtle.refuel(16)
  37.         turtle.select(1)
  38.     end
  39. end
  40.  
  41. function checkInv()
  42.     refuel()
  43.     if turtle.getItemCount(14) < 2 then
  44.         enderChests()
  45.     else
  46.         for i = 1, 13, 1 do
  47.             if turtle.getItemCount(i) > 0 then
  48.                 fullSlotCounter = fullSlotCounter + 1
  49.             end
  50.         end
  51.         if fullSlotCounter > 12 then
  52.             enderChests()
  53.         end
  54.     end
  55.     fullSlotCounter = 0
  56. end
  57.  
  58.  
  59.  
  60. function enderChests()
  61.     -- Unload slot 1 - 13
  62.     turtle.dig()
  63.     turtle.select(15)
  64.     turtle.place()
  65.     for i = 1, 13 , 1 do
  66.         turtle.select(i)
  67.         turtle.drop()
  68.     end
  69.     turtle.select(15)
  70.     turtle.dig()
  71.  
  72.     -- Load Slot 14 with coal
  73.     turtle.select(16)
  74.     turtle.place()
  75.    
  76.     if turtle.getItemCount(14) < 64 then
  77.         turtle.select(14)
  78.         turtle.suck(64 - turtle.getItemCount(14))
  79.     end
  80.    
  81.     turtle.select(16)
  82.     turtle.dig()
  83. end
  84.  
  85. function startMining()
  86.     enderChests()
  87.     refuel()
  88.  
  89.     turtle.forward()
  90.    
  91.  
  92.     for z = 1, depth, 1 do
  93.         turtle.turnRight()
  94.         for y = 1, height, 1 do
  95.             for x = 1, width - 1, 1 do
  96.                 turtle.dig()
  97.                 turtle.forward()
  98.                 checkInv()
  99.             end
  100.             if y < height then
  101.                 turtle.digUp()
  102.                 turtle.turnLeft()
  103.                 turtle.turnLeft()
  104.                 turtle.up()
  105.             end
  106.         end
  107.        
  108.         for i = 1, height - 1, 1 do
  109.             turtle.down()
  110.         end
  111.         if (depth % 2) == 1 then
  112.             turtle.turnRight()
  113.             turtle.turnRight()
  114.             for i = 1, width - 1, 1 do
  115.                 turtle.forward()
  116.             end
  117.         end
  118.         turtle.turnRight()
  119.         turtle.dig()
  120.         turtle.forward()
  121.        
  122.     end
  123.  
  124.     turtle.dig()
  125.     enderChests()
  126. end
  127.  
  128. -- Actual program
  129. if message == "start-mining" then
  130.     getValues()
  131.     approximitTime()
  132.     sendConfirm()
  133.     startMining()
  134. end
  135.  
  136.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement