Advertisement
problemlow

SugarCaneLine

May 24th, 2024 (edited)
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.01 KB | None | 0 0
  1. function searchString(bigString, searchString)
  2.     if bigString ~= nil and searchString ~= nil then
  3.         if bigString.match(bigString, searchString) == nil then
  4.             return false
  5.         else
  6.             return true
  7.         end
  8.     else
  9.         return false
  10.     end
  11. end
  12.  
  13.  
  14. function forwardMine()
  15.     turtle.select(1)
  16.     while turtle.getFuelLevel() == 0 do
  17.         OSName()
  18.         print("I need more fuel in slot 16")
  19.         turtle.select(16)
  20.         turtle.refuel(1)
  21.         turtle.select(1)
  22.         sleep(2.5)
  23.     end
  24.     tf, data = turtle.inspect()
  25.     name = data.name
  26.     if searchString(name, "sugar") == true then
  27.         dug = turtle.dig()
  28.     elseif searchString(name, "glass") == true then
  29.         turtle.turnRight()
  30.     elseif searchString(name, "redstone") == true then
  31.         print("")
  32.     elseif name == nil then
  33.         print("")
  34.     else
  35.         print("Something unexpected is here, im gonna wait for a human to hit enter just incase\nBlock Detected: ".. tostring(name))
  36.         read()
  37.         print("Restarting")
  38.     end
  39.     if dug == true then
  40.         dug = false
  41.         local mined = tonumber(load("total"))
  42.         mined = mined+1
  43.         save("total", mined)
  44.     end
  45.     moved = turtle.forward()
  46.     if redstone.getInput("front") == true then
  47.         print("Initiate deposit boogie")
  48.         for slot = 1,15 do
  49.             turtle.select(slot)
  50.             turtle.dropUp(64)
  51.             turtle.turnRight()
  52.             turtle.turnRight()
  53.         end
  54.     end
  55. end
  56.  
  57.  
  58. function OSName()
  59.     shell.run("clear")
  60.     local total = load("total")
  61.     print("ProSugarPlantation v1.1\nCollected a total of "..total.." sugar cane")
  62. end
  63.  
  64.  
  65. function save(filename, data)
  66.     local file,err = io.open(filename .. ".txt",'w')
  67.     if file then
  68.         file:write(tostring(data))
  69.         file:close()
  70.     else
  71.         print("error:", err)
  72.     end
  73. end
  74.  
  75.  
  76. function load(filename)
  77.     local file = io.open(filename .. ".txt", "r")
  78.     if file then
  79.         local firstLine = file:read("*l")
  80.         io.close(file)
  81.         return firstLine
  82.     else
  83.         print(filename .. ".txt")
  84.         return nil
  85.     end
  86. end
  87.  
  88.  
  89. while true do
  90.     OSName()
  91.     forwardMine()
  92. end
  93. shell.run("reboot")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement