DogePastes

StripMine.lua

Jun 16th, 2021 (edited)
441
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. partnerID = 10
  2. timeout = 0.5
  3. onState = true
  4. movedBlocks = 0
  5. task = "idle"
  6.  
  7. function ivFull()
  8.     for i = 1,16 do
  9.         if turtle.getItemCount(i) == 0 then
  10.             return false
  11.         end
  12.     end
  13.     return true
  14. end
  15.  
  16. function stripMineStart()
  17.     for i = 0,8 do
  18.         if ivFull() == false then
  19.             if turtle.compare() then
  20.                 turtle.select(2)
  21.                 turtle.dig()
  22.                 turtle.select(1)
  23.                 sleep(2)
  24.             else
  25.                 turtle.forward()
  26.                 movedBlocks = movedBlocks + 1
  27.                 rednet.send(partnerID,"Move")
  28.                 turtle.dig()
  29.                 turtle.digUp()
  30.             end
  31.         else
  32.             turtle.turnLeft()
  33.             turtle.dig()
  34.             turtle.place()
  35.             for i = 3,16 do
  36.                 turtle.select(i)
  37.                 turtle.drop()
  38.             end
  39.             turtle.turnRight()
  40.             turtle.select(1)
  41.         end
  42.         select(1)
  43.         if turtle.getItemCount(1) == 0 then
  44.             task = "return"
  45.         end
  46.     end
  47. end
  48.  
  49.  
  50. function returnPoint()
  51.     turtle.digUp()
  52.     rednet.receive()
  53.     turtle.up()
  54.     turtle.back()
  55.     turtle.back()
  56.     rednet.send(partnerID,"Begin")
  57.     rednet.send(partnerID,"Up")
  58.     for i = 0,movedBlocks -3 do
  59.         turtle.back()
  60.         rednet.send(partnerID,"Back")
  61.     end
  62.     rednet.send(partnerID,"Break")
  63.     onState = false
  64. end
  65.  
  66.  
  67. function checkTask()
  68.     if task == "mine" then
  69.         stripMineStart()
  70.     elseif task == "return" then
  71.         returnPoint()
  72.     end
  73. end
  74.  
  75. rednet.open("left")
  76.  
  77. while onState do
  78.     checkTask()
  79.     rednet.send(3,"Send")
  80.     id,msg,prot = rednet.receive(timeout)
  81.     if msg == "back" then
  82.         task = "return"
  83.     end
  84.     if msg == "start" then
  85.         task = "mine"
  86.     end
  87.     if msg == "stop" then
  88.         break
  89.     end
  90.     checkTask()
  91. end
RAW Paste Data