Advertisement
skypop

CocoaFarmer

Sep 16th, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.76 KB | None | 0 0
  1. local i,test,item
  2. local function selectBean()
  3.     for i=1,16 do
  4.         item = turtle.getItemDetail(i)
  5.         if item and item.name=="minecraft:dye" and item.damage==3 then
  6.             turtle.select(i)
  7.             return true
  8.         end
  9.     end
  10.     return false
  11. end
  12.  
  13. local function crop()
  14.     for i=1,4 do
  15.         test,item = turtle.inspect()
  16.         if test and item.name=="minecraft:cocoa" and item.state.age==2 then
  17.             turtle.dig()
  18.             if selectBean() then
  19.                 turtle.place()
  20.             end
  21.         end
  22.         turtle.turnLeft()
  23.     end
  24. end
  25.  
  26. local _f = math.floor
  27. local function strTime(sec)
  28.     local str,d,h,m,s = "",_f(sec/86400),_f(sec/3600)%24,_f(sec/60)%60,_f(sec%60)
  29.     if d>0 then str = d>1 and d.." days " or "1 day " end
  30.     if h>0 then str = str..h.."h" end
  31.     if m>0 then str = str..(m>9 and m or "0"..m) end
  32.     if h==0 then str = m>0 and str..":"..(s>9 and s or "0"..s) or s.."s" end
  33.     return str
  34. end
  35. local w,h = term.getSize()
  36. local function computer()
  37.     term.setBackgroundColor(colors.white)
  38.     term.setTextColor(colors.black)
  39.     term.setCursorPos(1,1) term.clearLine()
  40.     term.write("#"..os.getComputerID().." - "..os.getComputerLabel())
  41.     term.setCursorPos(1,2) term.clearLine()
  42.     term.write("Running: "..strTime(os.clock()))
  43.     term.setBackgroundColor(colors.black)
  44.     term.setTextColour(colors.gray)
  45.     term.setCursorPos(1,3) term.clearLine()
  46.     term.write(string.rep(string.char(131),w))
  47.     term.setTextColor(colors.white)
  48. end
  49.  
  50. term.clear()
  51. computer()
  52. local batch,tick,e,p = os.startTimer(.1),os.startTimer(1)
  53. while true do
  54.     e,p = os.pullEvent("timer")
  55.     if p==batch then
  56.         os.cancelTimer(tick)
  57.         rs.setOutput("bottom",true) -- lock hopper
  58.         crop()
  59.         rs.setOutput("bottom",false) -- unlock hopper
  60.         batch = os.startTimer(60) --1 min
  61.         tick = os.startTimer(1)
  62.     elseif p==tick then
  63.         computer()
  64.         tick = os.startTimer(1)
  65.     end
  66. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement