Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- certus quartz cluster miner
- -- setup a detector and this turtle next to a budding certus quartz to mine it automatically on maturity
- local function epocSecs()
- return os.epoch() / (60 * 1000)
- end
- -- constants
- local updateSide = "left"
- local maxUpdates = 5 -- the max level of states. 0 to this number
- local minState = 0
- local reset = minState -2 -- two updates are sent when the block generates, so the first update sets the state to minState
- local timeoutPeriod = 5 * 60 -- in secconds
- -- variables
- local updates = 0
- local prevUpdates = 0
- local lastUpdateTime = epocSecs()
- -- reset the system on reboot
- turtle.dig()
- -- main loop
- while true do
- if updates >= maxUpdates then
- sleep(1)
- print("ready to dig")
- turtle.dig()
- updates = reset
- lastUpdateTime = epocSecs()
- end
- if not turtle.detect() then
- if updates ~= -1 then
- updates = reset
- end
- lastUpdateTime = epocSecs()
- end
- if rs.getInput(updateSide) == true then
- updates = updates + 1
- end
- if (lastUpdateTime + timeoutPeriod) < epocSecs() then
- print("Timeout... Resetting")
- lastUpdateTime = epocSecs()
- turtle.dig()
- updates = reset
- end
- if updates ~= prevUpdates then
- print("update " .. tostring(updates))
- print("elapsed ".. epocSecs() - lastUpdateTime)
- prevUpdates = updates
- end
- sleep(0.05)
- end
Advertisement
Add Comment
Please, Sign In to add comment