Advertisement
FakoTheGreat

BAMF

Apr 8th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.31 KB | None | 0 0
  1. local altarName = "left"
  2. local altarDir = "south"
  3. local returnDir = "north"
  4. local importChest = "top"
  5. local exportChest = "west"
  6. local myInven = "right"
  7. local waitForFullBlood = true
  8.  
  9. local altr = peripheral.wrap(altarName)
  10. local aSlot
  11. local impCh = peripheral.wrap(importChest)
  12. local turt = peripheral.wrap(myInven)
  13. local bloodPool
  14. local enoughBlood = true
  15. local placedItem
  16. local waitingOnMoreItems = false
  17.  
  18. function checkTurtle ()
  19.   local tInv = turt.getAllStacks()
  20.   local hasItem = false
  21.  
  22.   if tInv[16] ~= nil then
  23.     hasItem = true
  24.   end
  25.  
  26.   return hasItem
  27. end
  28.  
  29. function turtleHolding ()
  30.   local tInv = turt.getAllStacks()
  31.   local holdingItem = false
  32.  
  33.   if tInv[1] ~= nil then
  34.     holdingItem = true
  35.   end
  36.  
  37.   return holdingItem
  38. end
  39.  
  40. function checkAltar ()
  41.   local aInv = altr.getAllStacks()
  42.   local tInv = turt.getAllStacks()
  43.   local match = false
  44.  
  45.   if aInv[1] ~= nil and tInv[16] ~= nil then
  46.     if aInv[1]["id"] == tInv[16]["id"] then
  47.       match = true
  48.     end
  49.   end
  50.  
  51.   return match
  52. end
  53.  
  54. function findImport ()
  55.   local iInv = impCh.getAllStacks()
  56.  
  57.   local slot = nil
  58.  
  59.   for k,v in pairs(iInv) do
  60.     if v ~= nil then
  61.       slot = k
  62.       break
  63.     end
  64.   end
  65.  
  66.   return slot
  67. end
  68.  
  69. function fillAltar ()
  70.   local slot = findImport()
  71.   local worked = false
  72.   if slot ~= nil then
  73.     if not turtleHolding() then
  74.       impCh.pushItemIntoSlot("down",slot,1,1)
  75.     end
  76.     altr.pullItemIntoSlot(returnDir,1,1,1)
  77.     worked = true
  78.   end
  79.  
  80.   return worked
  81. end
  82.  
  83. print("Blood Altar Management Function")
  84. print("Booting up. Checking For item.")
  85.  
  86. while not checkTurtle() do
  87.   print("No item found. Place item to generate in slot 16.")
  88.   os.sleep(5)
  89. end
  90.  
  91. print("Item found. Starting automation.")
  92.  
  93. placedItem = fillAltar()
  94.  
  95. while true do
  96.   bloodPool = altr.getTankInfo("top")
  97.   if not waitingOnMoreItems then
  98.     if checkAltar() then
  99.       altr.pushItemIntoSlot(exportChest,1,1)
  100.       placedItem = fillAltar()
  101.       print("Item ejected.")
  102.     end
  103.    
  104.     if bloodPool[1]["amount"]==0 then
  105.       print("Out of blood.")
  106.       aSlot = altr.getAllStacks()
  107.       if aSlot[1] ~= nil then
  108.         altr.pushItemIntoSlot(returnDir,1,1)
  109.         print("Item retrieved for safety.")
  110.       end
  111.       print("Add more blood to continue...")
  112.       waitingOnMoreItems = true
  113.       enoughBlood = false
  114.     end
  115.  
  116.     if not placedItem then
  117.       print("Unable to insert into altar.")
  118.       print("Fix import/export chests to continue...")
  119.       waitingOnMoreItems = true
  120.     end
  121.  
  122.     if not checkTurtle() then
  123.       print("No item found in turtle.")
  124.       aSlot = altr.getAllStacks()
  125.       if aSlot[1] ~= nil then
  126.         altr.pushItemIntoSlot(exportChest,1,1)
  127.         print("Altar ejected for safety.")
  128.       end
  129.       print("Place item in slot 16 to continue...")
  130.       waitingOnMoreItems = true
  131.     end
  132.   else
  133.     if bloodPool[1]["amount"] > 0 and not waitForFullBlood then
  134.       enoughBlood = true
  135.     elseif bloodPool[1]["amount"] == bloodPool[1]["capacity"] then
  136.       enoughBlood = true
  137.     end
  138.    
  139.     if enoughBlood and checkTurtle() then
  140.       placedItem = fillAltar()
  141.       if placedItem then
  142.         print("Problem(s) fixed. Automation resumed.")
  143.         waitingOnMoreItems = false
  144.       end
  145.     end
  146.   end
  147.  
  148.   os.sleep(.25)
  149. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement