]> git.lizzy.rs Git - skycraft.git/blob - src/common/schems.lua
Added Missing Files
[skycraft.git] / src / common / schems.lua
1 skycraft.schems = {}
2
3 function skycraft.get_schem(schemname)
4         return skycraft.schems[schemname].data
5 end
6
7 function skycraft.get_schem_raw(schemname)
8         return skycraft.schems[schemname].raw
9 end
10
11 function skycraft.load_schem(schemname)
12         local schem = {}
13         local file = io.open(skycraft.modpath .. "/schems/" .. schemname .. ".we", "r")
14         schem.raw = file:read()
15         file:seek("set")
16         local _, _, contents = file:read("*number", 1, "*all")
17         file:close()
18         schem.data = minetest.deserialize(contents)
19         skycraft.schems[schemname] = schem
20 end
21
22 function skycraft.check_schem(pos, schemname)
23         local schem = skycraft.get_schem(schemname)
24         for _, n in pairs(schem) do
25                 if minetest.get_node(vector.add(pos, n)).name ~= n.name then
26                         return false
27                 end
28         end
29         return true
30 end
31
32 function skycraft.remove_schem(pos, schemname)
33         local schem = skycraft.get_schem(schemname)
34         for _, n in pairs(schem) do
35                 minetest.remove_node(vector.add(pos, n))
36         end
37 end
38
39 function skycraft.add_schem(pos, schemname)
40         local schem_raw = skycraft.get_schem_raw(schemname)
41         worldedit.deserialize(pos, schem_raw)
42 end