Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- device_inscriber = peripheral.find("ae2:inscriber")
- device_container = peripheral.find("inventory",function (name, device)
- newStr = peripheral.getType(name)
- return newStr ~= "ae2:inscriber"
- end)
- local slotMap = {
- ["ae2:logic_processor_press"] = 1,
- ["ae2:calculation_processor_press"] = 1,
- ["ae2:engineering_processor_press"] = 1,
- ["ae2:silicon_press"] = 1,
- ["ae2:printed_logic_processor"] = 1,
- ["ae2:printed_calculation_processor"] = 1,
- ["ae2:printed_engineering_processor"] = 1,
- ["ae2:printed_silicon"] = 2,
- ["minecraft:redstone"] = 3,
- ["minecraft:gold_ingot"] = 3,
- ["ae2:certus_quartz_crystal"] = 3,
- ["minecraft:diamond"] = 3,
- ["ae2:silicon"] = 3,
- }
- local recipes = {
- ["ae2:printed_logic_processor"] = {
- ["ae2:logic_processor_press"] = {
- slot = {}
- },
- ["minecraft:gold_ingot"] = {
- slot = {}
- }
- },
- ["ae2:printed_calculation_processor"] = {
- ["ae2:calculation_processor_press"] = {
- slot = {}
- },
- ["ae2:certus_quartz_crystal"] = {
- slot = {}
- }
- },
- ["ae2:printed_engineering_processor"] = {
- ["ae2:engineering_processor_press"] = {
- slot = {}
- },
- ["minecraft:diamond"] = {
- slot = {}
- }
- },
- ["ae2:printed_silicon"] = {
- ["ae2:silicon_press"] = {
- slot = {}
- },
- ["ae2:silicon"] = {
- slot = {}
- }
- },
- ["ae2:logic_processor"] = {
- ["ae2:printed_logic_processor"] = {
- slot = {}
- },
- ["minecraft:redstone"] = {
- slot = {}
- },
- ["ae2:printed_silicon"] = {
- slot = {}
- }
- },
- ["ae2:calculation_processor"] = {
- ["ae2:printed_calculation_processor"] = {
- slot = {}
- },
- ["minecraft:redstone"] = {
- slot = {}
- },
- ["ae2:printed_silicon"] = {
- slot = {}
- }
- },
- ["ae2:engineering_processor"] = {
- ["ae2:printed_engineering_processor"] = {
- slot = {}
- },
- ["minecraft:redstone"] = {
- slot = {}
- },
- ["ae2:printed_silicon"] = {
- slot = {}
- }
- }
- }
- function itemMatch(index,itemStack)
- for recipeName, recipe in pairs(recipes) do
- for itemName, slot in pairs(recipe) do
- if itemStack.name == itemName then
- table.insert(slot, index)
- end
- end
- end
- end
- function clearInscriberOutput()
- -- 4 是输出槽
- device_inscriber.pushItems(peripheral.getName(device_container),4)
- end
- function clearInscriber()
- -- 4 是输出槽
- for i = 1, 4, 1 do
- device_inscriber.pushItems(peripheral.getName(device_container),i)
- end
- end
- function clearRecipe(recipeName)
- for itemName, slot in pairs(recipes[recipeName]) do
- slot = {}
- end
- end
- function clearAll()
- for recipeName, recipe in pairs(recipes) do
- clearRecipe(recipeName)
- end
- end
- function pushToInscriber(index,targetIndex)
- device_container.pushItems(peripheral.getName(device_inscriber),index,64,targetIndex)
- end
- function checkInscriberIndexIsEmpty(index)
- if device_inscriber.list()[index] == nil then
- return true
- else
- return false
- end
- end
- function craft(recipeName)
- -- 有很多个slot ,必须其中一个为空才返回
- -- itemName 有很多个,每次循环都是其中的一个,
- target_recipe = recipes[recipeName]
- print("craft: ",recipeName)
- for itemName, slot in pairs(target_recipe) do
- -- 要先转送
- index = table.remove(slot,1)
- pushToInscriber(index,slotMap[itemName])
- end
- retFlag = false
- repeat
- retFlag = false
- -- 槽转送以后且槽为空时才清空slot
- for itemName, slot in pairs(target_recipe) do
- -- 要先转送
- if #slot == 0 then
- if checkInscriberIndexIsEmpty(slotMap[itemName]) then -- 容器和目标槽位都为空
- print("slot ",slotMap[itemName])
- print("itemName ",itemName)
- print("clear",recipeName)
- clearRecipe(recipeName)
- clearInscriber()
- return
- else -- 容器为空,目标不为空
- end
- else
- if checkInscriberIndexIsEmpty(slotMap[itemName]) then -- 容器不为空,目标为空
- print("ise: ",itemName.." "..slotMap[itemName])
- index = table.remove(slot,1)
- pushToInscriber(index,slotMap[itemName])
- clearInscriberOutput()
- else -- 容器不为空,目标不为空
- end
- end
- end
- sleep(5)
- -- print("loop again")
- until retFlag
- end
- function recipeExist()
- for recipeName, recipe in pairs(recipes) do
- craftFlag = true
- for itemName, slot in pairs(recipe) do
- if #slot == 0 then
- craftFlag = false
- break
- end
- end
- if craftFlag then -- 满足配方,合成
- craft(recipeName)
- end
- clearRecipe(recipeName)
- end
- end
- -- 大循环遍历
- function mainloop()
- retFlag = true
- repeat
- -- 初始化阶段
- retFlag = true
- containerList = device_container.list() -- 遍历容器所有物品
- for index, itemStack in pairs(containerList) do
- if itemStack ~=nil then
- itemMatch(index,itemStack)
- end
- end
- if recipeExist() then -- 判断是否有配方存在并且合成配方
- retFlag = false
- end
- print("exist ",retFlag)
- clearAll()
- until retFlag
- end
- clearInscriber()
- mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement