Advertisement
TechManDylan

FeedMe

Apr 22nd, 2021
788
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.10 KB | None | 0 0
  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. if not modules.hasModule("plethora:sensor") then
  6.     error("The entity sensor is missing", 0)
  7. end
  8. if not modules.hasModule("plethora:introspection") then
  9.     error("The introspection module is missing", 0)
  10. end
  11. local inv = modules.getInventory()
  12. local cachedSlot = false
  13. while true do
  14.     local data = modules.getMetaOwner()
  15.     while data.food.hungry do
  16.             local item
  17.         if cachedSlot then
  18.             local slotItem = inv.getItem(cachedSlot)
  19.             if slotItem and slotItem.consume then
  20.                 item = slotItem
  21.             else
  22.                 cachedSlot = nil
  23.             end
  24.         end
  25.         if not item then
  26.             for slot, meta in pairs(inv.list()) do
  27.                 local slotItem = inv.getItem(slot)
  28.                 if slotItem and slotItem.consume then
  29.                     print("Using food from slot " .. slot)
  30.                     item = slotItem
  31.                     cachedSlot = slot
  32.                     break
  33.                 end
  34.             end
  35.         end
  36.         if item then
  37.             item.consume()
  38.         else
  39.             print("Cannot find food")
  40.             break
  41.         end
  42.         data = modules.getMetaOwner()
  43.     end
  44.     sleep(5)
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement