Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Recipes to build
- recipes = {
- storagecell = {
- redstone = {1,3,9,11},
- quartzcrystal = {2,5,7,10},
- mebasicprocessor = {6}
- },
- storagesegment = {
- redstone = {1,3,9,11},
- mebasicprocessor = {2},
- glass = {6},
- storagecell = {5,6,10}
- },
- storageblock = {
- glowstone = {1,3,9,11},
- storagesegment = {5,6,10},
- glass = {6},
- meadvancedprocessor = {2}
- },
- me16kstorage = {
- glass = {1,3},
- redstone = {2,5,7},
- storageblock = {6},
- iron = {9,10,11}
- }
- }
- appen1 = "appeng.materials." -- Need theese to get the correct name from applied energistics
- appen2 = ".name"
- chest = peripheral.wrap("left")
- function getSlot(slot)
- local info = chest.getStackInSlot(slot)
- if info then
- return info
- else
- return false
- end
- end
- function split(inputstr, sep) -- splits a string into a table
- if sep == nil then
- sep = "%s"
- end
- t={} ; i=1
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- t[i] = str
- i = i + 1
- end
- return t
- end
- function getName(slot) -- Returns the name, And if its applied energistics remove the long names
- local convert = {
- appen1.."quartzcrystal"..appen2,
- appen1.."mebasicprocessor"..appen2,
- appen1.."storagecell"..appen2,
- appen1.."storagesegment"..appen2,
- appen1.."storageblock"..appen2,
- appen1.."meadvancedprocessor"..appen2
- }
- local info = getSlot(slot)
- if info then
- info.name = string.lower(info.name)
- for k,v in pairs(convert) do -- Search through table and find appen names
- if info.name == v then
- info.name = split(info.name, ".")
- info.name = info.name[3]
- return info.name
- end
- end
- return info.name
- else
- return false
- end
- end
- function getQty(slot)
- local info = getSlot(slot)
- if info then
- return info.qty
- else
- return false
- end
- end
- function getChest() -- Returns the entire inventory of the chest as a table for faster access
- local size = chest.getInventorySize()
- local content = {}
- chest.condenseItems()
- for i = 1, size do
- local name = getName(i)
- local qty = getQty(i)
- if name then
- if content[name] then
- content[name] = content[name] + qty
- else
- content[name] = qty
- end
- else
- break
- end
- end
- return content
- end
- function getRecipe(name) -- Creates a table which displays needed item and quantity instead of need item and position as recipes does
- local recipe = {}
- for k,v in pairs(name) do
- if recipe[k] then
- recipe[k] = recipe[k] + #v
- else
- recipe[k] = #v
- end
- end
- return recipe
- end
- function compare(name, qty) -- Checks if name is in the chest, aswell as the correct quantity or more
- local content = getChest()
- local foundName = ""
- local foundQty = 0
- for k,v in pairs(content) do
- if k == name then
- if v >= qty then
- return true
- else
- foundQty = v or 0
- end
- else
- foundName = k
- end
- end
- return false, foundQty
- end
- function printT(t)
- for k,v in pairs(t) do
- print(k..": "..v)
- end
- end
- function gotRecipe(recipe, amount) -- Checks a recipe if everything is in the chest, Returns missing materials
- amount = amount or 1
- local missing = {}
- local content = getChest()
- local recipe = getRecipe(recipe)
- for itemName,itemQty in pairs(recipe) do
- found, qty = compare(itemName, itemQty * amount)
- if not found then
- if missing[itemName] then
- missing[itemName] = missing[itemName] + ((itemQty*amount)-qty)
- else
- missing[itemName] = itemQty*amount-qty
- end
- end
- end
- return missing
- end
- function isRecipe(name) -- Checks if name is a recipe in this code or not
- if recipes[name] then
- return true
- else
- return false
- end
- end
- function gotEnough(recipe, amount)
- amount = amount or 1
- local missing = gotRecipe(recipe, amount)
- if missing then
- for k,v in pairs(missing) do
- if isRecipe(k) then
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement