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 local r
= math
.random(1,3)
138 add_spawner({x
=pos
.x
+11,y
=pos
.y
+2, z
=pos
.z
+17})
140 add_spawner({x
=pos
.x
+17,y
=pos
.y
+2, z
=pos
.z
+11})
142 add_spawner({x
=pos
.x
+5,y
=pos
.y
+2, z
=pos
.z
+11})
144 make_entrance({x
=pos
.x
,y
=pos
.y
, z
=pos
.z
}, brick
, sand
, flood_sand
)
145 minetest
.log("action", "Created pyramid at ("..pos
.x
..","..pos
.y
..","..pos
.z
..")")
149 local perl1
= {SEED1
= 9130, OCTA1
= 3, PERS1
= 0.5, SCAL1
= 250} -- Values should match minetest mapgen V6 desert noise.
152 local function hlp_fnct(pos
, name
)
153 local n
= minetest
.get_node_or_nil(pos
)
154 if n
and n
.name
and n
.name
== name
then
160 local function ground(pos
, old
)
162 while hlp_fnct(p2
, "air") do
173 minetest
.register_on_generated(function(minp
, maxp
, seed
)
174 if maxp
.y
< 0 then return end
175 math
.randomseed(seed
)
178 perlin1
= minetest
.get_perlin(perl1
.SEED1
, perl1
.OCTA1
, perl1
.PERS1
, perl1
.SCAL1
)
180 local noise1
= perlin1
:get_2d({x
=minp
.x
,y
=minp
.y
})--,z=minp.z})
182 if noise1
> 0.25 or noise1
< -0.26 then
183 local mpos
= {x
=math
.random(minp
.x
,maxp
.x
), y
=math
.random(minp
.y
,maxp
.y
), z
=math
.random(minp
.z
,maxp
.z
)}
185 local sands
= {"default:desert_sand", "default:sand"}
190 p2
= minetest
.find_node_near(mpos
, 25, sand
)
191 while p2
== nil and cnt
< 5 do
193 mpos
= {x
=math
.random(minp
.x
,maxp
.x
), y
=math
.random(minp
.y
,maxp
.y
), z
=math
.random(minp
.z
,maxp
.z
)}
194 p2
= minetest
.find_node_near(mpos
, 25, sand
)
200 if p2
== nil then return end
201 if p2
.y
< 0 then return end
204 local opos1
= {x
=p2
.x
+22,y
=p2
.y
-1,z
=p2
.z
+22}
205 local opos2
= {x
=p2
.x
+22,y
=p2
.y
-1,z
=p2
.z
}
206 local opos3
= {x
=p2
.x
,y
=p2
.y
-1,z
=p2
.z
+22}
207 local opos1_n
= minetest
.get_node_or_nil(opos1
)
208 local opos2_n
= minetest
.get_node_or_nil(opos2
)
209 local opos3_n
= minetest
.get_node_or_nil(opos3
)
210 if opos1_n
and opos1_n
.name
and opos1_n
.name
== "air" then
211 p2
= ground(opos1
, p2
)
213 if opos2_n
and opos2_n
.name
and opos2_n
.name
== "air" then
214 p2
= ground(opos2
, p2
)
216 if opos3_n
and opos3_n
.name
and opos3_n
.name
== "air" then
217 p2
= ground(opos3
, p2
)
220 if p2
.y
< 0 then p2
.y
= 0 end
221 if minetest
.find_node_near(p2
, 25, {"default:water_source"}) ~= nil or
222 minetest
.find_node_near(p2
, 22, {"default:dirt_with_grass"}) ~= nil or
223 minetest
.find_node_near(p2
, 52, {"default:sandstonebrick"}) ~= nil or
224 minetest
.find_node_near(p2
, 52, {"default:desert_sandstone_brick"}) ~= nil then
228 if math
.random(0,10) > 7 then
231 if sand
== "default:desert_sand" then
232 minetest
.after(0.8, make
, p2
, "default:desert_sandstone_brick", "default:desert_sandstone", "default:desert_stone", "default:desert_sand", "desert")
234 minetest
.after(0.8, make
, p2
, "default:sandstonebrick", "default:sandstone", "default:sandstone", "default:sand", "sandstone")
239 -- Add backwards-compability for nodes from the original pyramids mod
240 if minetest
.get_modpath("pyramids") == nil then
242 minetest
.register_alias("pyramids:trap", "tsm_pyramids:trap")
243 minetest
.register_alias("pyramids:trap_2", "tsm_pyramids:trap_2")
244 minetest
.register_alias("pyramids:deco_stone1", "tsm_pyramids:deco_stone1")
245 minetest
.register_alias("pyramids:deco_stone2", "tsm_pyramids:deco_stone2")
246 minetest
.register_alias("pyramids:deco_stone3", "tsm_pyramids:deco_stone3")
247 minetest
.register_alias("pyramids:spawner_mummy", "tsm_pyramids:spawner_mummy")
249 -- FIXME: Entities are currently NOT backwards-compatible
250 -- TODO: Update README when full backwards-compability is achieved
253 minetest
.register_chatcommand("spawnpyramid", {
254 description
= S("Generate a pyramid"),
255 params
= S("[<room_type>]"),
256 privs
= { server
= true },
257 func
= function(name
, param
)
258 local player
= minetest
.get_player_by_name(name
)
260 return false, S("No player.")
262 local pos
= player
:get_pos()
263 pos
= vector
.round(pos
)
264 local s
= math
.random(1,2)
265 local r
= tonumber(param
)
272 ok
, msg
= make(pos
, "default:sandstonebrick", "default:sandstone", "default:sandstone", "default:sand", "sandstone", room_id
)
274 ok
, msg
= make(pos
, "default:desert_sandstone_brick", "default:desert_sandstone", "default:desert_stone", "default:desert_sand", "desert", room_id
)
277 return true, S("Pyramid generated at @1.", minetest
.pos_to_string(pos
))