Initial commit
This commit is contained in:
commit
b26908f747
2
depends.txt
Normal file
2
depends.txt
Normal file
@ -0,0 +1,2 @@
|
||||
treasurer
|
||||
intllib?
|
1
description.txt
Normal file
1
description.txt
Normal file
@ -0,0 +1 @@
|
||||
Randomly spawns surprise blocks closely about ground level. When mined, those blocks drop random low-grade treasures.
|
81
init.lua
Normal file
81
init.lua
Normal file
@ -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)
|
1
locale/de.txt
Normal file
1
locale/de.txt
Normal file
@ -0,0 +1 @@
|
||||
Surprise block=Überraschungsblock
|
1
locale/template.txt
Normal file
1
locale/template.txt
Normal file
@ -0,0 +1 @@
|
||||
Surprise block
|
49
nodes.lua
Normal file
49
nodes.lua
Normal file
@ -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
|
BIN
screenshot.png
Normal file
BIN
screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
BIN
textures/tsm_surprise_question_anim.png
Normal file
BIN
textures/tsm_surprise_question_anim.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
BIN
textures/tsm_surprise_question_noanim.png
Normal file
BIN
textures/tsm_surprise_question_noanim.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 182 B |
BIN
textures/tsm_surprise_question_used.png
Normal file
BIN
textures/tsm_surprise_question_used.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 118 B |
Loading…
x
Reference in New Issue
Block a user