Advertisement
lucifersamfr

feeder

Dec 17th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local sensor = peripheral.wrap("top")
  2. local rsSide = "back"
  3. local count = {}
  4. local specie = "Sheep"
  5. local min = 16
  6.  
  7. function enableFeeder()
  8.   rs.setOutput(rsSide, false)
  9.   print("Feeder enabled.")
  10. end
  11.  
  12. function disableFeeder()
  13.   rs.setOutput(rsSide, true)
  14.   print("Feeder disabled.")
  15. end
  16.  
  17. function reset()
  18.   count=0
  19. end
  20.  
  21. function add()
  22.   count = count +1
  23. end
  24.  
  25. function registerMob(id)
  26.   if pcall(function() mob = sensor.getMobData(id) end) then
  27.     local type = mob.name
  28.     --print(type.." found.")
  29.     if type==specie then
  30.       add()
  31.     end
  32.   else
  33.     print("error fetching fleeing animal.")
  34.   end
  35. end
  36.  
  37. disableFeeder()
  38. while true do
  39.   if not rs.getInput("bottom") then
  40.     print("Forced! Slaughterhouse must be running. Feeder enabled.")
  41.     rs.setOutput(rsSide, false)
  42.   else
  43.     reset()
  44.     for i,j in pairs(sensor.getMobIds()) do  
  45.       registerMob(j)
  46.     end
  47.     if count<min then
  48.       print(specie.."s count : "..count.." < "..min)
  49.       enableFeeder()
  50.     else
  51.       print(specie.."s count : "..count.." >= "..min)
  52.       disableFeeder()
  53.     end
  54.   end
  55.   sleep(30)
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement