Make falling of trap stones more unpredictable
[minetest_pyramids/tsm_pyramids.git] / nodes.lua
blobf31e3c3b9635bd4c6dafa8ad679a0bda69182eea
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 minetest.register_node("tsm_pyramids:trap", {
65 description = S("Cracked Sandstone Brick"),
66 _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."),
67 tiles = {"default_sandstone_brick.png^tsm_pyramids_crack.png"},
68 is_ground_content = false,
69 groups = {crumbly=3,cracky=3},
70 sounds = default.node_sound_stone_defaults(),
71 on_construct = function(pos)
72 minetest.get_node_timer(pos):start(0.1)
73 end,
74 _tsm_pyramids_crack = 1,
75 on_timer = trap_on_timer,
76 drop = {
77 items = {
78 { items = { "default:sand" }, rarity = 1 },
79 { items = { "default:sand" }, rarity = 2 },
84 minetest.register_node("tsm_pyramids:trap_2", {
85 description = S("Falling Cracked Sandstone Brick"),
86 _doc_items_longdesc = S("This old porous brick falls under its own weight."),
87 tiles = {"default_sandstone_brick.png^tsm_pyramids_crack2.png"},
88 is_ground_content = false,
89 groups = {crumbly=3,cracky=3,falling_node=1,not_in_creative_inventory=1},
90 sounds = default.node_sound_stone_defaults(),
91 drop = {
92 items = {
93 { items = { "default:sand" }, rarity = 1 },
94 { items = { "default:sand" }, rarity = 2 },
99 minetest.register_node("tsm_pyramids:desert_trap", {
100 description = S("Cracked Desert Sandstone Brick"),
101 _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."),
102 tiles = {"default_desert_sandstone_brick.png^tsm_pyramids_crack.png"},
103 is_ground_content = false,
104 groups = {crumbly=3,cracky=3},
105 sounds = default.node_sound_stone_defaults(),
106 on_construct = function(pos)
107 minetest.get_node_timer(pos):start(0.1)
108 end,
109 _tsm_pyramids_crack = 1,
110 on_timer = trap_on_timer,
111 drop = {
112 items = {
113 { items = { "default:desert_sand" }, rarity = 1 },
114 { items = { "default:desert_sand" }, rarity = 2 },
119 minetest.register_node("tsm_pyramids:desert_trap_2", {
120 description = S("Falling Cracked Desert Sandstone Brick"),
121 _doc_items_longdesc = S("This old porous brick falls under its own weight."),
122 tiles = {"default_desert_sandstone_brick.png^tsm_pyramids_crack2.png"},
123 is_ground_content = false,
124 groups = {crumbly=3,cracky=3,falling_node=1,not_in_creative_inventory=1},
125 sounds = default.node_sound_stone_defaults(),
126 drop = {
127 items = {
128 { items = { "default:desert_sand" }, rarity = 1 },
129 { items = { "default:desert_sand" }, rarity = 2 },