TheDieselPunk

Autofeed

May 9th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local modules = peripheral.find("manipulator") or peripheral.find("neuralInterface")
  2. if not modules then
  3.     error("Must have neural interface or manipulator", 0)
  4. end
  5.  
  6. if not modules.hasModule("plethora:sensor") then
  7.     error("The entity sensor is missing", 0)
  8. end
  9. if not modules.hasModule("plethora:introspection") then
  10.     error("The introspection module is missing", 0)
  11. end
  12.  
  13. local inv = modules.getInventory()
  14.  
  15. local cachedSlot = false
  16. while true do
  17.     local data = modules.getMetaOwner()
  18.     while data.food.hungry do
  19.         local item
  20.         if cachedSlot then
  21.             local slotItem = inv.getItem(cachedSlot)
  22.             if slotItem and slotItem.consume then
  23.                 item = slotItem
  24.             else
  25.                 cachedSlot = nil
  26.             end
  27.         end
  28.         if not item then
  29.             for slot, meta in pairs(inv.list()) do
  30.                 local slotItem = inv.getItem(slot)
  31.                 if slotItem and slotItem.consume then
  32.                     print("Using food from slot " .. slot)
  33.                     item = slotItem
  34.                     cachedSlot = slot
  35.                     break
  36.                 end
  37.             end
  38.         end
  39.         if item then
  40.             item.consume()
  41.         else
  42.             print("Cannot find food")
  43.             break
  44.         end
  45.         data = modules.getMetaOwner()
  46.     end
  47.     sleep(5)
  48. end
Add Comment
Please, Sign In to add comment