Advertisement
Tacnuke

ender-lily farm

Mar 1st, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.58 KB | None | 0 0
  1. -- ender lily farm using TE autonomous activators, rednet cabling, vacuum hoppers, and itemducts
  2. local side = "bottom"  --side the monitor is on
  3. local tcolor = colors.white --text color
  4. local bgcolor = colors.red  -- background color
  5. local m =peripheral.wrap(side) -- wraps the peripheral for use
  6. local heading = "Time Remaining" --header text
  7.  
  8. m.clear() -- clears the monitor
  9. m.setCursorPos(1,1) --sets the cursor to the top left
  10. m.setTextScale(1) --sets the text scale on the monitor
  11. m.setTextColor(tcolor) -- sets text color
  12. m.setBackgroundColor(bgcolor) --sets background color
  13.  
  14. function center(text) --pretty self explanatory here.
  15.   x,y = m.getSize()
  16.   x1,y1 = m.getCursorPos()
  17.   m.setCursorPos((math.floor(x/2) - (math.floor(#text/2))), y1)
  18.   m.write(text)
  19. end
  20.  
  21. local function cycle()
  22.   rs.setBundledOutput("back", colors.white) --redstone on
  23.     sleep(1)
  24.   rs.setBundledOutput("back", 0) --redstone off
  25. end
  26.  
  27.  
  28. function time() --the countdown timer
  29.  
  30.   local su = fs.open("time", "r") -- opens the backup file in read only
  31.   local i = tonumber(su.readAll()) -- reads the time remaining
  32.  
  33.     repeat
  34.       m.setCursorPos(1,3)
  35.       center(heading) --centers the heading
  36.       m.setCursorPos(1,5)
  37.       i=i-1
  38.       center(tostring(i)) --centers the count down timer
  39.       sleep(1)
  40.       su.close() -- closes the read only file
  41.  
  42.        local f=fs.open("time", "w") -- opens the backup file in writable mode
  43.          f.write(tonumber(i)) -- updates the file
  44.          f.close() -- closes and saves the updates to the file
  45.    until i<1 --ending condition for the repeat loop
  46.    
  47.   m.clear() --clears the monitor
  48.   center("Harvesting and Planting") --display output when the timer finishes
  49.   cycle() -- fires the redstone pulse
  50.   m.clear() --clears the monitor again when done
  51.  
  52.   local Res = fs.open("time", "w") --opens the backup in writable mode again
  53.   Res.write(tonumber(8500)) --resets the time for ~1 minecraft week
  54.   Res.close() --saves the update and closes the file
  55.  
  56. end
  57.  
  58. while true do
  59. --center(textutils.formatTime(os.time(), false)) displays the current minecraft time @start. won't update yet.
  60. local h = fs.open("time", fs.exists("time") and "a" or "w") --checks if the file exits
  61. local defTime = "8500" --rough time in a minecraft week in seconds
  62.   if not h then
  63.   print("File not found. Creating new file.")
  64.   h.write(tonumber(defTime)) --creates the file with you starting run time
  65.   h.close()
  66.   else
  67.   print("Reading file...")
  68.   local r=fs.open("time", "r")
  69.   local res=r.readAll()
  70.   sleep(1)
  71.   time()
  72.   print("Resetting")
  73.   sleep(1)
  74.   end
  75. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement