Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ccm = require "cc.completion"
- local completion = require("cc.shell.completion")
- function startup()
- local function l_completion(shell, index, partial, previousArgs)
- if index == 1 then
- return ccm.choice(partial, {"tstOut", "combine", "saw", "press", "deployer", "spout"})
- end
- return nil
- end
- shell.setCompletionFunction("work.lua", l_completion)
- end
- startup()
- -- create ?????????
- local saw = peripheral.find("create:saw")
- local deployer = peripheral.find("create:deployer")
- local spout = peripheral.find("create:spout")
- local tanks = {peripheral.find("fluidTank")}
- local depots = {peripheral.find("create:depot")}
- local box_input = peripheral.find("minecraft:chest")
- -- ??????????????????
- -- ???edit???????????????arg
- -- arg = {"tstOut",1}
- local depot_deployer = depots[4]
- local depot_saw = depots[3]
- local depot_press = depots[1]
- local depot_spout = depots[2]
- --[[ ??????,?????????handler,??????handler????,
- ??????,??????????,?????????? ]]
- local lastNbt = ""
- local itemMap = {}
- local ingredient = ""
- local recipe_ls = {}
- local recipe_map = {
- ["create:mechanical_press"] = function (input_inv, input_slot)
- return process_combine_press(input_inv, input_slot, depot_press)
- end,
- ["create:mechanical_saw"] = function (input_inv, input_slot)
- return process_combine_saw(input_inv, input_slot, depot_saw)
- end,
- }
- local fluidBucketMap = {
- ["minecraft:water_bucket"] = "minecraft:water",
- ["minecraft:lava_bucket"] = "minecraft:lava",
- ["immersiveengineering:redstone_acid_bucket"] = "immersiveengineering:redstone_acid"
- }
- -- --------------------------------------------------------------------
- -- tools
- function pgn(peri)
- return peripheral.getName(peri)
- end
- function findItemSlot(itemType, inv)
- for index,item in pairs(inv.list()) do
- if item.name == itemType then
- return index
- end
- end
- return false
- end
- function findFluidInv(fluidType)
- print("fluitypes:",fluidType)
- for periindex,tankperi in pairs(tanks) do
- for tankindex,tank in pairs(tankperi.tanks()) do
- if tank.name == fluidType then
- if tank.amount > 1000 then
- return periindex
- end
- end
- end
- end
- return false
- end
- function invClean(inv)
- if inv then
- for index,item in pairs(inv.list()) do
- inv.pushItems(pgn(box_input),index)
- end
- end
- end
- -- --------------------------------------------------------------------
- -- init
- function cleanllSlot()
- invClean(saw)
- invClean(deployer)
- if depots then
- for index,depot in pairs(depots) do
- invClean(depot)
- end
- end
- end
- function initRecipe(startIndex)
- recipe_ls = {}
- turtle.select(1)
- ret = turtle.getItemDetail()
- if ret~= nil then
- ingredient = ret.name
- else
- return false
- end
- for i = startIndex, 16, 1 do
- turtle.select(i)
- ret = turtle.getItemDetail()
- if ret~= nil then
- table.insert(recipe_ls, ret.name)
- else
- return true
- end
- end
- end
- -- --------------------------------------------------------------------
- -- combine process
- function process_combine_saw(input_inv, input_slot, out_inv)
- input_inv.pushItems(pgn(saw),input_slot,1)
- while true do
- if #(out_inv.list()) ~= 0 then
- return out_inv
- end
- end
- end
- function process_combine_press(input_inv, input_slot, out_inv)
- lastNbt = input_inv.getItemDetail(input_slot).nbt
- input_inv.pushItems(pgn(out_inv),input_slot,1)
- while true do
- if out_inv.getItemDetail(1).nbt ~= lastNbt then
- return out_inv
- end
- end
- end
- function process_combine_deployer(itemType, input_inv, input_slot, out_inv)
- lastNbt = input_inv.getItemDetail(input_slot).nbt
- input_inv.pushItems(pgn(out_inv),input_slot,1)
- while true do
- itemSlot = findItemSlot(itemType, box_input)
- if itemSlot ~= false then
- box_input.pushItems(pgn(deployer),itemSlot,1)
- break
- end
- sleep(5)
- end
- while true do
- if out_inv.getItemDetail(1).nbt ~= lastNbt then
- invClean(deployer)
- return out_inv
- end
- end
- end
- function process_combine_spout(fluidType,input_inv, input_slot, out_inv)
- lastNbt = input_inv.getItemDetail(input_slot).nbt
- input_inv.pushItems(pgn(out_inv),input_slot,1)
- while true do
- tankIndex = findFluidInv(fluidType)
- if tankIndex ~= false then
- tanks[tankIndex].pushFluid(pgn(spout),1000)
- break
- end
- sleep(5)
- end
- while true do
- if out_inv.getItemDetail(1).nbt ~= lastNbt then
- spout.pushFluid(pgn(tanks[tankIndex]),1000)
- return out_inv
- end
- end
- end
- -- --------------------------------------------------------------------
- -- singleProcess
- -- ???????? ?????,????????????
- function process_single_saw(input_inv, input_slot, out_inv)
- input_inv.pushItems(pgn(saw),input_slot)
- while true do
- if #(saw.list()) == 0 then
- invClean(out_inv)
- return true
- end
- end
- end
- function process_single_press(input_inv, input_slot, out_inv)
- origName = input_inv.getItemDetail(input_slot).name
- input_inv.pushItems(pgn(out_inv),input_slot)
- repeat
- local retFlag = true
- for i,item in pairs(out_inv.list()) do
- if item.name == origName then
- retFlag = false
- end
- end
- until retFlag
- invClean(out_inv)
- end
- function process_single_spout(fluidType, input_inv, input_slot, out_inv)
- origName = input_inv.getItemDetail(input_slot).name
- input_inv.pushItems(pgn(out_inv),input_slot)
- while true do
- tankIndex = findFluidInv(fluidType)
- if tankIndex ~= false then
- tanks[tankIndex].pushFluid(pgn(spout),1000)
- break
- end
- sleep(5)
- local retFlag = true
- for i,item in pairs(out_inv.list()) do
- if item.name == origName then
- retFlag = false
- end
- end
- if retFlag then
- break
- end
- end
- invClean(out_inv)
- end
- function process_single_deployer(itemType, input_inv, input_slot, out_inv)
- origName = input_inv.getItemDetail(input_slot).name
- -- ????????
- input_inv.pushItems(pgn(out_inv),input_slot)
- repeat
- local retFlag = true
- -- ??????????
- if #(deployer.list()) == 0 then
- while true do
- itemSlot = findItemSlot(itemType, box_input)
- if itemSlot ~= false then
- box_input.pushItems(pgn(deployer),itemSlot)
- break
- end
- sleep(5)
- end
- end
- for i,item in pairs(out_inv.list()) do
- if item.name == origName then
- retFlag = false
- end
- end
- until retFlag
- print("process end ")
- invClean(out_inv)
- invClean(deployer)
- end
- -- --------------------------------------------------------------------
- function singleTask()
- cleanllSlot()
- turtle.select(1)
- ret = turtle.getItemDetail()
- if not initRecipe(1) then
- print(" no appoint recipe")
- return false
- end
- cb = nil
- if arg[1] == "saw" then
- cb = function (input_slot)
- process_single_saw(box_input,input_slot,depot_saw)
- end
- elseif arg[1] == "press" then
- cb = function (input_slot)
- process_single_press(box_input,input_slot,depot_press)
- end
- elseif arg[1] == "deployer" then
- cb = function (input_slot)
- process_single_deployer(ingredient, box_input, input_slot, depot_deployer)
- end
- initRecipe(2)
- elseif arg[1] == "spout" then
- cb = function (input_slot)
- fluidType = fluidBucketMap[ingredient]
- process_single_spout(fluidType, box_input, input_slot, box_input)
- end
- initRecipe(2)
- else
- print(" no appoint process")
- return false
- end
- input_inv = box_input
- repeat
- local retFlag = true
- for index, value in pairs(recipe_ls) do
- inputSlot = findItemSlot(value, box_input)
- if inputSlot == false then
- -- print("no find any ",value)
- else
- retFlag = false
- cb(inputSlot)
- end
- end
- until retFlag
- print("process done!")
- end
- function serialCombine()
- cleanllSlot()
- if not initRecipe(2) then
- print(" no appoint recipe")
- return false
- end
- while true do
- input_inv = box_input
- inputSlot = findItemSlot(ingredient, box_input)
- if inputSlot == false then
- print("no find any ",ingredient)
- return false
- end
- while true do
- for index, value in pairs(recipe_ls) do
- if recipe_map[value] ~= nil then
- input_inv = recipe_map[value](input_inv, inputSlot)
- inputSlot = 1
- elseif fluidBucketMap[value] ~= nil then
- input_inv = process_combine_spout(fluidBucketMap[value], input_inv, inputSlot, depot_spout)
- inputSlot = 1
- else
- input_inv = process_combine_deployer(value, input_inv, inputSlot, depot_deployer)
- inputSlot = 1
- end
- end
- if input_inv.getItemDetail(inputSlot).nbt == nil then
- input_inv.pushItems(pgn(box_input),inputSlot)
- break
- end
- end
- end
- end
- function mainloop()
- if arg[1] == "tstOut" then
- -- ???????? ???,?????????
- box_input.pushItems(pgn(depots[tonumber(arg[2])]),1)
- elseif arg[1] == "combine" then
- -- ????
- serialCombine()
- else
- singleTask()
- end
- end
- mainloop()
Advertisement
Add Comment
Please, Sign In to add comment