Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local altarName = "left"
- local altarDir = "south"
- local returnDir = "north"
- local importChest = "top"
- local exportChest = "west"
- local myInven = "right"
- local waitForFullBlood = true
- local altr = peripheral.wrap(altarName)
- local aSlot
- local impCh = peripheral.wrap(importChest)
- local turt = peripheral.wrap(myInven)
- local bloodPool
- local enoughBlood = true
- local placedItem
- local waitingOnMoreItems = false
- function checkTurtle ()
- local tInv = turt.getAllStacks()
- local hasItem = false
- if tInv[16] ~= nil then
- hasItem = true
- end
- return hasItem
- end
- function turtleHolding ()
- local tInv = turt.getAllStacks()
- local holdingItem = false
- if tInv[1] ~= nil then
- holdingItem = true
- end
- return holdingItem
- end
- function checkAltar ()
- local aInv = altr.getAllStacks()
- local tInv = turt.getAllStacks()
- local match = false
- if aInv[1] ~= nil and tInv[16] ~= nil then
- if aInv[1]["id"] == tInv[16]["id"] then
- match = true
- end
- end
- return match
- end
- function findImport ()
- local iInv = impCh.getAllStacks()
- local slot = nil
- for k,v in pairs(iInv) do
- if v ~= nil then
- slot = k
- break
- end
- end
- return slot
- end
- function fillAltar ()
- local slot = findImport()
- local worked = false
- if slot ~= nil then
- if not turtleHolding() then
- impCh.pushItemIntoSlot("down",slot,1,1)
- end
- altr.pullItemIntoSlot(returnDir,1,1,1)
- worked = true
- end
- return worked
- end
- print("Blood Altar Management Function")
- print("Booting up. Checking For item.")
- while not checkTurtle() do
- print("No item found. Place item to generate in slot 16.")
- os.sleep(5)
- end
- print("Item found. Starting automation.")
- placedItem = fillAltar()
- while true do
- bloodPool = altr.getTankInfo("top")
- if not waitingOnMoreItems then
- if checkAltar() then
- altr.pushItemIntoSlot(exportChest,1,1)
- placedItem = fillAltar()
- print("Item ejected.")
- end
- if bloodPool[1]["amount"]==0 then
- print("Out of blood.")
- aSlot = altr.getAllStacks()
- if aSlot[1] ~= nil then
- altr.pushItemIntoSlot(returnDir,1,1)
- print("Item retrieved for safety.")
- end
- print("Add more blood to continue...")
- waitingOnMoreItems = true
- enoughBlood = false
- end
- if not placedItem then
- print("Unable to insert into altar.")
- print("Fix import/export chests to continue...")
- waitingOnMoreItems = true
- end
- if not checkTurtle() then
- print("No item found in turtle.")
- aSlot = altr.getAllStacks()
- if aSlot[1] ~= nil then
- altr.pushItemIntoSlot(exportChest,1,1)
- print("Altar ejected for safety.")
- end
- print("Place item in slot 16 to continue...")
- waitingOnMoreItems = true
- end
- else
- if bloodPool[1]["amount"] > 0 and not waitForFullBlood then
- enoughBlood = true
- elseif bloodPool[1]["amount"] == bloodPool[1]["capacity"] then
- enoughBlood = true
- end
- if enoughBlood and checkTurtle() then
- placedItem = fillAltar()
- if placedItem then
- print("Problem(s) fixed. Automation resumed.")
- waitingOnMoreItems = false
- end
- end
- end
- os.sleep(.25)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement