GraySloth

ComputerCraft: MiscPeripherals: 'Feed'

Feb 15th, 2013
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.79 KB | None | 0 0
  1. --v1.3 by GraySloth 2013-Feb-23 for the miscPeripheral mod with the Feeding Module it feeds animals between 6am and noon in-game time
  2. --wheat carrot or seeds depending on the animal need to be in the only item in the turtle, and can only use one of those types of food at a time.
  3. --it sends a redstone signal to output(bottom by default) if it can't find food, it can also be forced to feed manually if a redstone signal is sent to input(bottom by default) and can be set to always feed if alwaysOn is true
  4.  
  5. --variables
  6. local feeder = peripheral.wrap("right")
  7. --available locations: top, bottom, left, right, front or back
  8. local input = "bottom" --receives signal for manual feeding
  9. local output = "bottom" --sends signal when out of food
  10. local alwaysOn = false --true sets to always feed
  11. --functions
  12. function clear()
  13.    term.clear()
  14.    term.setCursorPos(1,1)
  15. end
  16.  
  17. function food()
  18.    if turtle.getItemCount(1) == 0 then
  19.       clear()
  20.       print("Needs more food")
  21.       print("Searching for food hold ctrl+t to stop")
  22.       while turtle.getItemCount(1) == 0 do
  23.          redstone.setOutput(output, true)
  24.          for n=2,16 do
  25.             if turtle.getItemCount(1) == 0 then
  26.                turtle.select(n)
  27.                turtle.transferTo(1)
  28.         end
  29.          end
  30.       end
  31.       print("Food selected")
  32.       redstone.setOutput(output, false)
  33.    end
  34. end
  35.  
  36.  
  37. --Main
  38. while true do
  39.    if (os.time() > 6) and (os.time() < 12) or (redstone.getInput(input)) or alwaysOn then
  40.       clear()
  41.       print(textutils.formatTime(os.time(),true))
  42.       print("Feeding time!")
  43.       food()
  44.       turtle.select(1)
  45.       feeder.feed()
  46.       os.sleep(1)
  47.    else
  48.       clear()
  49.       print(textutils.formatTime(os.time(),true))
  50.       print("waiting till morning")
  51.       food()
  52.       os.sleep(1)
  53.    end
  54. end
Advertisement
Add Comment
Please, Sign In to add comment