]> git.lizzy.rs Git - skycraft.git/commitdiff
Added Missing Files
authorElias Fleckenstein <eliasfleckenstein@web.de>
Tue, 9 Jun 2020 15:44:13 +0000 (17:44 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Tue, 9 Jun 2020 15:44:13 +0000 (17:44 +0200)
schems/wither_spawn_x.we [new file with mode: 0644]
schems/wither_spawn_z.we [new file with mode: 0644]
src/common/schems.lua [new file with mode: 0644]
src/main/wither_spawn.lua [new file with mode: 0644]

diff --git a/schems/wither_spawn_x.we b/schems/wither_spawn_x.we
new file mode 100644 (file)
index 0000000..7b8bc94
--- /dev/null
@@ -0,0 +1 @@
+5:return {{["y"] = 1, ["x"] = 0, ["name"] = "mcl_nether:soul_sand", ["z"] = 0}, {["y"] = 2, ["x"] = 0, ["name"] = "mcl_heads:wither_skeleton", ["z"] = 0, ["param2"] = 2, ["param1"] = 15}, {["y"] = 0, ["x"] = 1, ["name"] = "mcl_nether:soul_sand", ["z"] = 0}, {["y"] = 1, ["x"] = 1, ["name"] = "mcl_nether:soul_sand", ["z"] = 0}, {["y"] = 2, ["x"] = 1, ["name"] = "mcl_heads:wither_skeleton", ["z"] = 0, ["param2"] = 2, ["param1"] = 15}, {["y"] = 1, ["x"] = 2, ["name"] = "mcl_nether:soul_sand", ["z"] = 0}, {["y"] = 2, ["x"] = 2, ["name"] = "mcl_heads:wither_skeleton", ["z"] = 0, ["param2"] = 2, ["param1"] = 15}}
\ No newline at end of file
diff --git a/schems/wither_spawn_z.we b/schems/wither_spawn_z.we
new file mode 100644 (file)
index 0000000..0c9973f
--- /dev/null
@@ -0,0 +1 @@
+5:return {{["y"] = 0, ["x"] = 0, ["name"] = "mcl_nether:soul_sand", ["z"] = 1}, {["y"] = 1, ["x"] = 0, ["name"] = "mcl_nether:soul_sand", ["z"] = 0}, {["y"] = 1, ["x"] = 0, ["name"] = "mcl_nether:soul_sand", ["z"] = 1}, {["y"] = 1, ["x"] = 0, ["name"] = "mcl_nether:soul_sand", ["z"] = 2}, {["y"] = 2, ["x"] = 0, ["name"] = "mcl_heads:wither_skeleton", ["z"] = 0, ["param2"] = 3, ["param1"] = 15}, {["y"] = 2, ["x"] = 0, ["name"] = "mcl_heads:wither_skeleton", ["z"] = 1, ["param2"] = 3, ["param1"] = 15}, {["y"] = 2, ["x"] = 0, ["name"] = "mcl_heads:wither_skeleton", ["z"] = 2, ["param2"] = 3, ["param1"] = 15}}
\ No newline at end of file
diff --git a/src/common/schems.lua b/src/common/schems.lua
new file mode 100644 (file)
index 0000000..ace1637
--- /dev/null
@@ -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 (file)
index 0000000..e52a732
--- /dev/null
@@ -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)