5 -- global function to add new containers
6 function hopper:add_container(list)
7 for _, entry in pairs(list) do
9 local target_node = entry[2]
12 if string.sub(target_node, 1, 6) == "group:" then
13 local group_identifier, group_number
14 local equals_index = string.find(target_node, "=")
15 if equals_index ~= nil then
16 group_identifier = string.sub(target_node, 7, equals_index-1)
17 -- it's possible that the string was of the form "group:blah = 1", in which case we want to trim spaces off the end of the group identifier
18 local space_index = string.find(group_identifier, " ")
19 if space_index ~= nil then
20 group_identifier = string.sub(group_identifier, 1, space_index-1)
22 group_number = tonumber(string.sub(target_node, equals_index+1, -1))
24 group_identifier = string.sub(target_node, 7, -1)
25 group_number = "all" -- special value to indicate no number was provided
28 local group_info = hopper.groups[group_identifier]
29 if group_info == nil then
32 if group_info[group_number] == nil then
33 group_info[group_number] = {}
35 group_info[group_number][entry[1]] = entry[3]
36 hopper.groups[group_identifier] = group_info
37 neighbor_node = "group:"..group_identifier
38 -- result is a table of the form groups[group_identifier][group_number][relative_position][inventory_name]
40 local node_info = hopper.containers[target_node]
41 if node_info == nil then
44 node_info[entry[1]] = entry[3]
45 hopper.containers[target_node] = node_info
46 neighbor_node = target_node
47 -- result is a table of the form containers[target_node_name][relative_position][inventory_name]
50 local already_in_neighbors = false
51 for _, value in pairs(hopper.neighbors) do
52 if value == neighbor_node then
53 already_in_neighbors = true
57 if not already_in_neighbors then
58 table.insert(hopper.neighbors, neighbor_node)
63 -- "top" indicates what inventory the hopper will take items from if this node is located at the hopper's wide end
64 -- "side" indicates what inventory the hopper will put items into if this node is located at the hopper's narrow end and at the same height as the hopper
65 -- "bottom" indicates what inventory the hopper will put items into if this node is located at the hopper's narrow end and either above or below the hopper.
67 hopper:add_container({
68 {"top", "hopper:hopper", "main"},
69 {"bottom", "hopper:hopper", "main"},
70 {"side", "hopper:hopper", "main"},
71 {"side", "hopper:hopper_side", "main"},
73 {"bottom", "hopper:chute", "main"},
74 {"side", "hopper:chute", "main"},
76 {"bottom", "hopper:sorter", "main"},
77 {"side", "hopper:sorter", "main"},
80 hopper:add_container({
81 {"top", "utility:chest", "main"},
82 {"bottom", "utility:chest", "main"},
83 {"side", "utility:chest", "main"},
85 {"top", "utility:chest_open", "main"},
86 {"bottom", "utility:chest_open", "main"},
87 {"side", "utility:chest_open", "main"},
89 {"top", "utility:furnace", "dst"},
90 {"bottom", "utility:furnace", "src"},
91 {"side", "utility:furnace", "fuel"},
93 {"top", "utility:furnace_active", "dst"},
94 {"bottom", "utility:furnace_active", "src"},
95 {"side", "utility:furnace_active", "fuel"},