--[[ TSM: Surprise blocks This mod adds surprise blocks to Minetest. When destroyed, they drop one or more random items. The item is selected with the “treasurer” mod. Therefore, this is a treasure spawning mod. You also need to install at least one treasure registraton mod, otherwise, the questinon mark blocks stay empty. Refer to the documentation of the “treasurer” mod to learn more. ]] local S if (minetest.get_modpath("intllib")) then dofile(minetest.get_modpath("intllib").."/intllib.lua") S = intllib.Getter(minetest.get_current_modname()) else S = function ( s ) return s end end dofile(minetest.get_modpath("tsm_surprise").."/nodes.lua") --[[ here are some configuration variables ]] local blocks_per_chunk = 1 -- number of blocks per chunk. local height_min = -30000 -- minimum spawning height local height_max = 30000 -- maximum spawning height local height_above_ground = 4 -- generation code minetest.register_on_generated(function(minp, maxp, seed) -- get the water level and convert it to a number local water_level = minetest.setting_get("water_level") if water_level == nil or type(water_level) ~= "number" then water_level = 1 else water_level = tonumber(water_level) end if(maxp.y < height_min or minp.y > height_max) then return end local y_min = math.max(minp.y, height_min) local y_max = math.min(maxp.y, height_max) for i=1, blocks_per_chunk do local pos = {x=math.random(minp.x,maxp.x),z=math.random(minp.z,maxp.z), y=minp.y} local env = minetest.env -- Find ground level local ground = nil local top = y_max if env:get_node({x=pos.x,y=y_max,z=pos.z}).name ~= "air" then for y=y_max,y_min,-1 do local p = {x=pos.x,y=y,z=pos.z} if env:get_node(p).name == "air" then top = y break end end end for y=top,y_min,-1 do local p = {x=pos.x,y=y,z=pos.z} if env:get_node(p).name ~= "air" then ground = y break end end if(ground~=nil) then local block_pos = {x=pos.x,y=ground+height_above_ground, z=pos.z} local nn = minetest.get_node(block_pos).name if nn == "air" then -- Place the question mark block local block = {} block.name = "tsm_surprise:question" minetest.set_node(block_pos, block) end end end end)