SHOW:
|
|
- or go back to the newest paste.
1 | RECIPES = require("RECIPES") | |
2 | local sides = require("sides") | |
3 | local component = require("component") | |
4 | local event = require("event") | |
5 | local tank = component.ender_tank | |
6 | ||
7 | local currentCraft = "" | |
8 | ||
9 | -- This will be filled automatically by the code, no need to modify it | |
10 | local transposerList = { | |
11 | items = { | |
12 | id = "", | |
13 | side = "" | |
14 | }, | |
15 | fluids = { | |
16 | id = "", | |
17 | side = "", | |
18 | - | output= "" |
18 | + | output = "" |
19 | } | |
20 | } | |
21 | ||
22 | function tablelength(T) | |
23 | local count = 0 | |
24 | for _ in pairs(T) do count = count + 1 end | |
25 | return count | |
26 | end | |
27 | ||
28 | function getCurrentRecipeIndex(items) -- items from inventory | |
29 | local isRecipeFound = false | |
30 | ||
31 | for i=1, tablelength(RECIPES) do | |
32 | for j=1, tablelength(items) do | |
33 | local damage = "0" | |
34 | if items[j]["damage"] ~= nil then | |
35 | damage = items[j]["damage"] | |
36 | end | |
37 | local curRecipe = RECIPES[i]["item"][1] | |
38 | if RECIPES[i]["item"][2] ~= "*" then | |
39 | curRecipe = curRecipe .. "." .. RECIPES[i]["item"][2] | |
40 | end | |
41 | ||
42 | if string.match(items[j]["name"] .. "." .. math.floor(damage), curRecipe) then | |
43 | - | return RECIPES[i]["name"] |
43 | + | return i |
44 | end | |
45 | end | |
46 | end | |
47 | ||
48 | return nil | |
49 | end | |
50 | ||
51 | function getInventoryItems() | |
52 | local items = component.proxy(transposerList["items"]["id"]).getAllStacks(sides[transposerList["items"]["side"]]).getAll() | |
53 | local realItems ={} | |
54 | local increment = 1 | |
55 | ||
56 | for k,v in pairs(items) do | |
57 | if v["name"] ~= "minecraft:air" then | |
58 | realItems[increment] = v | |
59 | increment = increment + 1 | |
60 | end | |
61 | end | |
62 | ||
63 | return realItems | |
64 | end | |
65 | ||
66 | function getTransposersInfo() | |
67 | local transposers = component.list("transposer"); | |
68 | for id, data in pairs(transposers) do | |
69 | getTransposerSides(id) | |
70 | end | |
71 | end | |
72 | ||
73 | function getTransposerSides(transposerId) | |
74 | local possibleSides = {"bottom", "top", "back", "front", "right", "left"} | |
75 | local transposer = component.proxy(transposerId) | |
76 | local sides = {} | |
77 | ||
78 | for i=1, 6 do | |
79 | if transposer.getInventoryName(i-1) ~= nil and transposer.getFluidInTank(i-1)["n"] < 1 then | |
80 | transposerList["items"]["id"] = transposerId | |
81 | - | transposerList["items"]["side"] = possibleSides[i] |
81 | + | transposerList["items"]["side"] = possibleSides[i] |
82 | - | elseif transposer.getFluidInTank(i-1)["n"] > 0 or transposer.getTankCapacity(i-1) == 16000 then |
82 | + | print("Found inventory", transposerId, possibleSides[i]) |
83 | - | local fluid = transposer.getFluidInTank(i-1)[1] |
83 | + | elseif transposer.getFluidInTank(i-1)["n"] > 0 and transposer.getTankCapacity(i-1) == 16000 then |
84 | - | |
84 | + | |
85 | transposerList["fluids"]["id"] = transposerId | |
86 | transposerList["fluids"]["side"] = possibleSides[i] | |
87 | - | transposerList["fluids"]["side"] = possibleSides[i] |
87 | + | print("Found ender tank", transposerId, possibleSides[i]) |
88 | end | |
89 | - | elseif transposer.getFluidInTank(i-1)["n"] > 0 OR transposer.getTankCapacity(i-1) ~= 16000 then |
89 | + | elseif transposer.getFluidInTank(i-1)["n"] > 0 and transposer.getTankCapacity(i-1) ~= 16000 then |
90 | - | transposerList["fluids"]["output"] = transposerId |
90 | + | transposerList["fluids"]["output"] = possibleSides[i] |
91 | print("Found liquid output", transposerId, possibleSides[i]) | |
92 | end | |
93 | end | |
94 | end | |
95 | - | function getOutputLocation(transposer) |
95 | + | |
96 | - | if transposer.getInventoryName(sides.up) == "actuallyadditions:block_phantom_liquiface" then |
96 | + | local function setTank(fluid) |
97 | - | return sides.up |
97 | + | local f,s,t = tonumber(fluid[1]),tonumber(fluid[2]),tonumber(fluid[3]) |
98 | - | elseif transposer.getInventoryName(sides.down) == "actuallyadditions:block_phantom_liquiface" then |
98 | + | tank.setFrequency(f,s,t) |
99 | - | return sides.down |
99 | + | |
100 | ||
101 | function moveFluidToMachine(recipeIndex) | |
102 | local fluid = RECIPES[recipeIndex]["fluid"] | |
103 | local transposer = component.proxy(transposerList["fluids"]["id"]) | |
104 | local inputSide = transposerList["fluids"]["side"] | |
105 | - | local fluid = RECIPES[recipeName]["fluid"] |
105 | + | local outputSide = transposerList["fluids"]["output"] |
106 | print(inputSide, outputSide) | |
107 | setTank(fluid) | |
108 | - | local outputSide = transposerList["fluids"]["output"] |
108 | + | if transposer.getTankLevel(sides[outputSide]) == 0 then |
109 | transposer.transferFluid(sides[inputSide], sides[outputSide], tonumber(fluid[4])) | |
110 | - | if transposer.getTankLevel(outputSide) == 0 then |
110 | + | |
111 | - | transposer.transferFluid(sides[inputSide], outputSide, fluidAmount) |
111 | + | |
112 | end | |
113 | ||
114 | function init() | |
115 | getTransposersInfo() | |
116 | end | |
117 | ||
118 | function loopDeLoop() | |
119 | while event.pull(1, "interrupted") == nil do | |
120 | if getInventoryItems()[1] ~= nil then | |
121 | local currentRecipeIndex = getCurrentRecipeIndex(getInventoryItems()) | |
122 | if currentRecipeIndex == nil then | |
123 | print("that's not a recipe you dum dum, check your items") | |
124 | else | |
125 | print(currentRecipeIndex) | |
126 | print("crafting : " .. RECIPES[currentRecipeIndex]["name"]) | |
127 | moveFluidToMachine(currentRecipeIndex) | |
128 | end | |
129 | end | |
130 | local event, address, arg1, arg2, arg3 = event.pull(1) | |
131 | if type(address) == "string" and component.isPrimary(address) then | |
132 | if event == "key_down" and arg2 == keyboard.keys.q then | |
133 | os.exit() | |
134 | end | |
135 | end | |
136 | end | |
137 | end | |
138 | ||
139 | init() | |
140 | loopDeLoop() |