1 local S
= minetest
.get_translator("tsm_pyramids")
5 dofile(minetest
.get_modpath("tsm_pyramids").."/mummy.lua")
6 dofile(minetest
.get_modpath("tsm_pyramids").."/nodes.lua")
7 dofile(minetest
.get_modpath("tsm_pyramids").."/room.lua")
9 local mg_name
= minetest
.get_mapgen_setting("mg_name")
12 {name
="default:apple", max = 3},
13 {name
="default:steel_ingot", max = 3},
14 {name
="default:copper_ingot", max = 3},
15 {name
="default:gold_ingot", max = 2},
16 {name
="default:diamond", max = 1},
17 {name
="default:pick_steel", max = 1},
18 {name
="default:pick_diamond", max = 1},
19 {name
="default:papyrus", max = 9},
22 if minetest
.get_modpath("farming") then
23 table.insert(chest_stuff
, {name
="farming:bread", max = 3})
24 table.insert(chest_stuff
, {name
="farming:cotton", max = 8})
26 table.insert(chest_stuff
, {name
="farming:apple", max = 8})
27 table.insert(chest_stuff
, {name
="farming:apple", max = 3})
29 if minetest
.get_modpath("tnt") then
30 table.insert(chest_stuff
, {name
="tnt:gunpowder", max = 6})
32 table.insert(chest_stuff
, {name
="farming:apple", max = 3})
35 function tsm_pyramids
.fill_chest(pos
, stype
, flood_sand
)
36 minetest
.after(2, function()
37 local sand
= "default:sand"
38 if stype
== "desert_sandstone" or stype
== "desert_stone" then
39 sand
= "default:desert_sand"
41 local n
= minetest
.get_node(pos
)
42 if n
and n
.name
and n
.name
== "default:chest" then
43 local meta
= minetest
.get_meta(pos
)
44 local inv
= meta
:get_inventory()
45 inv
:set_size("main", 8*4)
47 -- Fill with sand in sand-flooded pyramids
49 table.insert(stacks
, {name
=sand
, count
= math
.random(1,32)})
52 if math
.random(1,10) >= 7 then
53 if minetest
.get_modpath("treasurer") ~= nil then
54 stacks
= treasurer
.select_random_treasures(3,7,9,{"minetool", "food", "crafting_component"})
57 local stuff
= chest_stuff
[math
.random(1,#chest_stuff
)]
58 table.insert(stacks
, {name
=stuff
.name
, count
= math
.random(1,stuff
.max)})
63 if not inv
:contains_item("main", stacks
[s
]) then
64 inv
:set_stack("main", math
.random(1,32), stacks
[s
])
72 local function add_spawner(pos
, mummy_offset
)
73 minetest
.set_node(pos
, {name
="tsm_pyramids:spawner_mummy"})
74 if not minetest
.settings
:get_bool("only_peaceful_mobs") then tsm_pyramids
.spawn_mummy(vector
.add(pos
, mummy_offset
),2) end
77 local function can_replace(pos
)
78 local n
= minetest
.get_node_or_nil(pos
)
79 if n
and n
.name
and minetest
.registered_nodes
[n
.name
] and not minetest
.registered_nodes
[n
.name
].walkable
then
88 local function make_foundation_part(pos
, set_to_stone
)
92 while can_replace(p2
)==true do
97 table.insert(set_to_stone
, table.copy(p2
))
102 local function make_entrance(pos
, brick
, sand
, flood_sand
)
103 local gang
= {x
=pos
.x
+10,y
=pos
.y
, z
=pos
.z
}
104 local max_sand_height
= math
.random(1,3)
106 local sand_height
= math
.random(1,max_sand_height
)
108 if flood_sand
and iy
<= sand_height
and iz
>= 3 then
109 minetest
.set_node({x
=gang
.x
+1,y
=gang
.y
+iy
,z
=gang
.z
+iz
}, {name
=sand
})
111 minetest
.remove_node({x
=gang
.x
+1,y
=gang
.y
+iy
,z
=gang
.z
+iz
})
113 if iz
>=3 and iy
== 3 then
114 minetest
.set_node({x
=gang
.x
,y
=gang
.y
+iy
+1,z
=gang
.z
+iz
}, {name
=brick
})
115 minetest
.set_node({x
=gang
.x
+1,y
=gang
.y
+iy
+1,z
=gang
.z
+iz
}, {name
=brick
})
116 minetest
.set_node({x
=gang
.x
+2,y
=gang
.y
+iy
+1,z
=gang
.z
+iz
}, {name
=brick
})
122 local function make_pyramid(pos
, brick
, sandstone
, stone
, sand
)
123 local set_to_brick
= {}
124 local set_to_sand
= {}
125 local set_to_stone
= {}
127 for iy
=0,math
.random(10,11),1 do
131 make_foundation_part({x
=pos
.x
+ix
,y
=pos
.y
,z
=pos
.z
+iz
}, set_to_stone
)
133 table.insert(set_to_brick
, {x
=pos
.x
+ix
,y
=pos
.y
+iy
,z
=pos
.z
+iz
})
135 local n
= minetest
.get_node({x
=pos
.x
+ix
,y
=pos
.y
+iy
+yy
,z
=pos
.z
+iz
})
136 if n
and n
.name
and n
.name
== stone
then
137 table.insert(set_to_sand
, {x
=pos
.x
+ix
,y
=pos
.y
+iy
+yy
,z
=pos
.z
+iz
})
143 minetest
.bulk_set_node(set_to_stone
, {name
=stone
})
144 minetest
.bulk_set_node(set_to_brick
, {name
=brick
})
145 minetest
.bulk_set_node(set_to_sand
, {name
=sand
})
148 local function make(pos
, brick
, sandstone
, stone
, sand
, ptype
, room_id
)
150 make_pyramid(pos
, brick
, sandstone
, stone
, sand
)
152 local ok
, msg
, flood_sand
= tsm_pyramids
.make_room(pos
, ptype
, room_id
)
153 -- Place mummy spawner
154 local r
= math
.random(1,3)
157 add_spawner({x
=pos
.x
+11,y
=pos
.y
+2, z
=pos
.z
+17}, {x
=0, y
=0, z
=-2})
160 add_spawner({x
=pos
.x
+17,y
=pos
.y
+2, z
=pos
.z
+11}, {x
=-2, y
=0, z
=0})
163 add_spawner({x
=pos
.x
+5,y
=pos
.y
+2, z
=pos
.z
+11}, {x
=2, y
=0, z
=0})
166 make_entrance({x
=pos
.x
,y
=pos
.y
, z
=pos
.z
}, brick
, sand
, flood_sand
)
168 minetest
.log("action", "Created pyramid at ("..pos
.x
..","..pos
.y
..","..pos
.z
..")")
172 local perl1
= {SEED1
= 9130, OCTA1
= 3, PERS1
= 0.5, SCAL1
= 250} -- Values should match minetest mapgen V6 desert noise.
175 local function hlp_fnct(pos
, name
)
176 local n
= minetest
.get_node_or_nil(pos
)
177 if n
and n
.name
and n
.name
== name
then
183 local function ground(pos
, old
)
185 while hlp_fnct(p2
, "air") do
196 minetest
.register_on_generated(function(minp
, maxp
, seed
)
197 if maxp
.y
< 0 then return end
198 math
.randomseed(seed
)
200 perlin1
= minetest
.get_perlin(perl1
.SEED1
, perl1
.OCTA1
, perl1
.PERS1
, perl1
.SCAL1
)
202 local noise1
= perlin1
:get_2d({x
=minp
.x
,y
=minp
.y
})--,z=minp.z})
204 if noise1
> 0.25 or noise1
< -0.26 then
205 local mpos
= {x
=math
.random(minp
.x
,maxp
.x
), y
=math
.random(minp
.y
,maxp
.y
), z
=math
.random(minp
.z
,maxp
.z
)}
207 local sands
= {"default:sand", "default:desert_sand"}
216 psand
[s
] = minetest
.find_node_near(mpos
, 25, sand
)
217 while psand
== nil and cnt
< 5 do
219 mpos
= {x
=math
.random(minp
.x
,maxp
.x
), y
=math
.random(minp
.y
,maxp
.y
), z
=math
.random(minp
.z
,maxp
.z
)}
220 psand
[s
] = minetest
.find_node_near(mpos
, 25, sand
)
222 if psand
[s
] ~= nil then
223 if cnt
< cnt_min
then
229 if p2
== nil then return end
230 if p2
.y
< 0 then return end
233 local opos1
= {x
=p2
.x
+22,y
=p2
.y
-1,z
=p2
.z
+22}
234 local opos2
= {x
=p2
.x
+22,y
=p2
.y
-1,z
=p2
.z
}
235 local opos3
= {x
=p2
.x
,y
=p2
.y
-1,z
=p2
.z
+22}
236 local opos1_n
= minetest
.get_node_or_nil(opos1
)
237 local opos2_n
= minetest
.get_node_or_nil(opos2
)
238 local opos3_n
= minetest
.get_node_or_nil(opos3
)
239 if opos1_n
and opos1_n
.name
and opos1_n
.name
== "air" then
240 p2
= ground(opos1
, p2
)
242 if opos2_n
and opos2_n
.name
and opos2_n
.name
== "air" then
243 p2
= ground(opos2
, p2
)
245 if opos3_n
and opos3_n
.name
and opos3_n
.name
== "air" then
246 p2
= ground(opos3
, p2
)
249 if p2
.y
< 0 then p2
.y
= 0 end
250 if minetest
.find_node_near(p2
, 25, {"default:water_source"}) ~= nil or
251 minetest
.find_node_near(p2
, 22, {"default:dirt_with_grass"}) ~= nil or
252 minetest
.find_node_near(p2
, 52, {"default:sandstonebrick"}) ~= nil or
253 minetest
.find_node_near(p2
, 52, {"default:desert_sandstone_brick"}) ~= nil then
257 if math
.random(0,10) > 7 then
260 if (mg_name
== "v6" and math
.random(1, 2) == 1) then
261 sand
= "default:sand"
263 if sand
== "default:desert_sand" then
264 -- Desert sandstone pyramid
265 minetest
.after(0.8, make
, p2
, "default:desert_sandstone_brick", "default:desert_sandstone", "default:desert_stone", "default:desert_sand", "desert_sandstone")
268 minetest
.after(0.8, make
, p2
, "default:sandstonebrick", "default:sandstone", "default:sandstone", "default:sand", "sandstone")
273 -- Add backwards-compability for nodes from the original pyramids mod
274 if minetest
.get_modpath("pyramids") == nil then
276 minetest
.register_alias("pyramids:trap", "tsm_pyramids:trap")
277 minetest
.register_alias("pyramids:trap_2", "tsm_pyramids:trap_2")
278 minetest
.register_alias("pyramids:deco_stone1", "tsm_pyramids:deco_stone1")
279 minetest
.register_alias("pyramids:deco_stone2", "tsm_pyramids:deco_stone2")
280 minetest
.register_alias("pyramids:deco_stone3", "tsm_pyramids:deco_stone3")
281 minetest
.register_alias("pyramids:spawner_mummy", "tsm_pyramids:spawner_mummy")
283 -- FIXME: Entities are currently NOT backwards-compatible
284 -- TODO: Update README when full backwards-compability is achieved
287 minetest
.register_chatcommand("spawnpyramid", {
288 description
= S("Generate a pyramid"),
289 params
= S("[<room_type>]"),
290 privs
= { server
= true },
291 func
= function(name
, param
)
292 local player
= minetest
.get_player_by_name(name
)
294 return false, S("No player.")
296 local pos
= player
:get_pos()
297 pos
= vector
.round(pos
)
298 local s
= math
.random(1,3)
299 local r
= tonumber(param
)
305 pos
= vector
.add(pos
, {x
=-11, y
=-1, z
=0})
308 ok
, msg
= make(pos
, "default:sandstonebrick", "default:sandstone", "default:sandstone", "default:sand", "sandstone", room_id
)
310 ok
, msg
= make(pos
, "default:desert_sandstone_brick", "default:desert_sandstone", "default:desert_stone", "default:desert_sand", "desert_sandstone", room_id
)
312 ok
, msg
= make(pos
, "default:desert_stonebrick", "default:desert_stone_block", "default:desert_stone", "default:desert_sand", "desert_stone", room_id
)
315 return true, S("Pyramid generated at @1.", minetest
.pos_to_string(pos
))