]> git.lizzy.rs Git - elidragon_v2.git/commitdiff
Add schems API
authorElias Fleckenstein <eliasfleckenstein@web.de>
Fri, 19 Feb 2021 20:59:37 +0000 (21:59 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Fri, 19 Feb 2021 20:59:37 +0000 (21:59 +0100)
mods/elidragon_schems/init.lua [new file with mode: 0644]
mods/elidragon_schems/mod.conf [new file with mode: 0644]

diff --git a/mods/elidragon_schems/init.lua b/mods/elidragon_schems/init.lua
new file mode 100644 (file)
index 0000000..58b44e7
--- /dev/null
@@ -0,0 +1,45 @@
+local schems = {}
+schems.loaded = {}
+
+function schems.get(name)
+       return schems.loaded[name].data
+end
+
+function schems.get_raw(name)
+       return schems.loaded[name].raw
+end
+
+function schems.load(name)
+       local schem = {}
+       local file = io.open(minetest.get_modpath(minetest.get_current_modname()) .. "/schems/" .. name .. ".we", "r")
+       schem.raw = file:read()
+       file:seek("set")
+       local _, _, contents = file:read("*number", 1, "*all")
+       file:close()
+       schem.data = minetest.deserialize(contents)
+       schems.loaded[name] = schem
+end
+
+function schems.check(pos, name)
+       local schem = schems.get(name)
+       for _, n in ipairs(schem) do
+               if minetest.get_node(vector.add(pos, n)).name ~= n.name then
+                       return false
+               end
+       end
+       return true
+end
+
+function schems.remove(pos, name)
+       local schem = schems.get(name)
+       for _, n in ipairs(schem) do
+               minetest.remove_node(vector.add(pos, n))
+       end
+end
+
+function schems.add_schem(pos, schemname)
+       local schem_raw = schems.get_raw(schemname)
+       worldedit.deserialize(pos, schem_raw)
+end
+
+elidragon.schems = schems
diff --git a/mods/elidragon_schems/mod.conf b/mods/elidragon_schems/mod.conf
new file mode 100644 (file)
index 0000000..5ced035
--- /dev/null
@@ -0,0 +1,4 @@
+name = elidragon_schems
+author = Fleckenstein
+description = A small schem API for Elidragon v2, runs on top of worldedit
+depends = elidragon, worldedit