largeNumberGoeshere

Certus quartz cluster miner

Mar 4th, 2025 (edited)
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.41 KB | None | 0 0
  1. -- certus quartz cluster miner
  2. -- setup a detector and this turtle next to a budding certus quartz to mine it automatically on maturity
  3.  
  4. local function epocSecs()
  5.     return os.epoch() / (60 * 1000)
  6. end
  7.  
  8.  
  9.  
  10. -- constants
  11. local updateSide = "left"
  12. local maxUpdates = 5 -- the max level of states. 0 to this number
  13. local minState = 0
  14. local reset = minState -2   -- two updates are sent when the block generates, so the first update sets the state to minState
  15. local timeoutPeriod = 5 * 60 -- in secconds
  16.  
  17. -- variables
  18. local updates = 0
  19. local prevUpdates = 0
  20. local lastUpdateTime = epocSecs()
  21.  
  22. -- reset the system on reboot
  23. turtle.dig()
  24.  
  25.  
  26. -- main loop
  27. while true do
  28.     if updates >= maxUpdates  then
  29.        sleep(1)
  30.        print("ready to dig")
  31.        turtle.dig()
  32.        
  33.        updates = reset
  34.        lastUpdateTime = epocSecs()
  35.     end
  36.    
  37.     if not turtle.detect() then
  38.         if updates ~= -1 then
  39.             updates = reset
  40.         end
  41.         lastUpdateTime = epocSecs()
  42.     end
  43.    
  44.    
  45.     if rs.getInput(updateSide) == true then
  46.         updates = updates + 1
  47.     end
  48.    
  49.    
  50.     if (lastUpdateTime + timeoutPeriod) < epocSecs() then
  51.         print("Timeout... Resetting")
  52.         lastUpdateTime = epocSecs()
  53.         turtle.dig()
  54.         updates = reset
  55.     end
  56.    
  57.    
  58.     if updates ~= prevUpdates then
  59.         print("update " .. tostring(updates))
  60.         print("elapsed ".. epocSecs() - lastUpdateTime)
  61.         prevUpdates = updates
  62.     end
  63.    
  64.     sleep(0.05)
  65. end
  66.  
Advertisement
Add Comment
Please, Sign In to add comment