Advertisement
TechManDylan

SnowShovelerTurtle

Jul 11th, 2024 (edited)
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 KB | None | 0 0
  1. -- File to store the count of broken snow blocks
  2. local snowCountFile = "snow_count.txt"
  3.  
  4. -- Function to read the snow count from the file
  5. local function readSnowCount()
  6.     if fs.exists(snowCountFile) then
  7.         local file = fs.open(snowCountFile, "r")
  8.         local count = tonumber(file.readLine())
  9.         file.close()
  10.         return count or 0
  11.     else
  12.         return 0
  13.     end
  14. end
  15.  
  16. -- Function to write the snow count to the file
  17. local function writeSnowCount(count)
  18.     local file = fs.open(snowCountFile, "w")
  19.     file.writeLine(tostring(count))
  20.     file.close()
  21. end
  22.  
  23. -- Initialize the count of broken snow blocks from the file
  24. local snowCount = readSnowCount()
  25.  
  26. -- Function to check if the block in front is snow and break it if so
  27. local function checkAndBreakSnow()
  28.     -- Get the block details in front of the turtle
  29.     local success, data = turtle.inspect()
  30.    
  31.     if success and data.name == "minecraft:snow" then
  32.         -- Break the block in front
  33.         turtle.dig()
  34.        
  35.         -- Increment the snow block count
  36.         snowCount = snowCount + 1
  37.        
  38.         -- Write the updated count to the file
  39.         writeSnowCount(snowCount)
  40.        
  41.         -- Display the count on the screen
  42.         term.clear()
  43.         term.setCursorPos(1, 1)
  44.         print("Snow blocks broken:")
  45.         term.setCursorPos(1, 2)
  46.         print(snowCount)
  47.     end
  48. end
  49.  
  50. -- Main loop to keep checking and breaking snow blocks
  51. while true do
  52.     checkAndBreakSnow()
  53.     -- Wait a short period before checking again
  54.     sleep(0.5)
  55. end
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement