Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (fs.exists("choices") == false) then --Check if this is first time run, no saved choices on file
- while true do
- print("Which layer?")
- local answer = read()
- if tonumber(answer)==nill then
- print("-Wrong answer, input not a number-")
- else
- local answerv = tonumber(string.format("%." .. 0 .. "f", answer))
- layer=answerv
- print("Layer ", layer, " chosen")
- break
- end
- end
- local file = fs.open("choices","w")
- file.writeLine("layer="..tostring(layer))
- file.close()
- end
- os.loadAPI("choices") -- Reads choices from file
- local layer= choices.layer
- local function move(steps)
- for i=1,steps do
- while not turtle.forward() do
- sleep(1)
- end
- end
- end
- local function empty()
- turtle.select(16)
- turtle.place()
- for i=1,15 do
- turtle.select(i)
- if turtle.getItemCount(i)>0 then
- while not turtle.drop() do
- sleep(1)
- end
- end
- end
- turtle.select(16)
- turtle.dig()
- turtle.select(1)
- end
- local function mine()
- --steps in spiral path
- local spiral={11,10,10,9,9,8,8,7,7,6,6,5,5,4,4,3}
- for i=1,#spiral do
- --print(spiral[i])
- for j=1,spiral[i] do
- turtle.dig()
- local emptyslot=0
- for i=1,15 do
- if turtle.getItemCount(i)<1 then
- emptyslot=emptyslot+1
- end
- end
- if emptyslot<1 then
- empty()
- end
- move(1)
- end
- turtle.turnRight()
- end
- turtle.turnLeft()
- move(4)
- turtle.turnLeft()
- move(4)
- turtle.turnLeft()
- turtle.turnLeft()
- empty()
- end
- local function home()
- while true do
- local success,data=turtle.inspect()
- if success and data.name=="peripheralsplusone:rf_charger" then
- turtle.turnLeft()
- turtle.turnLeft()
- return
- end
- if success==false or data.name~="tconstruct:clear_glass" then
- turtle.dig()
- move(1)
- else
- turtle.turnLeft()
- end
- end
- end
- rednet.open("left")
- rednet.host("OrechidMiner","layer"..layer)
- home()
- empty()
- while true do
- local _,message,_= rednet.receive()
- if message=="go" then
- mine()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement