Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- https://github.com/chuesler/computercraft-programs/blob/master/bloodmagic-altar/altar
- local fromAltarToTurtleDirection = "east"
- local fromChestToTurtleDirection = "west"
- local altar = peripheral.find("tealtar")
- local chest = peripheral.find("chest") or peripheral.find("iron")
- if not altar then
- error("Altar not found")
- end
- if not chest then
- error("Chest not found")
- end
- local bOrbString = "BloodOrb"
- ---------------------------------------------------------------------------------------------------------------
- local recipe = {
- -- default recipe
- { output = 'AWWayofTime:blankSlate', amount = 64, essence = 1000, input = 'minecraft:stone' },
- -- FTB Infinity Evolved (Expert)
- -- { output = 'AWWayofTime:blankSlate', amount = 64, essence = 1000, input = 'Thaumcraft:blockCosmeticSolid:6' },
- { output = 'AWWayofTime:reinforcedSlate', amount = 128, essence = 2000, input = 'AWWayofTime:blankSlate' },
- { output = 'AWWayofTime:imbuedSlate', amount = 128, essence = 5000, input = 'AWWayofTime:reinforcedSlate' },
- { output = 'AWWayofTime:demonicSlate', amount = 64, essence = 15000, input = 'AWWayofTime:imbuedSlate' },
- { output = 'AWWayofTime:bloodMagicBaseItems:27', amount = 64, essence = 30000, input = 'AWWayofTime:demonicSlate' },
- { output = bOrbString, amount = -1, essence = 0, input = bOrbString }
- }
- ---------------------------------------------------------------------------------------------------------------
- -- vvvv ##################### Altar related functions ###################### vvvv
- function getAltarBloodLevel()
- local tank = altar.getTankInfo()
- return tank[1]["contents"]["amount"]
- end
- function getItemInAltar()
- return altar.getStackInSlot(1) or nil
- end
- function altarHasOrb()
- local item = getItemInAltar()
- if item ~= nil and isOrb(item) then
- return true
- else
- return false
- end
- end
- -- ^^^^ ##################### Altar related functions ###################### ^^^^
- -- vvvv ##################### Chest related functions ###################### vvvv
- local chestContent = {}
- function updateChestContent()
- chestContent = {}
- for slot = 1, chest.getInventorySize() do
- local stack = chest.getStackInSlot(slot)
- local id = getItemId(stack)
- if stack then
- if chestContent[id] then
- chestContent[id].amount = chestContent[id].amount + stack.qty
- else
- chestContent[id] = { amount = stack.qty, slots={} }
- end
- table.insert(chestContent[id].slots, { slot=i, size=stack.qty })
- end
- end
- end
- function showChestContent()
- for itemId, db in pairs(chestContent) do
- print(itemId.. " | "..tostring(db.amount))
- end
- end
- function getAmountInChest(itemId)
- if chestContent[itemId] then
- return chestContent[itemId].amount
- else
- return 0
- end
- end
- function getItemSlotInChest(partOfItemID)
- for i=1, chest.getInventorySize() do
- local stack = chest.getStackInSlot(i)
- if stack and string.find(getItemId(stack), partOfItemID) then
- return i
- end
- end
- return 0
- end
- function chestHasOrb()
- return getItemSlotInChest(bOrbString) ~= 0
- end
- -- ^^^^ ##################### Chest related functions ###################### ^^^^
- -- vvvv ##################### Misc functions ############################### vvvv
- function debug(text)
- local debug = true
- if text ~= nil and debug then
- term.setTextColor(colors.blue)
- print(">>> "..text)
- term.setTextColor(colors.white)
- end
- end
- function pstatus(text)
- if text ~= nil then
- term.setTextColor(colors.yellow)
- print(" > "..text)
- term.setTextColor(colors.white)
- end
- end
- function getItemId(stack)
- if stack then
- if stack.dmg ~= nil and stack.dmg ~= 0 then
- return stack.id .. ":" .. stack.dmg
- else
- return stack.id
- end
- else
- return nil
- end
- end
- function isOrb(item)
- return string.find(getItemId(item), bOrbString)
- end
- function moveItemFromChestToAltar(slot, amount)
- chest.pushItem(fromChestToTurtleDirection, slot, amount or 1)
- altar.pullItem(fromAltarToTurtleDirection, 1)
- end
- function moveItemFromAltarToChest()
- altar.pushItem(fromAltarToTurtleDirection, 1)
- chest.pullItem(fromChestToTurtleDirection, 1)
- end
- -- ^^^^ ##################### Misc functions ###################### ^^^^
- function getNextRecipe()
- for _,r in pairs(recipe) do
- --debug(r.output.."|"..r.amount)
- debug(r.input .." in Chest:"..tostring(getAmountInChest(r.input)))
- if getAmountInChest(r.input) > 0 then
- if r.amount > getAmountInChest(r.output) then
- return r
- end
- end
- end
- return nil
- end
- local c = 0
- function dummy()
- c = c + 1
- if c == 1 then
- return "|"
- end
- if c == 2 then
- return "/"
- end
- if c == 3 then
- return "-"
- end
- if c == 4 then
- c = 0
- return "\\"
- end
- end
- local crafting = false
- local recipe = nil
- function showStatus()
- term.clear()
- term.setCursorPos(1,1)
- print("BloodAltar automation "..dummy())
- if recipe then
- pstatus("Blood Level: ("..tostring(getAltarBloodLevel()).."/"..tostring(recipe.essence)..")")
- pstatus("Input: "..recipe.input)
- pstatus(" -> ("..tostring(getAmountInChest(recipe.input)).." remaining)")
- pstatus("Output: "..recipe.output)
- pstatus(" -> ("..tostring(getAmountInChest(recipe.output)).."/"..tostring(recipe.amount)..")")
- else
- pstatus("no valid crafting recipe with ingredients found")
- end
- if crafting then
- pstatus("Crafting in progress")
- else
- pstatus("NOT crafting")
- end
- end
- function loop()
- updateChestContent()
- if not crafting then
- recipe = getNextRecipe()
- end
- showStatus()
- if recipe ~= nil then
- -- "valid" recipe - check altar
- if getItemInAltar() then -- ### Altar not empty
- if getItemId(getItemInAltar()) == recipe.output then
- -- ### Item in altar equals output in recipe -> take it out
- moveItemFromAltarToChest()
- crafting = false
- else
- if recipe.input ~= bOrbString and isOrb(getItemInAltar()) then
- -- ### recipe is not orb but orb in altar -> remove it
- moveItemFromAltarToChest()
- end
- end
- else -- ### Altar empty
- if getAltarBloodLevel() >= recipe.essence then
- moveItemFromChestToAltar( getItemSlotInChest(recipe.input) )
- crafting = true
- end
- end
- end
- end
- function run()
- os.queueEvent("timer")
- local stop = false
- while not stop do
- local ev, p1, p2, p3 = os.pullEvent()
- if ev == "timer" then
- os.startTimer(0.25)
- loop()
- end
- if ev == "char" and p1 == "t" then
- stop = true
- end
- end
- end
- run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement