Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RECIPES = require("RECIPES")
- local sides = require("sides")
- local component = require("component")
- local event = require("event")
- local tank = component.ender_tank
- local currentCraft = ""
- -- This will be filled automatically by the code, no need to modify it
- local transposerList = {
- items = {
- id = "",
- side = ""
- },
- fluids = {
- id = "",
- side = "",
- output= ""
- }
- }
- function tablelength(T)
- local count = 0
- for _ in pairs(T) do count = count + 1 end
- return count
- end
- function getCurrentRecipeIndex(items) -- items from inventory
- local isRecipeFound = false
- for i=1, tablelength(RECIPES) do
- for j=1, tablelength(items) do
- local damage = "0"
- if items[j]["damage"] ~= nil then
- damage = items[j]["damage"]
- end
- local curRecipe = RECIPES[i]["item"][1]
- if RECIPES[i]["item"][2] ~= "*" then
- curRecipe = curRecipe .. "." .. RECIPES[i]["item"][2]
- end
- if string.match(items[j]["name"] .. "." .. math.floor(damage), curRecipe) then
- return RECIPES[i]["name"]
- end
- end
- end
- return nil
- end
- function getInventoryItems()
- local items = component.proxy(transposerList["items"]["id"]).getAllStacks(sides[transposerList["items"]["side"]]).getAll()
- local realItems ={}
- local increment = 1
- for k,v in pairs(items) do
- if v["name"] ~= "minecraft:air" then
- realItems[increment] = v
- increment = increment + 1
- end
- end
- return realItems
- end
- function getTransposersInfo()
- local transposers = component.list("transposer");
- for id, data in pairs(transposers) do
- getTransposerSides(id)
- end
- end
- function getTransposerSides(transposerId)
- local possibleSides = {"bottom", "top", "back", "front", "right", "left"}
- local transposer = component.proxy(transposerId)
- local sides = {}
- for i=1, 6 do
- if transposer.getInventoryName(i-1) ~= nil and transposer.getFluidInTank(i-1)["n"] < 1 then
- transposerList["items"]["id"] = transposerId
- transposerList["items"]["side"] = possibleSides[i]
- elseif transposer.getFluidInTank(i-1)["n"] > 0 or transposer.getTankCapacity(i-1) == 16000 then
- local fluid = transposer.getFluidInTank(i-1)[1]
- if transposer.getInventoryName(i-1) == nil then
- transposerList["fluids"]["id"] = transposerId
- transposerList["fluids"]["side"] = possibleSides[i]
- end
- elseif transposer.getFluidInTank(i-1)["n"] > 0 OR transposer.getTankCapacity(i-1) ~= 16000 then
- transposerList["fluids"]["output"] = transposerId
- end
- end
- end
- function getOutputLocation(transposer)
- if transposer.getInventoryName(sides.up) == "actuallyadditions:block_phantom_liquiface" then
- return sides.up
- elseif transposer.getInventoryName(sides.down) == "actuallyadditions:block_phantom_liquiface" then
- return sides.down
- end
- return nil
- end
- function moveFluidToMachine(recipeIndex)
- local fluid = RECIPES[recipeName]["fluid"]
- local transposer = component.proxy(transposerList["fluids"]["id"])
- local inputSide = transposerList["fluids"]["side"]
- local outputSide = transposerList["fluids"]["output"]
- if transposer.getTankLevel(outputSide) == 0 then
- transposer.transferFluid(sides[inputSide], outputSide, fluidAmount)
- end
- end
- function init()
- getTransposersInfo()
- end
- function loopDeLoop()
- while event.pull(1, "interrupted") == nil do
- if getInventoryItems()[1] ~= nil then
- local currentRecipeIndex = getCurrentRecipeIndex(getInventoryItems())
- if currentRecipeIndex == nil then
- print("that's not a recipe you dum dum, check your items")
- else
- print(currentRecipeIndex)
- print("crafting : " .. RECIPES[currentRecipeIndex]["name"])
- moveFluidToMachine(currentRecipeIndex)
- end
- end
- local event, address, arg1, arg2, arg3 = event.pull(1)
- if type(address) == "string" and component.isPrimary(address) then
- if event == "key_down" and arg2 == keyboard.keys.q then
- os.exit()
- end
- end
- end
- end
- init()
- loopDeLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement