Fix crash if on_punch was called w/ nil damage
[minetest_pyramids/tsm_pyramids.git] / nodes.lua
blob6c3cb0fa10b9e2ab14ccca2c63903633f089185a
1 local S = minetest.get_translator("tsm_pyramids")
3 local img = {
4 "eye", "men", "sun",
5 "ankh", "scarab", "cactus"
7 local desc = {
8 S("Sandstone with Eye Engraving"), S("Sandstone with Man Engraving"), S("Sandstone with Sun Engraving"),
9 S("Desert Sandstone with Ankh Engraving"), S("Desert Sandstone with Scarab Engraving"), S("Desert Sandstone with Cactus Engraving")
12 local decodesc = ""
13 if minetest.get_modpath("doc_items") then
14 decodesc = doc.sub.items.temp.deco
15 end
17 for i=1, #img do
18 local sandstone_img, basenode
19 if i > 3 then
20 sandstone_img = "default_desert_sandstone.png"
21 basenode = "default:desert_sandstone"
22 else
23 sandstone_img = "default_sandstone.png"
24 basenode = "default:sandstone"
25 end
26 minetest.register_node("tsm_pyramids:deco_stone"..i, {
27 description = desc[i],
28 _doc_items_longdesc = decodesc,
29 is_ground_content = false,
30 tiles = {sandstone_img, sandstone_img, sandstone_img.."^tsm_pyramids_"..img[i]..".png"},
31 groups = minetest.registered_nodes[basenode].groups,
32 sounds = minetest.registered_nodes[basenode].sounds,
34 end
36 local trap_on_timer = function(pos, elapsed)
37 local n = minetest.get_node(pos)
38 if not (n and n.name) then
39 return true
40 end
41 -- Drop trap stone when player is nearby
42 local objs = minetest.get_objects_inside_radius(pos, 2)
43 for i, obj in pairs(objs) do
44 if obj:is_player() then
45 if minetest.registered_nodes[n.name]._tsm_pyramids_crack and minetest.registered_nodes[n.name]._tsm_pyramids_crack < 2 then
46 -- 70% chance to ignore player to make the time of falling less predictable
47 if math.random(1, 10) >= 3 then
48 return true
49 end
50 if n.name == "tsm_pyramids:trap" then
51 minetest.set_node(pos, {name="tsm_pyramids:trap_2"})
52 minetest.check_for_falling(pos)
53 elseif n.name == "tsm_pyramids:desert_trap" then
54 minetest.set_node(pos, {name="tsm_pyramids:desert_trap_2"})
55 minetest.check_for_falling(pos)
56 end
57 return true
58 end
59 end
60 end
61 return true
62 end
64 local register_trap_stone = function(basename, desc_normal, desc_falling, base_tile, drop)
65 minetest.register_node("tsm_pyramids:"..basename, {
66 description = desc_normal,
67 _doc_items_longdesc = S("This brick is old, porous and unstable and is barely able to hold itself. One should be careful not to disturb it."),
68 tiles = { base_tile .. "^tsm_pyramids_crack.png" },
69 is_ground_content = false,
70 groups = {crumbly=3,cracky=3},
71 sounds = default.node_sound_stone_defaults(),
72 on_construct = function(pos)
73 minetest.get_node_timer(pos):start(0.1)
74 end,
75 _tsm_pyramids_crack = 1,
76 on_timer = trap_on_timer,
77 drop = drop,
80 minetest.register_node("tsm_pyramids:"..basename.."_2", {
81 description = desc_falling,
82 _doc_items_longdesc = S("This old porous brick falls under its own weight."),
83 tiles = { base_tile .. "^tsm_pyramids_crack2.png" },
84 is_ground_content = false,
85 groups = {crumbly=3,cracky=3,falling_node=1,not_in_creative_inventory=1},
86 sounds = default.node_sound_stone_defaults(),
87 drop = drop,
89 end
91 register_trap_stone("trap",
92 S("Cracked Sandstone Brick"), S("Falling Cracked Sandstone Brick"),
93 "default_sandstone_brick.png",
94 { items = { { items = { "default:sand" }, rarity = 1 }, { items = { "default:sand" }, rarity = 2 }, } })
95 register_trap_stone("desert_trap",
96 S("Cracked Desert Sandstone Brick"), S("Falling Cracked Desert Sandstone Brick"),
97 "default_desert_sandstone_brick.png",
98 { items = { { items = { "default:desert_sand" }, rarity = 1 }, { items = { "default:desert_sand" }, rarity = 2 }, } })