Hiranus icon

Ballad of Alchemy Automation

Hiranus | PRO | 07/12/15 03:21:54 PM UTC | 0 ⭐ | 1114 👁️ | Never ⏰ | []
Lua |

11.81 KB

|

None

|

0 👍

/

0 👎

--------Ingredients Section
local alchemy = {}
function AlchemicalCrafting (item,name,ing)
    local tab = {}
    tab.item = item
    tab.name = name
    tab.ingredients = ing
    return tab
end
function Item (name,damage)
    local tab = {}
    tab.id = name
    tab.dmg = damage
    return tab
end
alchemy[1] = AlchemicalCrafting(Item("AWWayofTime:simpleCatalyst",0),"Simple Catalyst",
{ 
    alchemical = {
    Item("minecraft:gunpowder",0),
    }, 
    other = { 
        Item("minecraft:sugar",0),
        Item("minecraft:redstone",0),
        Item("minecraft:redstone",0),
        Item("minecraft:glowstone_dust",0),
        
    }
})
alchemy[2] = AlchemicalCrafting(Item("AWWayofTime:bloodMagicBaseAlchemyItems",3),"Strengthened Catalyst",
{ 
    alchemical = {
        Item("AWWayofTime:simpleCatalyst",0),
        Item("AWWayofTime:simpleCatalyst",0)
    }, 
    other = { 
        Item("minecraft:nether_wart",0),
        Item("minecraft:dye",15)
    }
})
alchemy[3] = AlchemicalCrafting(Item("AWWayofTime:bloodMagicBaseAlchemyItems",4),"Concentrated Catalyst",
{ 
    alchemical = {
        Item("AWWayofTime:bloodMagicBaseAlchemyItems",3),
        Item("AWWayofTime:bloodMagicBaseAlchemyItems",5)
    }, 
    other = { 
        Item("minecraft:gold_nugget")
    }
})
alchemy[4] = AlchemicalCrafting(Item("AWWayofTime:bloodMagicBaseAlchemyItems",5),"Fractured Bone",
{ 
    alchemical = {
    Item("minecraft:gunpowder",0),
    }, 
    other = { 
        Item("minecraft:bone",0),
        Item("minecraft:bone",0),
        Item("minecraft:bone",0),
        Item("minecraft:bone",0),
        
    }
})
alchemy[5] = AlchemicalCrafting(Item("AWWayofTime:incendium",0),"Incendium",
{ 
    alchemical = {
        Item("AWWayofTime:simpleCatalyst",0)
    }, 
    other = { 
        Item("minecraft:lava_bucket",0),
        Item("minecraft:blaze_powder",0),
        Item("minecraft:blaze_powder",0),
        Item("minecraft:netherrack",0)
    }
})
alchemy[6] = AlchemicalCrafting(Item("AWWayofTime:aether",0),"Aether",
{ 
    alchemical = {
        Item("AWWayofTime:simpleCatalyst",0)
    }, 
    other = { 
        Item("minecraft:ghast_tear",0),
        Item("minecraft:feather",0),
        Item("minecraft:feather",0),
        Item("minecraft:glowstone_dust",0)
    }
})
alchemy[7] = AlchemicalCrafting(Item("AWWayofTime:sanctus",0),"Sanctus",
{ 
    alchemical = {
        Item("AWWayofTime:simpleCatalyst",0)
    }, 
    other = { 
        Item("minecraft:gold_nugget",0),
        Item("minecraft:glass",0),
        Item("minecraft:glowstone_dust",0),
        Item("minecraft:glowstone_dust",0)
    }
})
alchemy[8] = AlchemicalCrafting(Item("AWWayofTime:crepitous",0),"Crepitous",
{ 
    alchemical = {
        Item("AWWayofTime:simpleCatalyst",0),
        Item("minecraft:gunpowder",0),
        Item("minecraft:gunpowder",0),
    }, 
    other = { 
        Item("minecraft:cobblestone",0),
        Item("minecraft:cobblestone",0)
    }
})
alchemy[9] = AlchemicalCrafting(Item("AWWayofTime:crystallos",0),"Crystallos",
{ 
    alchemical = {
        Item("AWWayofTime:simpleCatalyst",0)
    }, 
    other = { 
        Item("minecraft:ice",0),
        Item("minecraft:ice",0),
        Item("minecraft:snow",0),
        Item("minecraft:snow",0)
    }
})
alchemy[10] = AlchemicalCrafting(Item("AWWayofTime:terrae",0),"Terrae",
{ 
    alchemical = {
        Item("AWWayofTime:simpleCatalyst",0)
    }, 
    other = { 
        Item("minecraft:sand",0),
        Item("minecraft:dirt",0),
        Item("minecraft:obsidian",0),
        Item("minecraft:obsidian",0)
    }
})
alchemy[11] = AlchemicalCrafting(Item("AWWayofTime:aquasalus",0),"Aquasalus",
{ 
    alchemical = {
        Item("AWWayofTime:simpleCatalyst",0),
    }, 
    other = { 
        Item("minecraft:dye",0),
        Item("minecraft:potion",0),
        Item("minecraft:potion",0),
        Item("minecraft:potion",0),
    }
})
alchemy[12] = AlchemicalCrafting(Item("AWWayofTime:tennebrae",0),"Tenebrae",
{ 
    alchemical = {
        Item("AWWayofTime:simpleCatalyst",0),
        Item("minecraft:coal",0),
        Item("minecraft:coal",0),
    }, 
    other = { 
        Item("minecraft:dye",0),
        Item("minecraft:clay_ball",0),
    }
})
alchemy[13] = AlchemicalCrafting(Item("AWWayofTime:magicales",0),"Magicales",
{ 
    alchemical = {
        Item("AWWayofTime:simpleCatalyst",0),
        Item("minecraft:gunpowder",0),
    }, 
    other = { 
        Item("minecraft:glowstone_dust",0),
        Item("minecraft:glowstone_dust",0),
        Item("minecraft:redstone",0),
        
    }
})
alchemy[14] = AlchemicalCrafting(Item("AWWayofTime:bloodMagicBaseAlchemyItems",0),"Offensa",
{ 
    alchemical = {
        Item("AWWayofTime:bloodMagicBaseAlchemyItems",3),
        Item("AWWayofTime:incendium",0),
    }, 
    other = { 
        Item("minecraft:arrow",0),
        Item("minecraft:arrow",0),
        Item("minecraft:flint",0)
    }
})
alchemy[15] = AlchemicalCrafting(Item("AWWayofTime:bloodMagicBaseAlchemyItems",1),"Praesidium",
{ 
    alchemical = {
        Item("AWWayofTime:bloodMagicBaseAlchemyItems",3),
        Item("AWWayofTime:tennebrae",0),
        Item("minecraft:web",0),
    }, 
    other = { 
        Item("minecraft:iron_ingot",0),
        Item("minecraft:redstone",0)
    }
})
alchemy[16] = AlchemicalCrafting(Item("AWWayofTime:bloodMagicBaseAlchemyItems",2),"Orbis Terrae",
{ 
    alchemical = {
        Item("AWWayofTime:bloodMagicBaseAlchemyItems",3),
        Item("AWWayofTime:terrae",0),
        Item("minecraft:gunpowder",0),
    }, 
    other = { 
        
        Item("minecraft:sand",0),
        Item("minecraft:netherrack",0)
    }
})
alchemy[17] = AlchemicalCrafting(Item("AWWayofTime:bloodMagicBaseAlchemyItems",6),"Virtus",
{ 
    alchemical = {
        Item("minecraft:coal",0),
        Item("AWWayofTime:bloodMagicBaseAlchemyItems",3),
    }, 
    other = { 
        Item("minecraft:gunpowder",0),
        Item("minecraft:redstone",0),
        Item("minecraft:redstone",0)
    }
})
alchemy[18] = AlchemicalCrafting(Item("AWWayofTime:bloodMagicBaseAlchemyItems",7),"Reductus",
{ 
    alchemical = {
        Item("AWWayofTime:bloodMagicBaseAlchemyItems",3),
    }, 
    other = { 
        Item("minecraft:carrot",0),
        Item("minecraft:gold_ingot",0),
        Item("minecraft:soul_sand",0),
        Item("minecraft:redstone",0)
    }
})
alchemy[19] = AlchemicalCrafting(Item("AWWayofTime:bloodMagicBaseAlchemyItems",8),"Potentia",
{ 
 
    alchemical = {
        Item("AWWayofTime:bloodMagicBaseAlchemyItems",3),
    }, 
    other = { 
        Item("minecraft:glowstone_dust",0),
        Item("minecraft:quartz",0),
        Item("minecraft:dye",4),
        Item("minecraft:dye",4)
    }
})
alchemy[20] = AlchemicalCrafting(Item("minecraft:web",0),"Cobweb",
{ 
 
    alchemical = {
    }, 
    other = { 
        Item("minecraft:string",0),
        Item("minecraft:string",0),
        Item("minecraft:string",0),
        Item("minecraft:string",0),
        Item("minecraft:string",0)
    }
})
 
