forked from Atria1234/WideChests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
81 lines (75 loc) · 2.35 KB
/
init.lua
File metadata and controls
81 lines (75 loc) · 2.35 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
require("init-settings")
function MergingChests.Limits()
if MergingChests.CheckMod(MergingChests.UnlimitedModName) then
return {
width = settings.startup["max-chest-width"].value,
height = settings.startup["max-chest-height"].value,
area = settings.startup["max-chest-area"].value
}
else
return {
width = math.min(settings.startup["max-chest-width"].value, 42),
height = math.min(settings.startup["max-chest-height"].value, 42),
area = math.min(settings.startup["max-chest-area"].value, 1600)
}
end
end
MergingChests.MergableChestIds = { }
for _, data in pairs(MergingChests.MergableChestIdToData) do
if (
MergingChests.CheckMod(MergingChests.AllTypesModName)
or data.logistic and MergingChests.CheckMod(MergingChests.LogisticModName)
or settings.startup["mergable-chest-name"].value == data.name
) then
table.insert(MergingChests.MergableChestIds, data.id)
end
end
local ANY = "any-size"
local chestWhitelist = nil
function parseWhitelist()
chestWhitelist = { }
local hasItem = false
for width, height in string.gmatch(settings.startup["whitelist-chest-sizes"].value, "([%dN]+)[×xX$*]([%dN]+)") do
if (tonumber(width) or width == "N") and (tonumber(height) or height == "N") then
width = tonumber(width) or ANY
height = tonumber(height) or ANY
if not chestWhitelist[width] then
chestWhitelist[width] = { }
hasItem = true
end
if not chestWhitelist[width][ANY] then
chestWhitelist[width][height] = true
end
end
end
if not hasItem then
chestWhitelist = { [ANY] = { [ANY] = true } }
end
end
MergingChests.AreaChests = {
["wooden-chest"] = true,
["iron-chest"] = true,
["steel-chest"] = true,
["brass-chest"] = true,
["titanium-chest"] = true,
["small-storage"] = true,
["small-storage-2"] = true,
["small-storage-3"] = true,
["nullius-small-chest-1"] = true,
["nullius-small-chest-2"] = true
}
function MergingChests.CheckWhitelist(id, width, height)
if chestWhitelist == nil then
parseWhitelist()
end
local limits = MergingChests.Limits()
return
(MergingChests.AreaChests[id] or width == 1 or height == 1) and
width * height <= limits.area and
width <= limits.width and
height <= limits.height and
(
(chestWhitelist[ANY] and (chestWhitelist[ANY][ANY] or chestWhitelist[ANY][height])) or
(chestWhitelist[width] and (chestWhitelist[width][ANY] or chestWhitelist[width][height]))
)
end