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")
10 {name
="default:apple", max = 3},
11 {name
="default:steel_ingot", max = 3},
12 {name
="default:copper_ingot", max = 3},
13 {name
="default:gold_ingot", max = 2},
14 {name
="default:diamond", max = 1},
15 {name
="default:pick_steel", max = 1},
16 {name
="default:pick_diamond", max = 1},
17 {name
="default:papyrus", max = 9},
20 if minetest
.get_modpath("farming") then
21 table.insert(chest_stuff
, {name
="farming:bread", max = 3})
22 table.insert(chest_stuff
, {name
="farming:cotton", max = 8})
24 table.insert(chest_stuff
, {name
="farming:apple", max = 8})
25 table.insert(chest_stuff
, {name
="farming:apple", max = 3})
27 if minetest
.get_modpath("tnt") then
28 table.insert(chest_stuff
, {name
="tnt:gunpowder", max = 6})
30 table.insert(chest_stuff
, {name
="farming:apple", max = 3})
33 function tsm_pyramids
.fill_chest(pos
, stype
, flood_sand
)
34 minetest
.after(2, function()
35 local sand
= "default:sand"
36 if stype
== "desert" then
37 sand
= "default:desert_sand"
39 local n
= minetest
.get_node(pos
)
40 if n
and n
.name
and n
.name
== "default:chest" then
41 local meta
= minetest
.get_meta(pos
)
42 local inv
= meta
:get_inventory()
43 inv
:set_size("main", 8*4)
45 -- Fill with sand in sand-flooded pyramids
47 table.insert(stacks
, {name
=sand
, count
= math
.random(1,32)})
50 if math
.random(1,10) >= 7 then
51 if minetest
.get_modpath("treasurer") ~= nil then
52 stacks
= treasurer
.select_random_treasures(3,7,9,{"minetool", "food", "crafting_component"})
55 local stuff
= chest_stuff
[math
.random(1,#chest_stuff
)]
56 table.insert(stacks
, {name
=stuff
.name
, count
= math
.random(1,stuff
.max)})
61 if not inv
:contains_item("main", stacks
[s
]) then
62 inv
:set_stack("main", math
.random(1,32), stacks
[s
])
70 local function add_spawner(pos
)
71 minetest
.set_node(pos
, {name
="tsm_pyramids:spawner_mummy"})
72 if not minetest
.settings
:get_bool("only_peaceful_mobs") then tsm_pyramids
.spawn_mummy({x
=pos
.x
,y
=pos
.y
,z
=pos
.z
-2},2) end
75 local function can_replace(pos
)
76 local n
= minetest
.get_node_or_nil(pos
)
77 if n
and n
.name
and minetest
.registered_nodes
[n
.name
] and not minetest
.registered_nodes
[n
.name
].walkable
then
86 local function underground(pos
, stone
, sand
)
91 while can_replace(p2
)==true do
93 if cnt
> 25 then break end
94 if cnt
>math
.random(2,4) then mat
= stone
end
95 minetest
.set_node(p2
, {name
=mat
})
100 local function make_entrance(pos
, brick
, sand
, flood_sand
)
101 local gang
= {x
=pos
.x
+10,y
=pos
.y
, z
=pos
.z
}
102 local max_sand_height
= math
.random(1,3)
104 local sand_height
= math
.random(1,max_sand_height
)
106 if flood_sand
and iy
<= sand_height
and iz
>= 3 then
107 minetest
.set_node({x
=gang
.x
+1,y
=gang
.y
+iy
,z
=gang
.z
+iz
}, {name
=sand
})
109 minetest
.remove_node({x
=gang
.x
+1,y
=gang
.y
+iy
,z
=gang
.z
+iz
})
111 if iz
>=3 and iy
== 3 then
112 minetest
.set_node({x
=gang
.x
,y
=gang
.y
+iy
+1,z
=gang
.z
+iz
}, {name
=brick
})
113 minetest
.set_node({x
=gang
.x
+1,y
=gang
.y
+iy
+1,z
=gang
.z
+iz
}, {name
=brick
})
114 minetest
.set_node({x
=gang
.x
+2,y
=gang
.y
+iy
+1,z
=gang
.z
+iz
}, {name
=brick
})
120 local function make(pos
, brick
, sandstone
, stone
, sand
, ptype
, room_id
)
124 if iy
<1 then underground({x
=pos
.x
+ix
,y
=pos
.y
,z
=pos
.z
+iz
}, stone
, sand
) end
125 minetest
.set_node({x
=pos
.x
+ix
,y
=pos
.y
+iy
,z
=pos
.z
+iz
}, {name
=brick
})
127 local n
= minetest
.get_node({x
=pos
.x
+ix
,y
=pos
.y
+iy
+yy
,z
=pos
.z
+iz
})
128 if n
and n
.name
and n
.name
== stone
then
129 minetest
.set_node({x
=pos
.x
+ix
,y
=pos
.y
+iy
+yy
,z
=pos
.z
+iz
},{name
=sand
})
135 local ok
, msg
, flood_sand
= tsm_pyramids
.make_room(pos
, ptype
, room_id
)
136 add_spawner({x
=pos
.x
+11,y
=pos
.y
+2, z
=pos
.z
+17})
137 make_entrance({x
=pos
.x
,y
=pos
.y
, z
=pos
.z
}, brick
, sand
, flood_sand
)
138 minetest
.log("action", "Created pyramid at ("..pos
.x
..","..pos
.y
..","..pos
.z
..")")
142 local perl1
= {SEED1
= 9130, OCTA1
= 3, PERS1
= 0.5, SCAL1
= 250} -- Values should match minetest mapgen V6 desert noise.
145 local function hlp_fnct(pos
, name
)
146 local n
= minetest
.get_node_or_nil(pos
)
147 if n
and n
.name
and n
.name
== name
then
153 local function ground(pos
, old
)
155 while hlp_fnct(p2
, "air") do
166 minetest
.register_on_generated(function(minp
, maxp
, seed
)
167 if maxp
.y
< 0 then return end
168 math
.randomseed(seed
)
171 perlin1
= minetest
.get_perlin(perl1
.SEED1
, perl1
.OCTA1
, perl1
.PERS1
, perl1
.SCAL1
)
173 local noise1
= perlin1
:get_2d({x
=minp
.x
,y
=minp
.y
})--,z=minp.z})
175 if noise1
> 0.25 or noise1
< -0.26 then
176 local mpos
= {x
=math
.random(minp
.x
,maxp
.x
), y
=math
.random(minp
.y
,maxp
.y
), z
=math
.random(minp
.z
,maxp
.z
)}
178 local sands
= {"default:desert_sand", "default:sand"}
183 p2
= minetest
.find_node_near(mpos
, 25, sand
)
184 while p2
== nil and cnt
< 5 do
186 mpos
= {x
=math
.random(minp
.x
,maxp
.x
), y
=math
.random(minp
.y
,maxp
.y
), z
=math
.random(minp
.z
,maxp
.z
)}
187 p2
= minetest
.find_node_near(mpos
, 25, sand
)
193 if p2
== nil then return end
194 if p2
.y
< 0 then return end
197 local opos1
= {x
=p2
.x
+22,y
=p2
.y
-1,z
=p2
.z
+22}
198 local opos2
= {x
=p2
.x
+22,y
=p2
.y
-1,z
=p2
.z
}
199 local opos3
= {x
=p2
.x
,y
=p2
.y
-1,z
=p2
.z
+22}
200 local opos1_n
= minetest
.get_node_or_nil(opos1
)
201 local opos2_n
= minetest
.get_node_or_nil(opos2
)
202 local opos3_n
= minetest
.get_node_or_nil(opos3
)
203 if opos1_n
and opos1_n
.name
and opos1_n
.name
== "air" then
204 p2
= ground(opos1
, p2
)
206 if opos2_n
and opos2_n
.name
and opos2_n
.name
== "air" then
207 p2
= ground(opos2
, p2
)
209 if opos3_n
and opos3_n
.name
and opos3_n
.name
== "air" then
210 p2
= ground(opos3
, p2
)
213 if p2
.y
< 0 then p2
.y
= 0 end
214 if minetest
.find_node_near(p2
, 25, {"default:water_source"}) ~= nil or
215 minetest
.find_node_near(p2
, 22, {"default:dirt_with_grass"}) ~= nil or
216 minetest
.find_node_near(p2
, 52, {"default:sandstonebrick"}) ~= nil or
217 minetest
.find_node_near(p2
, 52, {"default:desert_sandstone_brick"}) ~= nil then
221 if math
.random(0,10) > 7 then
224 if sand
== "default:desert_sand" then
225 minetest
.after(0.8, make
, p2
, "default:desert_sandstone_brick", "default:desert_sandstone", "default:desert_stone", "default:desert_sand", "desert")
227 minetest
.after(0.8, make
, p2
, "default:sandstonebrick", "default:sandstone", "default:sandstone", "default:sand", "sandstone")
232 -- Add backwards-compability for nodes from the original pyramids mod
233 if minetest
.get_modpath("pyramids") == nil then
235 minetest
.register_alias("pyramids:trap", "tsm_pyramids:trap")
236 minetest
.register_alias("pyramids:trap_2", "tsm_pyramids:trap_2")
237 minetest
.register_alias("pyramids:deco_stone1", "tsm_pyramids:deco_stone1")
238 minetest
.register_alias("pyramids:deco_stone2", "tsm_pyramids:deco_stone2")
239 minetest
.register_alias("pyramids:deco_stone3", "tsm_pyramids:deco_stone3")
240 minetest
.register_alias("pyramids:spawner_mummy", "tsm_pyramids:spawner_mummy")
242 -- FIXME: Entities are currently NOT backwards-compatible
243 -- TODO: Update README when full backwards-compability is achieved
246 minetest
.register_chatcommand("spawnpyramid", {
247 description
= S("Generate a pyramid"),
248 params
= S("[<room_type>]"),
249 privs
= { server
= true },
250 func
= function(name
, param
)
251 local player
= minetest
.get_player_by_name(name
)
253 return false, S("No player.")
255 local pos
= player
:get_pos()
256 pos
= vector
.round(pos
)
257 local s
= math
.random(1,2)
258 local r
= tonumber(param
)
265 ok
, msg
= make(pos
, "default:sandstonebrick", "default:sandstone", "default:sandstone", "default:sand", "sandstone", room_id
)
267 ok
, msg
= make(pos
, "default:desert_sandstone_brick", "default:desert_sandstone", "default:desert_stone", "default:desert_sand", "desert", room_id
)
270 return true, S("Pyramid generated at @1.", minetest
.pos_to_string(pos
))