alchemy[21] = AlchemicalCrafting(Item("minecraft:gunpowder",0),"Gunpowder",
{ 
 
    alchemical = {
        Item("minecraft:coal",0),
    }, 
    other = { 
        Item("minecraft:gunpowder",0),
        Item("minecraft:sand",0),
 
    }
})
alchemy[22] = AlchemicalCrafting(Item("minecraft:coal",0),"Coal",
{ 
 
    alchemical = {
    }, 
    other = { 
        Item("minecraft:charcoal",0),
        Item("minecraft:charcoal",0),
        Item("minecraft:charcoal",0),
        Item("minecraft:charcoal",0),
        Item("minecraft:charcoal",0)
    }
})
 
----------End of ingredients section
 
-----"Limits" section
local quantities = {}
function PrepareConfig ()
    
    for i=1,#alchemy do
        quantities[i]={}
        quantities[i].name = alchemy[i].name
        quantities[i].lowPriNum = 50
        quantities[i].highPriNum = 25
    end
    cfg=fs.open("config.cfg","w")
    cfg.write(textutils.serialize(quantities))
    cfg.flush()
    cfg.close()
end
function LoadConfig()
    local cfg = fs.open("config.cfg", "r")
    quantities = textutils.unserialize( cfg.readAll() )  
    cfg.close()
