Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bRedNet = false
- local nBatterySlot = 1
- -- ----------------------------------------------------------
- local function say(message)
- if bRedNet == true then
- rednet.send(nMasterComputerID, message)
- end
- print(message)
- -- sleep(0.2)
- end
- -- ----------------------------------------------------------
- local function turnLeft()
- turtle.turnLeft()
- end
- -- ----------------------------------------------------------
- local function turnRight()
- turtle.turnRight()
- end
- -- ----------------------------------------------------------
- local function getFreeSlots()
- local nSpace = 0
- for invloop=1,16 do
- local items = turtle.getItemCount(invloop)
- if items == 0 then
- nSpace = nSpace + 1
- end
- end
- return nSpace
- end
- -- ----------------------------------------------------------
- local function tryForwards()
- local nMaxTries = 10
- local nTries = 0
- while not turtle.forward() do
- sleep(0.8)
- nTries = nTries + 1
- if nTries >= nMaxTries then
- return false
- end
- end
- return true
- end
- -- ----------------------------------------------------------
- local function recharge()
- say("trying to recharge")
- turtle.select(nBatterySlot)
- local e = turtle.getFuelLevel()
- turtle.refuel()
- nEnergy = turtle.getFuelLevel()
- say("fuel: "..e.." -> "..nEnergy)
- if nEnergy > e then
- return true
- end
- return false
- end
- -- ----------------------------------------------------------
- -- ----------------------------------------------------------
- local function waitForEnergy()
- local count = 0
- local hasEnergy = false
- say("Waiting for energy in Slot "..nBatterySlot)
- while not hasEnergy do
- if recharge() == true then
- hasEnergy = true
- return true
- else
- sleep(5)
- count = count + 1
- if count == 5 then
- say("Waiting for energy in Slot "..nBatterySlot)
- count = 0
- end
- end
- end
- return true
- end
- -- ----------------------------------------------------------
- local function isOperational()
- -- get energy
- local nEnergyLevel = turtle.getFuelLevel()
- local required = 20
- if nEnergyLevel <= required then
- waitForEnergy()
- end
- -- all cool
- return true
- end
- -- ----------------------------------------------------------
- local function loopi()
- isOperational()
- while not turtle.suck() do
- sleep(2)
- end
- turnRight()
- turnRight()
- tryForwards()
- tryForwards()
- tryForwards()
- turnLeft()
- tryForwards()
- turnRight()
- tryForwards()
- tryForwards()
- tryForwards()
- tryForwards()
- turnLeft()
- tryForwards()
- turtle.select(2)
- turtle.drop()
- turnLeft()
- turnLeft()
- tryForwards()
- turnRight()
- tryForwards()
- tryForwards()
- tryForwards()
- tryForwards()
- turnLeft()
- tryForwards()
- turnRight()
- tryForwards()
- tryForwards()
- tryForwards()
- turtle.select(2)
- turtle.drop()
- return true
- end
- local done = false
- while not done do
- loopi()
- end
Advertisement
Add Comment
Please, Sign In to add comment