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" 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
, rot
, brick
, sand
, flood_sand
)
103 local roffset_arr
= {
104 { x
=0, y
=0, z
=1 }, -- front
105 { x
=-1, y
=0, z
=0 }, -- left
106 { x
=0, y
=0, z
=-1 }, -- back
107 { x
=1, y
=0, z
=0 }, -- right
109 local roffset
= roffset_arr
[rot
+ 1]
112 way
= vector
.add(pos
, {x
=11, y
=0, z
=0})
114 way
= vector
.add(pos
, {x
=22, y
=0, z
=11})
116 way
= vector
.add(pos
, {x
=11, y
=0, z
=22})
118 way
= vector
.add(pos
, {x
=0, y
=0, z
=11})
120 local max_sand_height
= math
.random(1,3)
122 local sand_height
= math
.random(1,max_sand_height
)
125 local way_dir
= vector
.add(vector
.add(way
, {x
=0,y
=iy
,z
=0}), vector
.multiply(roffset
, ie
))
126 if flood_sand
and iy
<= sand_height
and ie
>= 3 then
127 minetest
.set_node(way_dir
, {name
=sand
})
129 minetest
.remove_node(way_dir
)
131 -- build decoration above entrance
132 if ie
>=3 and iy
== 3 then
133 local deco
= {x
=way_dir
.x
, y
=way_dir
.y
+1,z
=way_dir
.z
}
134 minetest
.set_node(deco
, {name
=brick
})
135 if rot
== 0 or rot
== 2 then
136 minetest
.set_node(vector
.add(deco
, {x
=-1, y
=0, z
=0}), {name
=brick
})
137 minetest
.set_node(vector
.add(deco
, {x
=1, y
=0, z
=0}), {name
=brick
})
139 minetest
.set_node(vector
.add(deco
, {x
=0, y
=0, z
=-1}), {name
=brick
})
140 minetest
.set_node(vector
.add(deco
, {x
=0, y
=0, z
=1}), {name
=brick
})
147 local function make_pyramid(pos
, brick
, sandstone
, stone
, sand
)
148 local set_to_brick
= {}
149 local set_to_sand
= {}
150 local set_to_stone
= {}
152 for iy
=0,math
.random(10,11),1 do
156 make_foundation_part({x
=pos
.x
+ix
,y
=pos
.y
,z
=pos
.z
+iz
}, set_to_stone
)
158 table.insert(set_to_brick
, {x
=pos
.x
+ix
,y
=pos
.y
+iy
,z
=pos
.z
+iz
})
160 local n
= minetest
.get_node({x
=pos
.x
+ix
,y
=pos
.y
+iy
+yy
,z
=pos
.z
+iz
})
161 if n
and n
.name
and n
.name
== stone
then
162 table.insert(set_to_sand
, {x
=pos
.x
+ix
,y
=pos
.y
+iy
+yy
,z
=pos
.z
+iz
})
168 minetest
.bulk_set_node(set_to_stone
, {name
=stone
})
169 minetest
.bulk_set_node(set_to_brick
, {name
=brick
})
170 minetest
.bulk_set_node(set_to_sand
, {name
=sand
})
173 local function make(pos
, brick
, sandstone
, stone
, sand
, ptype
, room_id
)
175 make_pyramid(pos
, brick
, sandstone
, stone
, sand
)
177 local rot
= math
.random(0, 3)
179 local ok
, msg
, flood_sand
= tsm_pyramids
.make_room(pos
, ptype
, room_id
, rot
)
180 -- Place mummy spawner
181 local r
= math
.random(1,3)
182 -- 4 possible spawner positions
183 local spawner_posses
= {
185 {{x
=pos
.x
+11,y
=pos
.y
+2, z
=pos
.z
+5}, {x
=0, y
=0, z
=2}},
187 {{x
=pos
.x
+17,y
=pos
.y
+2, z
=pos
.z
+11}, {x
=-2, y
=0, z
=0}},
189 {{x
=pos
.x
+11,y
=pos
.y
+2, z
=pos
.z
+17}, {x
=0, y
=0, z
=-2}},
191 {{x
=pos
.x
+5,y
=pos
.y
+2, z
=pos
.z
+11}, {x
=2, y
=0, z
=0}},
193 -- Delete the spawner position in which the entrance will be placed
194 table.remove(spawner_posses
, (rot
% 4) + 1)
195 add_spawner(spawner_posses
[r
][1], spawner_posses
[r
][2])
197 make_entrance(pos
, rot
, brick
, sand
, flood_sand
)
199 minetest
.log("action", "Created pyramid at ("..pos
.x
..","..pos
.y
..","..pos
.z
..")")
203 local perl1
= {SEED1
= 9130, OCTA1
= 3, PERS1
= 0.5, SCAL1
= 250} -- Values should match minetest mapgen V6 desert noise.
206 local function hlp_fnct(pos
, name
)
207 local n
= minetest
.get_node_or_nil(pos
)
208 if n
and n
.name
and n
.name
== name
then
214 local function ground(pos
, old
)
216 while hlp_fnct(p2
, "air") do
227 minetest
.register_on_generated(function(minp
, maxp
, seed
)
228 if maxp
.y
< 0 then return end
229 math
.randomseed(seed
)
231 perlin1
= minetest
.get_perlin(perl1
.SEED1
, perl1
.OCTA1
, perl1
.PERS1
, perl1
.SCAL1
)
233 local noise1
= perlin1
:get_2d({x
=minp
.x
,y
=minp
.y
})--,z=minp.z})
235 if noise1
> 0.25 or noise1
< -0.26 then
236 local mpos
= {x
=math
.random(minp
.x
,maxp
.x
), y
=math
.random(minp
.y
,maxp
.y
), z
=math
.random(minp
.z
,maxp
.z
)}
238 local sands
= {"default:sand", "default:desert_sand"}
247 psand
[s
] = minetest
.find_node_near(mpos
, 25, sand
)
248 while psand
== nil and cnt
< 5 do
250 mpos
= {x
=math
.random(minp
.x
,maxp
.x
), y
=math
.random(minp
.y
,maxp
.y
), z
=math
.random(minp
.z
,maxp
.z
)}
251 psand
[s
] = minetest
.find_node_near(mpos
, 25, sand
)
253 if psand
[s
] ~= nil then
254 if cnt
< cnt_min
then
260 if p2
== nil then return end
261 if p2
.y
< 0 then return end
264 local opos1
= {x
=p2
.x
+22,y
=p2
.y
-1,z
=p2
.z
+22}
265 local opos2
= {x
=p2
.x
+22,y
=p2
.y
-1,z
=p2
.z
}
266 local opos3
= {x
=p2
.x
,y
=p2
.y
-1,z
=p2
.z
+22}
267 local opos1_n
= minetest
.get_node_or_nil(opos1
)
268 local opos2_n
= minetest
.get_node_or_nil(opos2
)
269 local opos3_n
= minetest
.get_node_or_nil(opos3
)
270 if opos1_n
and opos1_n
.name
and opos1_n
.name
== "air" then
271 p2
= ground(opos1
, p2
)
273 if opos2_n
and opos2_n
.name
and opos2_n
.name
== "air" then
274 p2
= ground(opos2
, p2
)
276 if opos3_n
and opos3_n
.name
and opos3_n
.name
== "air" then
277 p2
= ground(opos3
, p2
)
280 if p2
.y
< 0 then p2
.y
= 0 end
281 if minetest
.find_node_near(p2
, 25, {"default:water_source"}) ~= nil or
282 minetest
.find_node_near(p2
, 22, {"default:dirt_with_grass"}) ~= nil or
283 minetest
.find_node_near(p2
, 52, {"default:sandstonebrick"}) ~= nil or
284 minetest
.find_node_near(p2
, 52, {"default:desert_sandstone_brick"}) ~= nil then
288 if math
.random(0,10) > 7 then
291 if (mg_name
== "v6" and math
.random(1, 2) == 1) then
292 sand
= "default:sand"
294 if sand
== "default:desert_sand" then
295 -- Desert sandstone pyramid
296 minetest
.after(0.8, make
, p2
, "default:desert_sandstone_brick", "default:desert_sandstone", "default:desert_stone", "default:desert_sand", "desert")
299 minetest
.after(0.8, make
, p2
, "default:sandstonebrick", "default:sandstone", "default:sandstone", "default:sand", "sandstone")
304 -- Add backwards-compability for nodes from the original pyramids mod
305 if minetest
.get_modpath("pyramids") == nil then
307 minetest
.register_alias("pyramids:trap", "tsm_pyramids:trap")
308 minetest
.register_alias("pyramids:trap_2", "tsm_pyramids:trap_2")
309 minetest
.register_alias("pyramids:deco_stone1", "tsm_pyramids:deco_stone1")
310 minetest
.register_alias("pyramids:deco_stone2", "tsm_pyramids:deco_stone2")
311 minetest
.register_alias("pyramids:deco_stone3", "tsm_pyramids:deco_stone3")
312 minetest
.register_alias("pyramids:spawner_mummy", "tsm_pyramids:spawner_mummy")
314 -- FIXME: Entities are currently NOT backwards-compatible
315 -- TODO: Update README when full backwards-compability is achieved
318 minetest
.register_chatcommand("spawnpyramid", {
319 description
= S("Generate a pyramid"),
320 params
= S("[<room_type>]"),
321 privs
= { server
= true },
322 func
= function(name
, param
)
323 local player
= minetest
.get_player_by_name(name
)
325 return false, S("No player.")
327 local pos
= player
:get_pos()
328 pos
= vector
.round(pos
)
329 local s
= math
.random(1,2)
330 local r
= tonumber(param
)
336 pos
= vector
.add(pos
, {x
=-11, y
=-1, z
=0})
338 ok
, msg
= make(pos
, "default:sandstonebrick", "default:sandstone", "default:sandstone", "default:sand", "sandstone", room_id
)
340 ok
, msg
= make(pos
, "default:desert_sandstone_brick", "default:desert_sandstone", "default:desert_stone", "default:desert_sand", "desert", room_id
)
343 return true, S("Pyramid generated at @1.", minetest
.pos_to_string(pos
))