Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------------- Direwolf20 autominer script - mining turtle
- -- Use group of turtles for automining.
- -- Controller turtle give commands to other turtles for real job and provides power.
- -- Tutorial: http://www.youtube.com/watch?v=uXhBzaaEtAs
- ------ Turtle setup (inventory slot = contents):
- -- Miner: 13|14|15|16 = coal chest | drop off chest | Mining well | Energy conduit
- -- FuelBoss: 12|13|14|15|16 = cobblestone | coal chest | drop off chest | Mining well | Energy conduit
- -- Chunkloader: 13|16 = coal chest | chunkloader
- -- Controller: 1|2 = energy tesseract setup with shiny metal | Energy condiut
- ------ Usage:
- ---- Legend:
- -- P = controller turtle (see mainProg script), must be 1 level above other turtles
- -- F = fuel boss + automining turtle - fuels P, must be next to it
- -- A = automining turtle, repeat as much as you need
- -- C = chunkloader turtle, not shown below, should be before and after mining group
- ---- Place turtles vertically like this:
- -- P
- -- AAF
- ---- Startup program:
- -- for P - any, just execute mainProg NNN
- -- F: shell.run("miner","fuelBoss")
- -- A: shell.run("miner","Miner")
- -- C: shell.run("miner","chunkloader")
- rednet.open("right")
- local func, compileResult
- local tArgs = {...}
- local myName
- local enderChests = 1
- function cleanup()
- if enderChests==0 then
- turtle.turnRight() -- if we don't have ender chest, we face our neighbour to the right
- end
- -- clean up general slots
- for i = 1,11 do
- turtle.select(i)
- -- just for fuelBoss - stock up with cobblestone in 12
- if myName=="fuelBoss" and turtle.compareTo(12) then
- turtle.transferTo(12)
- end
- cleanupDrop()
- end
- -- fuelBoss keeps cobble in 12, others just drop it
- if not myName=="fuelBoss" then
- turtle.select(12)
- cleanupDrop()
- end
- if enderChests==0 then
- turtle.turnLeft() -- at the end face original direction
- end
- end
- function cleanupDrop()
- if enderChests>0 then
- turtle.dropDown() -- if we have enderchest, we drop down to it
- else
- turtle.drop() -- else we drop to the turtle in front of use (assuming rotation already took place)
- end
- end
- function place()
- clearFront()
- turtle.select(16)
- turtle.place()
- clearDown()
- turtle.down()
- clearFront()
- turtle.select(15)
- turtle.place()
- clearDown()
- turtle.select(14)
- turtle.placeDown()
- end
- function remove()
- turtle.select(14)
- turtle.trasnferTo(1)
- turtle.dropUp()
- turtle.digDown()
- turtle.select(15)
- turtle.trasnferTo(2)
- turtle.dropUp()
- turtle.dig()
- turtle.up()
- turtle.select(16)
- turtle.trasnferTo(3)
- turtle.dropUp()
- turtle.dig()
- end
- function fuel()
- print("In fuel")
- if enderChests == 1 then
- print("Fueling")
- placeFuelChest()
- turtle.select(1)
- turtle.suckUp()
- turtle.dropUp(turtle.getItemCount(1) - 4)
- turtle.refuel()
- removeFuelChest()
- end
- end
- function fuelBoss()
- placeFuelChest()
- turtle.select(1)
- turtle.suckUp()
- turtle.dropUp(turtle.getItemCount(1) - 4)
- removeFuelChest()
- turtle.up()
- turtle.turnRight()
- turtle.select(1)
- turtle.drop()
- turtle.turnLeft()
- turtle.down()
- end
- function placeFuelChest()
- turtle.select(13)
- turtle.placeUp()
- end
- function removeFuelChest()
- turtle.select(13)
- turtle.digUp()
- end
- function checkFuel()
- if turtle.getFuelLevel() < 400 then
- fuel()
- end
- end
- function isMiningWellActive()
- local miningWell = peripheral.wrap("front")
- return miningWell.isActive()
- end
- function cycle()
- place()
- -- local totalWorkDuration = os.startTimer(25)
- local countDown = 20
- local countDownThreshold = 21
- local hadItem = false
- sleep(5)
- while countDown > 0 do
- if turtle.getItemCount(1) > 0 then
- print("Now I had item")
- hadItem = true
- end
- cleanup()
- sleep(3)
- local hasItem = false
- if hadItem and countDown < countDownThreshold then -- wait for first item to appear, then check for new items
- for slot=1,11 do
- if turtle.getItemCount(slot) > 0 then
- hasItem = true
- end
- end
- end
- if(not(hasItem)) then
- print("No items, so probably done")
- break
- end
- countDown = countDown - 1
- end
- while turtle.getItemCount(1) > 0 do
- print("Still not clean")
- cleanup()
- sleep(2)
- end
- remove()
- checkFuel()
- -- fuel boss will leave track of cobblestone behind it - takes from slot 12
- -- if we run out of cobble, we will keep 1 specimen for restocking - see cleanup function
- if myName == "fuelBoss" and turtle.getItemCount(12)>1 then
- turtle.select(12)
- turtle.placeDown()
- end
- -- Step forward - for resiliency against obstacles break anything around
- clearFront()
- turtle.forward()
- clearUp()
- clearDown()
- -- fuelBoss also makes way for controller turtle
- if myName == "fuelBoss" then
- clearFront()
- turtle.forward()
- turtle.turnRight()
- clearFront()
- turtle.forward()
- clearUp()
- clearDown()
- turtle.back()
- turtle.turnLeft()
- turtle.back()
- end
- end
- -- custom sleep function with double timers
- function waitForTimer(mainTimer, sleepDuration)
- local sleepTimer = os.startTimer(sleepDuration)
- local bigTimerHit = 0
- repeat
- local sEvent, param = os.pullEvent( "timer" )
- if param == mainTimer then
- bigTimerHit = 1
- end
- until param == sleepTimer
- return bigTimerHit == 1
- end
- function clearFront()
- turtle.select(2)
- turtle.dig()
- turtle.drop()
- end
- function clearDown()
- turtle.select(2)
- turtle.digDown()
- turtle.dropDown()
- end
- function clearUp()
- turtle.select(2)
- turtle.digUp()
- turtle.dropUp()
- end
- function checkIn(fromID)
- local msg = myName
- if myName == "Miner" or myName == "fuelBoss" then
- msg = myName.."|"..enderChests
- end
- rednet.send(fromID, msg)
- end
- function reboot()
- print("Rebooting...")
- sleep(1)
- os.reboot()
- end
- function chunkLoad()
- turtle.select(16)
- turtle.digUp()
- checkFuel()
- clearFront()
- turtle.forward()
- clearUp()
- turtle.select(16)
- turtle.placeUp()
- end
- function update(id)
- fs.delete("mine_update")
- shell.run("pastebin","get","0jbMsR9D","mine_update")
- if fs.exists("mine_update") then
- fs.delete("mine_backup")
- if fs.exists("mine") then
- fs.move("mine", "mine_backup")
- end
- fs.move("mine_update", "mine")
- end
- shell.run("pastebin","get","5Tx1TifC","mainProg_update")
- if fs.exists("mainProg_update") then
- fs.delete("mainProg_backup")
- if fs.exists("mainProg") then
- fs.move("mainProg", "mainProg_backup")
- end
- fs.move("mainProg_update", "mainProg")
- end
- if id ~= nil then
- rednet.send(id,"Done")
- os.reboot()
- end
- end
- function reportFuelRequests(id)
- if turtle.getFuelLevel() < 400 then
- print("Need fuel")
- rednet.send(id, "needFuel")
- end
- end
- function grabFuel()
- print ("Grabbing fuel")
- turtle.select(1)
- turtle.drop()
- turtle.up()
- turtle.turnRight()
- local distance = 0
- while turtle.forward() do
- distance = distance + 1
- end
- turtle.select(1)
- turtle.suck()
- turtle.drop(turtle.getItemCount(1) - 4)
- turtle.refuel()
- print("Fuel level: "..turtle.getFuelLevel())
- for i=1,distance do
- turtle.back()
- end
- turtle.turnLeft()
- turtle.down()
- end
- function moveForward()
- cycleFunction(50, function() return turtle.forward() end)
- end
- function moveBack()
- cycleFunction(50, function() return turtle.back() end)
- end
- function turnLeft()
- turtle.turnLeft()
- end
- function turnRight()
- turtle.turnRight()
- end
- function moveDown()
- cycleFunction(50, function() return turtle.down() end)
- end
- function moveUp()
- cycleFunction(50, function() return turtle.up() end)
- end
- function cycleFunction(count,func)
- while not func() and count>0 do
- count = count - 1
- sleep(0.3)
- end
- if count == 0 then
- print("Limit reached! Stopping cycle!")
- end
- end
- function echo(id)
- print("Echo from "..id)
- end
- function writeStartup(turtleName)
- fs.delete("startup")
- local startupFile = fs.open("startup", "w")
- startupFile.writeLine("shell.run(\"mine\",\""..turtleName.."\")")
- startupFile.close()
- end
- -------------------------
- print("Start time: ", textutils.formatTime(os.time(), true))
- if #tArgs == 1 and "update" == (tArgs[1].."") then
- update()
- error()
- end
- if #tArgs == 1 and "startup-fuelBoss" == (tArgs[1].."") then
- writeStartup("fuelBoss")
- error()
- end
- if #tArgs == 1 and "startup-chunkloader" == (tArgs[1].."") then
- writeStartup("chunkloader")
- error()
- end
- if #tArgs == 1 and "startup-Miner" == (tArgs[1].."") then
- writeStartup("Miner")
- error()
- end
- myName = tArgs[1]..""
- if tArgs[2] ~= nil then
- enderChests = math.min(1, tonumber(tArgs[2]))
- end
- assert(myName == "fuelBoss" or myName == "chunkloader" or myName == "Miner", "Unsupported turtle name"..myName)
- print("My name is "..myName..", ender chests: "..enderChests)
- checkFuel()
- while true do
- local id,msg,dist = rednet.receive()
- func, compileResult = loadstring(msg.."(...)")
- print(func)
- print(compileResult)
- if func == nil then
- print("Unknown function "..msg..". Skipping execution.")
- else
- setfenv(func, getfenv())
- func(id)
- rednet.send(id,"Done")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment