]> git.lizzy.rs Git - minetest-m13.git/commitdiff
Add TNT
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 15 May 2021 18:57:43 +0000 (20:57 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 15 May 2021 18:57:43 +0000 (20:57 +0200)
data/mods/tnt/init.lua [new file with mode: 0644]
data/mods/tnt/textures/tnt_bottom.png [new file with mode: 0644]
data/mods/tnt/textures/tnt_side.png [new file with mode: 0644]
data/mods/tnt/textures/tnt_top.png [new file with mode: 0644]

diff --git a/data/mods/tnt/init.lua b/data/mods/tnt/init.lua
new file mode 100644 (file)
index 0000000..ec4224a
--- /dev/null
@@ -0,0 +1,39 @@
+function explode(pos)
+       for x = -5, 5 do
+               for y = -5, 5 do
+                       for z = -5, pos.z + 5 do
+                               local d = math.floor(math.sqrt(x ^ 2 + y ^ 2 + z ^ 2))
+                               if d < 3 or math.random(d) < 3 then
+                                       local pos = {
+                                               x = pos.x + x,
+                                               y = pos.y + y,
+                                               z = pos.z + z
+                                       }
+                                       local node = minetest.env:get_node(pos)
+                                       minetest.env:remove_node(pos)
+
+                                       if node.name == "tnt:tnt" then
+                                               explode(pos)
+                                       end
+
+                                       local def = minetest.registered_nodes[node.name]
+                                       if def.drop and type(def.drop) == "string" then
+                                               minetest.env:add_item(pos, def.drop)
+                                       end
+                               end
+                       end
+               end
+       end
+end
+
+minetest.register_node("tnt:tnt", {
+       description = "TNT",
+       tile_images = {"tnt_top.png", "tnt_bottom.png", "tnt_side.png"},
+})
+
+minetest.register_on_punchnode(function(pos, oldnode, digger)
+       if oldnode.name == "tnt:tnt" then
+               minetest.env:remove_node(pos)
+               explode(pos)
+    end
+end)
diff --git a/data/mods/tnt/textures/tnt_bottom.png b/data/mods/tnt/textures/tnt_bottom.png
new file mode 100644 (file)
index 0000000..cc2e586
Binary files /dev/null and b/data/mods/tnt/textures/tnt_bottom.png differ
diff --git a/data/mods/tnt/textures/tnt_side.png b/data/mods/tnt/textures/tnt_side.png
new file mode 100644 (file)
index 0000000..21109fb
Binary files /dev/null and b/data/mods/tnt/textures/tnt_side.png differ
diff --git a/data/mods/tnt/textures/tnt_top.png b/data/mods/tnt/textures/tnt_top.png
new file mode 100644 (file)
index 0000000..ceb44b6
Binary files /dev/null and b/data/mods/tnt/textures/tnt_top.png differ