View difference between Paste ID: bkcHsUG6 and xHQv4Jf4
SHOW: | | - or go back to the newest paste.
1
--[[
2
	Using: CC: Tweaked, Plethora
3-
	pastebin run xHQv4Jf4
3+
	pastebin run bkcHsUG6
4-
	pastebin get xHQv4Jf4 startup
4+
	pastebin get bkcHsUG6 startup
5
]]--
6
7-
inputChest = peripheral.wrap("minecraft:ender chest_0")
7+
if pcall(os.loadAPI, "jLib/jFuncs") then
8
else
9-
fabricatorsMap = {}
9+
    shell.run("pastebin get kqBFGcfV jLib/jFuncs")
10-
fabricatorsMap ["forestry:fabricator_0"] = { material = "Tin Ingot" }
10+
    os.loadAPI("jLib/jFuncs")
11
end
12-
fabricatorPerip = {}
12+
13-
for key, perip in pairs(fabricatorsMap) do
13+
14-
	perip.perip = peripheral.wrap(key)
14+
local smelters = { peripheral.find("xu2:tilelargishchest") }
15
local inputChest = peripheral.find("minecraft:ender chest")
16
17-
function sendAll(items, fabricator)
17+
local recipes= { 
18-
	for i, _ in pairs(items) do
18+
    [1] = { [1] = { ["name"] = "thermalfoundation:material", ["damage"] = 128, ["count"] = 12},
19-
		inputChest.pushItems(fabricator, i)
19+
			[2] = { ["name"] = "thermalfoundation:material", ["damage"] = 130, ["count"] = 4},
20
			[3] = { ["name"] = "minecraft:redstone", ["damage"] = 0, ["count"] = 40} },
21
	[2] = { [1] = { ["name"] = "minecraft:end_stone", ["damage"] = 0, ["count"] = 8},
22
			[2] = { ["name"] = "enderio:item_alloy_ingot", ["damage"] = 6, ["count"] = 8},
23
			[3] = { ["name"] = "minecraft:obsidian", ["damage"] = 0, ["count"] = 8} },
24-
    local items = inputChest.list()
24+
	[3] = { [1] = { ["name"] = "minecraft:iron_ingot", ["damage"] = 0, ["count"] = 8},
25
			[2] = { ["name"] = "thermalfoundation:material", ["damage"] = 768, ["count"] = 8},
26-
    for i, item in pairs(items) do
26+
			[3] = { ["name"] = "minecraft:obsidian", ["damage"] = 0, ["count"] = 8} },
27-
		local meta = inputChest.getItem(i).getMetadata()
27+
	[4] = { [1] = { ["name"] = "minecraft:dye", ["damage"] = 3, ["count"] = 8},
28-
        for key, fabMap in pairs(fabricatorsMap) do
28+
			[2] = { ["name"] = "thermalfoundation:material", ["damage"] = 768, ["count"] = 8},
29-
            if(string.find(meta.displayName, fabMap.material)) then
29+
			[3] = { ["name"] = "minecraft:slime_ball", ["damage"] = 0, ["count"] = 4} },
30-
            	sendAll(items, key)
30+
	[5] = { [1] = { ["name"] = "minecraft:slime_ball", ["damage"] = 0, ["count"] = 2},
31-
        	end
31+
			[2] = { ["name"] = "thermalfoundation:material", ["damage"] = 768, ["count"] = 12} },
32-
        end
32+
	[6] = { [1] = { ["name"] = "minecraft:iron_ingot", ["damage"] = 0, ["count"] = 8},
33-
    end
33+
			[2] = { ["name"] = "thermalfoundation:material", ["damage"] = 768, ["count"] = 8},
34
			[3] = { ["name"] = "appliedenergistics2:material", ["damage"] = 5, ["count"] = 8} },
35
	[7] = { [1] = { ["name"] = "minecraft:redstone", ["damage"] = 0, ["count"] = 8},
36
			[2] = { ["name"] = "appliedenergistics2:material", ["damage"] = 5, ["count"] = 8} },
37
	[8] = { [1] = { ["name"] = "minecraft:soul_sand", ["damage"] = 0, ["count"] = 8},
38
			[2] = { ["name"] = "minecraft:gold_ingot", ["damage"] = 0, ["count"] = 8} },
39
	[9] = { [1] = { ["name"] = "enderio:item_material", ["damage"] = 0, ["count"] = 1},
40
			[2] = { ["name"] = "enderio:item_material", ["damage"] = 52, ["count"] = 1} },
41
	[10] = { [1] = { ["name"] = "minecraft:quartz", ["damage"] = 0, ["count"] = 32} },
42
	[11] = { [1] = { ["name"] = "minecraft:redstone", ["damage"] = 0, ["count"] = 8},
43
			[2] = { ["name"] = "minecraft:gold_ingot", ["damage"] = 0, ["count"] = 8},
44
			[3] = { ["name"] = "minecraft:glowstone_dust", ["damage"] = 0, ["count"] = 8} },
45
	[12] = { [1] = { ["name"] = "enderio:item_alloy_ingot", ["damage"] = 1, ["count"] = 8},
46
			[2] = { ["name"] = "minecraft:ender_pearl", ["damage"] = 0, ["count"] = 8} },
47
	[13] = { [1] = { ["name"] = "minecraft:iron_ingot", ["damage"] = 0, ["count"] = 16},
48
			[2] = { ["name"] = "thermalfoundation:material", ["damage"] = 133, ["count"] = 8} },
49
	[14] = { [1] = { ["name"] = "thermalfoundation:material", ["damage"] = 130, ["count"] = 4},
50
			[2] = { ["name"] = "minecraft:glowstone_dust", ["damage"] = 0, ["count"] = 16},
51
			[3] = { ["name"] = "thermalfoundation:material", ["damage"] = 129, ["count"] = 12} },
52
	[15] = { [1] = { ["name"] = "thermalfoundation:material", ["damage"] = 768, ["count"] = 8},
53
			[2] = { ["name"] = "minecraft:coal", ["damage"] = 0, ["count"] = 8},
54
			[3] = { ["name"] = "minecraft:iron_ingot", ["damage"] = 0, ["count"] = 4} },
55
	[16] = { [1] = { ["name"] = "enderio:item_material", ["damage"] = 67, ["count"] = 1},
56
			[2] = { ["name"] = "enderio:item_material", ["damage"] = 66, ["count"] = 1} },
57
	[17] = { [1] = { ["name"] = "minecraft:gold_ingot", ["damage"] = 0, ["count"] = 8},
58
			[2] = { ["name"] = "thermalfoundation:material", ["damage"] = 130, ["count"] = 8} },
59
	[18] = { [1] = { ["name"] = "ic2:dust", ["damage"] = 9, ["count"] = 2},
60
			[2] = { ["name"] = "minecraft:wool", ["damage"] = 0, ["count"] = 2},
61
			[3] = { ["name"] = "thermalfoundation:material", ["damage"] = 65, ["count"] = 2} },
62
    [19] = { [1] = { ["name"] = "thermalfoundation:material", ["damage"] = 128, ["count"] = 8},
63
			[2] = { ["name"] = "minecraft:iron_ingot", ["damage"] = 0, ["count"] = 8},
64
			[3] = { ["name"] = "thermalfoundation:material", ["damage"] = 131, ["count"] = 8} },
65
	[20] = { [1] = { ["name"] = "minecraft:redstone", ["damage"] = 0, ["count"] = 8},
66
			[2] = { ["name"] = "minecraft:iron_ingot", ["damage"] = 0, ["count"] = 8} },
67
	[21] = { [1] = { ["name"] = "minecraft:iron_ingot", ["damage"] = 0, ["count"] = 8},
68
			[2] = { ["name"] = "minecraft:ender_pearl", ["damage"] = 0, ["count"] = 8} }
69
} 
70
71
local currSmelter = 1
72
local maxSmelter = #smelters
73
74
local function containsRecipe(items, recipe)
75
	local needed = {}
