aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/schems.lua42
-rw-r--r--src/main/wither_spawn.lua21
2 files changed, 63 insertions, 0 deletions
diff --git a/src/common/schems.lua b/src/common/schems.lua
new file mode 100644
index 0000000..ace1637
--- /dev/null
+++ b/src/common/schems.lua
@@ -0,0 +1,42 @@
+skycraft.schems = {}
+
+function skycraft.get_schem(schemname)
+ return skycraft.schems[schemname].data
+end
+
+function skycraft.get_schem_raw(schemname)
+ return skycraft.schems[schemname].raw
+end
+
+function skycraft.load_schem(schemname)
+ local schem = {}
+ local file = io.open(skycraft.modpath .. "/schems/" .. schemname .. ".we", "r")
+ schem.raw = file:read()
+ file:seek("set")
+ local _, _, contents = file:read("*number", 1, "*all")
+ file:close()
+ schem.data = minetest.deserialize(contents)
+ skycraft.schems[schemname] = schem
+end
+
+function skycraft.check_schem(pos, schemname)
+ local schem = skycraft.get_schem(schemname)
+ for _, n in pairs(schem) do
+ if minetest.get_node(vector.add(pos, n)).name ~= n.name then
+ return false
+ end
+ end
+ return true
+end
+
+function skycraft.remove_schem(pos, schemname)
+ local schem = skycraft.get_schem(schemname)
+ for _, n in pairs(schem) do
+ minetest.remove_node(vector.add(pos, n))
+ end
+end
+
+function skycraft.add_schem(pos, schemname)
+ local schem_raw = skycraft.get_schem_raw(schemname)
+ worldedit.deserialize(pos, schem_raw)
+end
diff --git a/src/main/wither_spawn.lua b/src/main/wither_spawn.lua
new file mode 100644
index 0000000..e52a732
--- /dev/null
+++ b/src/main/wither_spawn.lua
@@ -0,0 +1,21 @@
+local dim = {"x", "z"}
+
+for _, d in pairs(dim) do
+ skycraft.load_schem("wither_spawn_" .. d)
+end
+
+minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing)
+ if newnode.name == "mcl_heads:wither_skeleton" then
+ for _, d in pairs(dim) do
+ for i = 0, 2 do
+ local p = vector.add(pos, {x = 0, y = -2, z = 0, [d] = -i})
+ local schemname = "wither_spawn_" .. d
+ if skycraft.check_schem(p, schemname) then
+ skycraft.remove_schem(p, schemname)
+ minetest.add_entity(vector.add(p, {x = 0, y = 1, z = 0, [d] = 1}), "mobs_mc:wither")
+ end
+ end
+ end
+ end
+end)
+