Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- startup script for mining turtles
- function ack(id)
- rednet.send(id, "ack")
- end
- rednet.close("right")
- rednet.open("right")
- function findDirection()
- local ret = 0
- local oldX, _, oldZ = gps.locate(1)
- print("location 1: "..oldX.." "..oldZ)
- local moved = false
- for d = 1,4 do
- print("testing direction "..d)
- if not turtle.detect() then
- while not turtle.forward() do
- turtle.attack()
- sleep(0.25)
- end
- moved = true
- break
- else
- turtle.turnRight()
- end
- end
- if not moved then
- turtle.dig()
- while not turtle.forward() do
- turtle.attack()
- sleep(0.25)
- end
- end
- local newX, _, newZ = gps.locate(1)
- print("location 2: "..newX.." "..newZ)
- while not turtle.back() do
- sleep(0.25)
- end
- local deltaX = newX - oldX
- local deltaZ = newZ - oldZ
- if deltaX == 1 then
- ret = 4
- elseif deltaX == -1 then
- ret = 2
- elseif deltaZ == 1 then
- ret = 1
- elseif deltaZ == -1 then
- ret = 3
- end
- print("found direction: "..ret)
- return ret
- end
- local pos = {}
- -- print("which direction am i facing?")
- -- pos[4] = tonumber(read())
- sleep(5)
- pos[4] = findDirection()
- pos[1], pos[2], pos[3] = gps.locate(1)
- local statefile = "state"
- local fh = fs.open(statefile, "w")
- for i = 1,4 do
- fh.writeLine(tostring(pos[i]))
- end
- fh.close()
- local state = {}
- local metastatefile = "metastate"
- local mfh = fs.open(metastatefile, "r")
- for i = 1,10 do
- state[i] = tonumber(mfh.readLine())
- end
- mfh.close()
- for Z = 1,state[8] do
- for X = 1,state[7] do
- local mineX = state[1] + (X - 1) * 5
- local mineZ = state[2] + (Z - 1) * 5
- if (Z >= state[10]) and (X >= state[9]) then
- print("going to mine at "..mineX.." "..mineZ)--..", dropping loot at "..state[3].." "..state[4].." "..state[5].." "..state[6])
- shell.run("miminer "..mineX.." "..mineZ.." "..state[3].." "..state[4].." "..state[5].." "..state[6])
- mfh = fs.open(metastatefile, "w")
- for i = 1,8 do
- mfh.writeLine(tostring(state[i]))
- end
- mfh.writeLine(tostring(X))
- mfh.writeLine(tostring(Z))
- mfh.close()
- sleep(5)
- else
- print("already mined out "..mineX.." "..mineZ)
- end
- end
- end
- -- while true do
- -- local msg = ""
- -- print("broadcasting ready signal")
- -- rednet.broadcast("drone ready")
- -- id, msg, _ = rednet.receive(10)
- -- if msg ~= "" then
- -- print("answer received")
- -- if msg == "mine at" then
- -- ack(id)
- -- args = {}
- -- for i = 1,6 do
- -- id, args[i], _ = rednet.receive()
- -- print("received: ", args[i])
- -- ack(id)
- -- end
- -- print("going to mine at "..args[1].." "..args[2]..", dropping loot at "..args[3].." "..args[4].." "..args[5].." "..args[6])
- -- shell.run("miminer ", args[1].." "..args[2].." "..args[3].." "..args[4].." "..args[5].." "..args[6]) -- go do stuff
- -- else
- -- os.sleep(10)
- -- end
- -- end
- -- end
Advertisement
Add Comment
Please, Sign In to add comment