forked from Ekdohibs/itest
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinit.lua
More file actions
303 lines (284 loc) · 8.47 KB
/
init.lua
File metadata and controls
303 lines (284 loc) · 8.47 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
local itest_world_upgrade = minetest.setting_getbool("voltbuild_itest_world_upgrade") or false
local generate_docs = minetest.setting_getbool("voltbuild_generate_docs")
modpath = minetest.get_modpath("voltbuild")
moreores_path = minetest.get_modpath("moreores")
pipeworks_path = minetest.get_modpath("pipeworks")
voltbuild = {}
voltbuild.registered_ores = {}
--enables more assert checks
voltbuild.debug = false
--upgrades nodes in their abm to reset their energy and max energy
voltbuild.upgrade = true or itest_world_upgrade
function voltbuild.register_ore(name,value)
voltbuild.registered_ores[name]=value
end
function voltbuild_create_infotext(name)
return(string.gsub(string.sub(name,string.find(name,":")+1),"_"," "))
end
function voltbuild_hacky_swap_node(pos,name)
local node = minetest.env:get_node(pos)
local meta = minetest.env:get_meta(pos)
if node.name == name then
return
end
node.name = name
local meta0 = meta:to_table()
minetest.env:set_node(pos,node)
meta = minetest.env:get_meta(pos)
meta:from_table(meta0)
meta:set_string("infotext",voltbuild_create_infotext(node.name))
end
function addVect(pos1,pos2)
return {x=pos1.x+pos2.x,y=pos1.y+pos2.y,z=pos1.z+pos2.z}
end
function param22dir(param2)
if param2==0 then
return {x=1,y=0,z=0}
elseif param2==1 then
return {x=0,y=0,z=-1}
elseif param2==2 then
return {x=-1,y=0,z=0}
else
return {x=0,y=0,z=1}
end
end
function get_node_field(name,meta,key,pos)
if meta == nil then meta = minetest.env:get_meta(pos) end
if name == nil then name = minetest.env:get_node(pos).name end
if meta:get_string(key) ~= "" then return meta:get_int(key) end
if minetest.registered_nodes[name] and
minetest.registered_nodes[name].voltbuild and
minetest.registered_nodes[name].voltbuild[key] then
return minetest.registered_nodes[name].voltbuild[key]
end
return minetest.get_item_group(name,key)
end
function get_node_field_float(name,meta,key,pos)
if meta == nil then meta = minetest.env:get_meta(pos) end
if name == nil then name = minetest.env:get_node(pos).name end
if meta:get_string(key) ~= "" then return meta:get_float(key) end
if minetest.registered_nodes[name] and
minetest.registered_nodes[name].voltbuild and
minetest.registered_nodes[name].voltbuild[key] then
return minetest.registered_nodes[name].voltbuild[key]
end
return 0
end
function get_item_field(name,key)
if minetest.registered_items[name] and
minetest.registered_items[name].voltbuild and
minetest.registered_items[name].voltbuild[key] then
return minetest.registered_items[name].voltbuild[key]
end
return minetest.get_item_group(name,key)
end
function is_fuel_no_lava(stack)
return (minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0)
and (string.find(stack:get_name(),"lava")==nil)
end
function clone_node(name)
node2={}
node=minetest.registered_nodes[name]
for k,v in pairs(node) do
node2[k]=v
end
return node2
end
function voltbuild.deep_copy (table_from,table_to)
local key,value
for key,value in pairs(table_from) do
if table_to[key] == nil then
if type(value) == "table" then
local deep_value = voltbuild.deep_copy(value,{})
table_to[key]=deep_value
else
table_to[key]=value
end
elseif type(table_to[key]) == "table" and type(value) == "table" then
table_to[key] = voltbuild.deep_copy(value,table_to[key])
end
end
return table_to
end
dofile(modpath.."/mapgen.lua")
dofile(modpath.."/voltbuild_objects.lua")
dofile(modpath.."/components.lua")
dofile(modpath.."/iron_furnace.lua")
dofile(modpath.."/energy_transport.lua")
dofile(modpath.."/cables.lua")
dofile(modpath.."/charge.lua")
dofile(modpath.."/generators.lua")
dofile(modpath.."/storage.lua")
dofile(modpath.."/consumers.lua")
dofile(modpath.."/craft.lua")
if itest_world_upgrade then
dofile(modpath.."/itest_upgrade_compat.lua")
print("voltbuild is using one way upgrade")
end
if generate_docs then
print("Generating voltbuild documentation.")
local key,value
local k, v
local craft_file = io.open(modpath.."/doc/crafts.txt","w")
for key, value in pairs(minetest.registered_items) do
if string.match(key,"voltbuild:") then
local crafts = minetest.get_all_craft_recipes(key)
if crafts and #crafts > 0 then
craft_file:write("output is ",key,"\n")
craft_file:write("In game description is ",value["description"],"\n")
local recipe
for k,recipe in pairs(crafts) do
if recipe.type then
craft_file:write("method is ",recipe.type,"\n")
end
if recipe.width == 0 then
craft_file:write("shapeless is true\n")
recipe.width=3
end
craft_file:write("recipe is\n")
local height
for k=1,9 do
if recipe.items[k] then
height = math.ceil(k/recipe.width)
end
end
for k=1,recipe.width*height do
if k % recipe.width == 1 or recipe.width == 1 then
craft_file:write(" ")
end
if recipe.items[k] then
craft_file:write(recipe.items[k])
else
craft_file:write("\"\"")
end
if k ~= recipe.width*height then
craft_file:write(", ")
end
if k % recipe.width == 0 then
craft_file:write("\n")
end
end
end
craft_file:write("\n\n")
end
end
end
for key, value in pairs(voltbuild.recipes) do
for k, v in pairs (value) do
--ignore __index and other metatable functions
if string.find(k,"__") ~= 1 then
local v_name
if type(v) == "string" then
craft_file:write("output is ",v,"\n")
if not string.find(v," ") then
v_name = v
else
v_name = string.sub(v,1,string.find(v," ")-1)
end
else
local craft_result,leftover = v(ItemStack(k))
v_name = craft_result.item:get_name()
craft_file:write("output is ",v_name,"\n")
end
local desc = minetest.registered_items[v_name]["description"]
craft_file:write("In game description is ",desc,"\n")
craft_file:write("method is ",key,"\n")
craft_file:write("recipe is ",k,"\n\n")
end
end
end
io.close(craft_file)
local volt_objects = {
generators = {type_check = function (name,table)
if table.groups.energy and not table.groups.energy_consumer then
return true
end
return false
end},
batboxes = {type_check = function (name,table)
if table.groups.energy and table.groups.energy_consumer and table.groups.energy_storage then
return true
end
return false
end},
transformers = {type_check = function (name,table)
if table.groups.energy_consumer and string.match(name,"transformer") then
return true
end
return false
end},
tools = {type_check = function(name,table)
if table.tool_capabilities then
return true
end
return false
end},
components = {type_check = function(name,table)
if table.voltbuild and table.voltbuild.component then
return true
end
return false
end},
nuclear_parts = {type_check = function(name,table)
if table.voltbuild and table.voltbuild.nuclear then
return true
end
return false
end},
--consumers goes last in list because easier to define it as not the others
consumers = {}}
volt_objects.consumers.type_check = function (name,table)
local ky, vl
for ky,vl in pairs(volt_objects) do
if ky ~= "consumers" then
if vl.type_check(name,table) then
return false
end
end
end
if table.groups.energy_consumer then
return true
end
return false
end
for key, value in pairs(minetest.registered_items) do
if string.match(key,"voltbuild:") and not string.match(key,"_active") then
for k, v in pairs(volt_objects) do
if v.type_check(key,value) then
volt_objects[k][key] = value
end
end
end
end
for key, value in pairs(volt_objects) do
local doc_file = io.open(modpath.."/doc/"..key..".txt","w")
local ky,vl
for ky, vl in pairs(value) do
if ky ~= "type_check" and ky ~= "file_summary" then
if vl and vl.documentation then
doc_file:write(ky,"\n")
if vl.description then
doc_file:write("In game description is ",vl.description,"\n")
else
print("WARNING! "..ky.." does not have description!!!!")
end
local required_fields = {"summary"}
for k,v in pairs(required_fields) do
if not vl.documentation[v] then
print("WARNING! "..ky.." does not have documentation."..v.." table!!!!")
end
end
for k, v in pairs(vl.documentation) do
doc_file:write(string.sub(k,1,1):upper(),string.sub(k,2),":\n")
doc_file:write(v,"\n")
end
doc_file:write("\n")
else
print("WARNING! "..ky.." does not have documentation table!!!!")
end
end
end
io.close(doc_file)
end
end
print("voltbuild loaded!")