end
-----End of "Limits" Section
 
----Peripheral section
local aeInterface
local chest
local altar
function Peripherals ()
    local per_found=0
    per_list = peripheral.getNames()
    for i = 1, #per_list do
        if peripheral.getType(per_list[i]) == "tileinterface" then
            aeInterface = peripheral.wrap(per_list[i])
            per_found=per_found+1
            print (" Found AE Interface")
        elseif  peripheral.getType(per_list[i]) == "tealtar" then
            altar = peripheral.wrap(per_list[i])
            per_found=per_found+1
            print (" Found Altar")
        else
            methods = peripheral.getMethods(per_list[i])
            for j = 1, #methods do
                    if methods[j] == "getStackInSlot" then
                            chest = peripheral.wrap(per_list[i])
                            per_found=per_found+1
                            print (" Found altar 'storage'")
                    end
            end
        end
    end
    if per_found ~= 3 then
    error("missing Peripherals") end
end
----End of Peripheral section
 
 
----List Section
local lowPriorityList = {}
local highPriorityList = {}
function PrepareListConnectionIDs()
    for i=1, #quantities do
        for j=1 ,#alchemy do
            if quantities[i].name == alchemy[j].name then
                quantities[i].alchemyID = j
                alchemy[j].quantitiesID = i
                break
            end
        end
    end