76
	for _, material in pairs(recipe) do
77
		table.insert(needed, {["name"] = material.name, ["damage"] = material.damage, ["count"] =  material.count})
78
	end
79
80
	local ret = {}
81
	for _, material in pairs(needed) do
82
    	for i, item in pairs(items) do
83
			if(item.name == material.name and item.damage == material.damage and material.count > 0) then
84
				--print(("Found match for %s-%s at slot %s"):format(material.name, material.damage, i))
85
				--print("-------------------------")
86
				table.insert(ret, { ["slot"] = i, ["count"] =  math.min(material.count, item.count)})
87
				material.count = material.count - math.min(material.count, item.count)
88
			end
89
		end
90
	end
91
	
92
93
	for _, material in pairs(needed) do
94
		if(material.count > 0) then
95
			return nil
96
		end
97
	end
98
	
99
	return ret
100
end
101
102
local function firstValidRecipe(items)
103
	local valid = nil
104
	for _, recipe in pairs(recipes) do
105
		valid = containsRecipe(items, recipe)
106
		if(valid ~= nil) then
107
			return valid
108
		end
109
	end
110
	return nil
111
end
112
113
local function sendItems(slots)
114
	for _, slot in pairs(slots) do
115
		inputChest.pushItems(peripheral.getName(smelters[currSmelter]), slot.slot, slot.count)
116
	end
117
	currSmelter = currSmelter + 1
118
	if(currSmelter > maxSmelter) then
119
		currSmelter = 1
120
	end
121
end
122
123
124
while (true) do
125
	local allItems = inputChest.list()
126
	local slots = firstValidRecipe(allItems)
127
	if(slots ~= nil) then
128
		sendItems(slots)
129
	else
130
		os.sleep(1)
131
	end	
132
end
133
134