commit b26908f7475a174b6c27c8a20fb559bd379ca6d2 Author: Wuzzy Date: Thu Aug 11 17:47:02 2016 +0200 Initial commit diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..99d02f1 --- /dev/null +++ b/depends.txt @@ -0,0 +1,2 @@ +treasurer +intllib? diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..d6ba129 --- /dev/null +++ b/description.txt @@ -0,0 +1 @@ +Randomly spawns surprise blocks closely about ground level. When mined, those blocks drop random low-grade treasures. diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..403ce24 --- /dev/null +++ b/init.lua @@ -0,0 +1,81 @@ +--[[ + 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) diff --git a/locale/de.txt b/locale/de.txt new file mode 100644 index 0000000..823db4c --- /dev/null +++ b/locale/de.txt @@ -0,0 +1 @@ +Surprise block=Überraschungsblock diff --git a/locale/template.txt b/locale/template.txt new file mode 100644 index 0000000..a636229 --- /dev/null +++ b/locale/template.txt @@ -0,0 +1 @@ +Surprise block diff --git a/nodes.lua b/nodes.lua new file mode 100644 index 0000000..082411f --- /dev/null +++ b/nodes.lua @@ -0,0 +1,49 @@ +--[[ + Register the question mark node +]] + +do + local nodedef = { + description = S("Surprise block"), + tiles = { { name = "tsm_surprise_question_anim.png", animation = { + type = "vertical_frames", aspect_w=16, aspect_h=16, length=2.0 } } }, + drop = "", + groups = { cracky=3, }, + after_destruct = function (pos, oldnode) + local drops = treasurer.select_random_treasures(1,0,3) + for _,item in ipairs(drops) do + local count, name + if type(item) == "string" then + name, count = item:match("^([a-zA-Z0-9_:]*) ([0-9]*)$") + if not name then + name = item + end + if not count then + count = 1 + end + else + count = item:get_count() + name = item:get_name() + end + if not inv or not inv:contains_item("main", ItemStack(name)) then + for i=1,count do + local obj = minetest.env:add_item(pos, name) + if obj ~= nil then + obj:get_luaentity().collect = true + local x = math.random(1, 5) + if math.random(1,2) == 1 then + x = -x + end + local z = math.random(1, 5) + if math.random(1,2) == 1 then + z = -z + end + obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z}) + end + end + end + end + end, + } + minetest.register_node("tsm_surprise:question",nodedef) +end diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..69c62f3 Binary files /dev/null and b/screenshot.png differ diff --git a/textures/tsm_surprise_question_anim.png b/textures/tsm_surprise_question_anim.png new file mode 100644 index 0000000..84c88c9 Binary files /dev/null and b/textures/tsm_surprise_question_anim.png differ diff --git a/textures/tsm_surprise_question_noanim.png b/textures/tsm_surprise_question_noanim.png new file mode 100644 index 0000000..ba75b0c Binary files /dev/null and b/textures/tsm_surprise_question_noanim.png differ diff --git a/textures/tsm_surprise_question_used.png b/textures/tsm_surprise_question_used.png new file mode 100644 index 0000000..de76f85 Binary files /dev/null and b/textures/tsm_surprise_question_used.png differ