Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Version 1.0
- args = {...}
- size = 0
- state = 1
- states = {"MINE", "REFUEL", "DEPOSIT","FINISHED"}
- os.loadAPI("oreMine/oreMine.lua")
- os.loadAPI("oreMine/move.lua")
- function createStart()
- h = fs.open("startup","w")
- h.writeLine("shell.run(\"oreMine/search.lua\")")
- h.close()
- end
- function deleteStart()
- fs.delete("startup")
- fs.delete("oreMine/size.lua")
- fs.delete("oreMine/pos.lua")
- fs.delete("oreMine/loc.lua")
- end
- function saveState()
- h = fs.open("oreMine/size.lua","w")
- h.writeLine(size)
- h.writeLine(state)
- h.close()
- end
- function readState()
- h = fs.open("oreMine/size.lua","r")
- size = tonumber(h.readLine())
- state = tonumber(h.readLine())
- h.close()
- end
- function saveLoc()
- h = fs.open("oreMine/loc.lua","w")
- h.writeLine(move.getx())
- h.writeLine(move.gety())
- h.writeLine(move.getz())
- h.close()
- end
- function getLoc()
- tx = 0
- ty = 0
- tz = 0
- h = fs.open("oreMine/loc.lua","r")
- tx = tonumber(h.readLine())
- ty = tonumber(h.readLine())
- tz = tonumber(h.readLine())
- h.close()
- return tx, ty, tz
- end
- function saveOreLoc()
- h = fs.open("oreMine/oreLoc.lua","w")
- h.writeLine(move.getx())
- h.writeLine(move.gety())
- h.writeLine(move.getz())
- h.close()
- end
- function delOreLoc()
- fs.delete("oreMine/oreLoc.lua")
- end
- function getOreLoc()
- tx = 0
- ty = 0
- tz = 0
- h = fs.open("oreMine/oreLoc.lua","r")
- tx = tonumber(h.readLine())
- ty = tonumber(h.readLine())
- tz = tonumber(h.readLine())
- h.close()
- return tx, ty, tz
- end
- function mine()
- state = 1
- saveState()
- if move.getx() > size then
- state = 4
- saveState()
- end
- if move.getz() == -1*size and (move.getx()%2 == 0) then
- move.move(move.getx()+1, move.gety() , move.getz())
- saveOreLoc()
- oreMine.find()
- delOreLoc()
- return
- end
- if move.getz() == 0 and (move.getx()%2 ~= 0) then
- move.move(move.getx()+1, move.gety(), move.getz())
- saveOreLoc()
- oreMine.find()
- delOreLoc()
- return
- end
- if move.getx()%2 == 0 then
- move.face(1)
- move.forward()
- saveOreLoc()
- oreMine.find()
- delOreLoc()
- elseif move.getx()%2 ~= 0 then
- move.face(3)
- move.forward()
- saveOreLoc()
- oreMine.find()
- delOreLoc()
- end
- end
- function fuel()
- if turtle.getFuelLevel() < 300 then
- state = 2
- saveState()
- for i = 1,16 do
- turtle.select(i)
- turtle.refuel(64)
- end
- end
- if turtle.getFuelLevel() < 300 then
- state = 2
- saveState()
- print("Out of Fuel")
- if not fs.exists("oreMine/loc.lua") then
- saveLoc()
- end
- move.move(0,0,0)
- move.face(3)
- for i = 1,16 do
- turtle.select(i)
- turtle.drop()
- end
- move.up()
- while turtle.getFuelLevel() < 1000 do
- turtle.select(1)
- turtle.drop()
- turtle.suck(64)
- turtle.refuel(64)
- end
- move.move(getLoc())
- fs.delete("oreMine/loc.lua")
- end
- end
- function deposit()
- num = 0
- for i = 1,16 do
- if turtle.getItemCount(i) > 0 then
- num = num + 1
- end
- end
- if num < 15 then
- return false
- end
- state = 3
- saveState()
- print("Depositing Items")
- if not fs.exists("oreMine/loc.lua") then
- saveLoc()
- end
- move.move(0,0,0)
- move.face(3)
- for i = 1, 16 do
- turtle.select(i)
- turtle.refuel(32)
- turtle.drop()
- end
- move.move(getLoc())
- fs.delete("oreMine/loc.lua")
- return true
- end
- if tonumber(args[1]) then
- size = tonumber(args[1])
- saveState()
- elseif fs.exists("oreMine/size.lua") then
- readState()
- else
- print("Please enter a number")
- return
- end
- if fs.exists("oreMine/oreLoc.lua") then
- move.move(getOreLoc())
- end
- if 1*state == 2 then
- fuel()
- elseif 1*state == 3 then
- deposit()
- end
- createStart()
- while state ~= 4 do
- mine()
- deposit()
- fuel()
- end
- move.move(0,0,0)
- move.face(1)
- deleteStart()
- print("Finished Mining!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement