Advertisement
rhn

OrechidMiner

rhn
Apr 25th, 2020
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.25 KB | None | 0 0
  1. if (fs.exists("choices") == false) then --Check if this is first time run, no saved choices on file
  2.     while true do
  3.             print("Which layer?")
  4.  
  5.             local answer = read()
  6.             if tonumber(answer)==nill then
  7.                 print("-Wrong answer, input not a number-")
  8.             else
  9.                 local answerv = tonumber(string.format("%." .. 0 .. "f", answer))
  10.                     layer=answerv
  11.                     print("Layer ", layer, " chosen")
  12.                     break
  13.             end
  14.     end
  15.  
  16.  
  17.     local file = fs.open("choices","w")
  18.     file.writeLine("layer="..tostring(layer))
  19.     file.close()
  20. end
  21. os.loadAPI("choices") -- Reads choices from file
  22. local layer= choices.layer
  23.  
  24.  
  25. local function move(steps)
  26.     for i=1,steps do
  27.         while not turtle.forward() do
  28.                     sleep(1)
  29.         end
  30.     end
  31. end
  32.  
  33. local function empty()
  34.     turtle.select(16)
  35.     turtle.place()
  36.     for i=1,15 do
  37.         turtle.select(i)
  38.         if turtle.getItemCount(i)>0 then
  39.             while not turtle.drop() do
  40.                 sleep(1)
  41.             end
  42.         end
  43.     end
  44.     turtle.select(16)
  45.     turtle.dig()
  46.     turtle.select(1)
  47. end
  48.  
  49. local function mine()
  50.     --steps in spiral path
  51.     local spiral={11,10,10,9,9,8,8,7,7,6,6,5,5,4,4,3}
  52.  
  53.     for i=1,#spiral do
  54.         --print(spiral[i])
  55.         for j=1,spiral[i] do
  56.             turtle.dig()
  57.             local emptyslot=0
  58.             for i=1,15 do
  59.                 if  turtle.getItemCount(i)<1 then
  60.                     emptyslot=emptyslot+1
  61.                 end
  62.             end
  63.             if emptyslot<1  then
  64.                 empty()
  65.             end
  66.             move(1)
  67.         end
  68.         turtle.turnRight()
  69.     end
  70.     turtle.turnLeft()
  71.     move(4)
  72.     turtle.turnLeft()
  73.     move(4)
  74.     turtle.turnLeft()
  75.     turtle.turnLeft()
  76.     empty()
  77. end
  78.  
  79.  
  80. local function home()
  81.     while true do
  82.         local success,data=turtle.inspect()
  83.         if success and data.name=="peripheralsplusone:rf_charger" then
  84.             turtle.turnLeft()
  85.             turtle.turnLeft()
  86.             return
  87.         end
  88.         if success==false or data.name~="tconstruct:clear_glass" then
  89.             turtle.dig()
  90.             move(1)
  91.         else
  92.             turtle.turnLeft()
  93.         end
  94.     end
  95. end
  96.  
  97.  
  98.  
  99. rednet.open("left")
  100. rednet.host("OrechidMiner","layer"..layer)
  101.  
  102. home()
  103. empty()
  104.  
  105. while true do
  106.     local _,message,_= rednet.receive()
  107.     if message=="go" then
  108.         mine()
  109.     end
  110. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement