emagiannu

[AutomaticEssentiaRefilling] beans

Mar 14th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | None | 0 0
  1. rednet.open("right")
  2. recvID = 69
  3. scanned = false
  4.  
  5. local af = peripheral.wrap("left") --Alchemical Furnace
  6. local afdirection = "west" -- Alchemical Furnace direction
  7. local delay = 0.8 --Refresh delay to check if beans are cooking
  8. local anDir = "down" --AspectAnalyzer position
  9. local aa = peripheral.wrap("bottom") --AspectAnalyzer
  10.  
  11. c = peripheral.wrap("top") --Golden Chest for beans
  12. chestDir = "top" -- direction of the Golden CHest for beans
  13. local beans = {}
  14.  
  15. function refillJar(asp, amo)
  16.   print("Adding " .. amo .. " to " .. asp .. ".")
  17.   if asp~=nil and amo > 0 then
  18.     print("Refilling " .. asp)
  19.     c.pushItem(anDir , beans[asp], amo)
  20.     turtle.turnLeft()    
  21.     turtle.drop()
  22.     turtle.turnRight()
  23.     waitForBeans()
  24.     print("Done Cooking " .. asp)
  25.     rednet.send(recvID ,"refilled")
  26.   end
  27. end
  28.  
  29. function scanBeans()
  30.   for i = 1, 51 do
  31.     c.pushItem(anDir , i, 1)
  32.     turtle.dropDown()
  33.     if aa.hasItem() and aa.itemHasAspects() then
  34.       beans[aa.getAspects()] = i
  35.       print(aa.getAspects() .. ": " .. beans[aa.getAspects()])
  36.       turtle.dropDown()
  37.     end
  38.       if aa.hasItem() then
  39.         turtle.suckDown()
  40.         turtle.drop()
  41.       end
  42.   end
  43. end
  44.  
  45. function waitForBeans()
  46.   sleep(2)
  47.   local count = 0
  48.   while count < 3 do
  49.     if af.getStackInSlot(1) == nil then
  50.       count = count + 1      
  51.     else
  52.       count = 0
  53.     end
  54.     print("Waiting for beans to cook (" .. 3-count .. ")")
  55.     sleep(delay)
  56.   end
  57. end
  58.  while true do
  59.    id,msg = rednet.receive()
  60.    print(msg)
  61.    if msg == "scan" then
  62.      if not scanned then
  63.        scanBeans()
  64.        scanned = true
  65.      end
  66.      rednet.send(recvID ,"scanned")
  67.    
  68.    elseif msg ~= null then
  69.      local t = textutils.unserialize(msg)
  70.      refillJar(t[1], t[2])
  71.    end
  72.  end
  73.  
  74. rednet.close("right")
Advertisement
Add Comment
Please, Sign In to add comment