end
function RefreshLists ()
    lowPriorityList = {}
    highPriorityList = {}
    for i=1, #quantities do
    
 
        detail = aeInterface.getItemDetail(alchemy[quantities[i].alchemyID].item)
 
        if detail ~= nil then
            
            qty = detail.basic().qty
            if qty<quantities[i].highPriNum then
                highPriorityList[#highPriorityList +1] = i
            elseif qty<quantities[i].lowPriNum then
                lowPriorityList[#lowPriorityList +1] = i
            end
        else
            highPriorityList[#highPriorityList +1] = i
        end
    end
end
----End of List Section
 
 
--crafting section
local currentlyCrafted
 
function DetermineCrafting()
    if #highPriorityList ~= 0 then
        if #highPriorityList == 1 then
            FindAndFillAltar(highPriorityList[1])
        else 
            ingredient = alchemy[quantities[highPriorityList[1]].alchemyID].ingredients.alchemical
            if #ingredient == 0 then
                FindAndFillAltar(highPriorityList[1])
            else
            local ing
                for i=1, #ingredient do
            
                    ing = CheckParents(ingredient[i])
                    if ing ~= nil then
                        break
                    end
                end
                    
                if ing == nil then
                    FindAndFillAltar(highPriorityList[1])
                else
                    FindAndFillAltar(ing)
                end
                
            end
        end
    elseif #lowPriorityList ~= 0 then
        slot = FindInChest(quantities[lowPriorityList[1]].name)
        if currentlyCrafted ~= lowPriorityList[1] then
            if currentlyCrafted ~= nil then
                EmptyAltar()
            end
            FillAltar(slot,lowPriorityList[1])
        end
    else
        if currentlyCrafted ~= nil then
            EmptyAltar()
        end
    end
end
 
 
 
 
function CheckParents (item)
    local toCraft = nil
    
    currItem = FindAlchemyIngredient(item)
    
    
    if alchemy[currItem].quantitiesID ~=nil then
        for i=1, #highPriorityList do
            if alchemy[currItem].quantitiesID == highPriorityList[i] then
                toCraft = highPriorityList[i]
                break
            end
        end
    end
    local alchIng = alchemy[currItem].ingredients.alchemical
    if #alchIng ~= 0 then
        local deepSearch = nil
        for i=1,#alchIng do
            deepSearch = CheckParents(alchIng[i])
            if deepSearch ~= nil then
 
                toCraft = deepSearch
                break
            end
        end
    end
    return toCraft
end
---End of crafting section
 
---random section
 
function FindInChest(item_name)
    maxslots = chest.getInventorySize()
    for i=1, maxslots do
        ch = chest.getStackInSlot(i)
        if ch ~= nil then
            if item_name == ch.display_name then
                return i
            end
        end
    end
end
function EmptyAltar()
    altar.pushItem(2,1)
    currentlyCrafted = nil
end
function FillAltar(slot,item)
    if slot ~= nil then
    chest.pushItem(1,slot)
    currentlyCrafted = item
    else
        
        error("Missing item in chest: " .. quantities[item].name .. ". Terminating")
    end
end
function FindAlchemyIngredient (item)
    local alchIng
    
    for i=1, #alchemy do
        if item.id == alchemy[i].item.id and item.dmg == alchemy[i].item.dmg then
            alchIng=i
        end
    end
    return alchIng
end
function FindAndFillAltar (id)
    slot = FindInChest(quantities[id].name)
    if currentlyCrafted ~= id then
        if currentlyCrafted ~= nil then
            EmptyAltar()
        end
        FillAltar(slot,id)
    end
end
 
---end of random section
if fs.exists("config.cfg") then
    LoadConfig()
    Peripherals()
    altar.pushItem(2,1)
    PrepareListConnectionIDs()
    sleep(5)
    while true do
        RefreshLists()
        DetermineCrafting()
        sleep(8)
    end
    
else
    PrepareConfig()
    print (" File 'config.cfg' was generated. Edit it to suit your needs and launch app again")
end

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