-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata-final-fixes.lua
More file actions
118 lines (108 loc) · 4.43 KB
/
data-final-fixes.lua
File metadata and controls
118 lines (108 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
local base_loaders, loader_ids, modded_loaders = {}, {}, {}
local blacklist = {
["ee-infinity-loader"] = true
}
---@param old data.LoaderPrototype
---@param id uint8
---@return data.LoaderPrototype
local function make_copy(old, id)
local new = table.deepcopy(old)
new.name = id .. "-" .. old.name
if mods["aai-loaders"] and old.name:find("aai%-") then
local name = AAILoaders.make_tier {
name = id .. (old.name == "aai-loader" and "" or "-" .. old.name:sub(5, -8)),
transport_belt = "transport-belt",
fluid = settings.startup["aai-loaders-mode"].value == "lubricated" and data.raw["storage-tank"][old.name .. "-pipe"] and data.raw["storage-tank"][old.name .. "-pipe"].fluid_box.filter or nil,
fluid_per_minute = settings.startup["aai-loaders-mode"].value == "lubricated" and data.raw["storage-tank"][old.name .. "-pipe"] and data.raw["storage-tank"][old.name .. "-pipe"].fluid_box.volume - 100 or nil,
recipe = {},
unlubricated_recipe = {}
}.loader.name
data.raw.item[name] = nil
data.raw.recipe[name] = nil
new.name = name
end
new.localised_name = old.localised_name or { "entity-name." .. old.name }
new.localised_description = old.localised_description or { "entity-description." .. old.name }
new.hidden = not settings.startup["lu-show-all-loaders"].value
new.factoriopedia_alternative = old.factoriopedia_alternative or old.name
new.hidden_in_factoriopedia = true
data.raw[new.type][new.name] = new
return new
end
local max_stack_size
if feature_flags.space_travel then
-- update util constant for max stack size
max_stack_size = data.raw["utility-constants"]["default"].max_belt_stack_size or 0
max_stack_size = max_stack_size > 1 and max_stack_size or 4
data.raw["utility-constants"]["default"].max_belt_stack_size = max_stack_size
if not data.raw.technology["transport-belt-capacity-1"] and not data.raw.technology["py-transport-belt-capacity-1"] then
error("Technology transport-belt-capacity-1 not found! Please install a mod that adds this technology, such as:\n\nhttps://mods.factorio.com/mod/stack-inserters\n")
end
end
-- mark existing loaders as base loaders
for _, prototypes in pairs {
data.raw.loader,
data.raw["loader-1x1"]
} do for _, loader in pairs(prototypes) do
if not blacklist[loader.name] and not loader.ignore_by_loader_utils then
base_loaders[loader.name] = loader.name
modded_loaders[loader.name] = {[0] = loader.name}
loader_ids[loader.name] = 0
loader.per_lane_filters = false
loader.wait_for_full_stack = false
loader.respect_insert_limits = false
loader.placeable_by = loader.placeable_by or data.raw.item[loader.name] and {item = loader.name, count = 1} or nil
loader.filter_count = loader.filter_count >= 2 and loader.filter_count or 2 -- ensure at least 2 filters for the base loader
if max_stack_size then
loader.max_belt_stack_size = (loader.max_belt_stack_size or 0) > 1 and loader.max_belt_stack_size or max_stack_size
loader.adjustable_belt_stack_size = true
end
elseif loader.ignore_by_loader_utils then
blacklist[loader.name] = true
loader.ignore_by_loader_utils = nil
end
end end
-- find a way to avoid the race condition
for _, prototypes in pairs {
data.raw.loader,
data.raw["loader-1x1"]
} do for bit, id in pairs {
[0] = "lf",
"rl",
"fs"
} do for _, old in pairs(table.deepcopy(prototypes)) do
if not blacklist[old.name] then
local new = make_copy(old, id)
if id == "lf" then
new.filter_count = 2
new.per_lane_filters = true
elseif id == "rl" then
new.respect_insert_limits = true
elseif id == "fs" then
new.wait_for_full_stack = true
end
-- save the ID and lookup
loader_ids[new.name] = loader_ids[old.name] + 2^bit
base_loaders[new.name] = base_loaders[old.name]
modded_loaders[base_loaders[new.name]][loader_ids[new.name]] = new.name
modded_loaders[base_loaders[new.name]][loader_ids[new.name]] = new.name
end
end end end
-- set next_upgrade properly
for _, prototypes in pairs {
data.raw.loader,
data.raw["loader-1x1"]
} do for _, loader in pairs(prototypes) do
if not blacklist[loader.name] and loader.next_upgrade then
loader.next_upgrade = modded_loaders[prototypes[base_loaders[loader.name]].next_upgrade][loader_ids[loader.name]]
end
end end
data:extend{{
type = "mod-data",
name = "loader-utils",
data = {
base_loaders = base_loaders,
loader_ids = loader_ids,
modded_loaders = modded_loaders
}
}}