184 lines
4.0 KiB
Lua
184 lines
4.0 KiB
Lua
-----------------
|
|
-- Decorations --
|
|
-----------------
|
|
|
|
-- The main decoration handler, through the game's decoration manager.
|
|
|
|
|
|
-- A list of all schematics, for re-use.
|
|
loud_walking.schematics = {}
|
|
|
|
function table.contains_substring(t, s)
|
|
if type(s) ~= "string" then
|
|
return nil
|
|
end
|
|
|
|
for key, value in pairs(t) do
|
|
if type(value) == 'string' and s:find(value) then
|
|
if key then
|
|
return key
|
|
else
|
|
return true
|
|
end
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
|
|
|
|
-- Copy all the decorations except the ones I don't like.
|
|
loud_walking.decorations = {}
|
|
local bad_deco = {}
|
|
for _, i in pairs({"apple_tree", "pine_tree", "jungle_tree", "acacia_tree", "aspen_tree", }) do
|
|
bad_deco[i] = true
|
|
end
|
|
|
|
do
|
|
for _, odeco in pairs(minetest.registered_decorations) do
|
|
if not bad_deco[odeco.schematic] then
|
|
local deco = {}
|
|
if odeco.biomes then
|
|
deco.biomes = {}
|
|
for _, b in pairs(odeco.biomes) do
|
|
deco.biomes[b] = true
|
|
end
|
|
end
|
|
|
|
deco.deco_type = odeco.deco_type
|
|
deco.decoration = odeco.decoration
|
|
deco.schematic = odeco.schematic
|
|
deco.fill_ratio = odeco.fill_ratio
|
|
|
|
if odeco.noise_params then
|
|
deco.fill_ratio = math.max(0.001, odeco.noise_params.scale + odeco.noise_params.offset)
|
|
end
|
|
|
|
local nod = minetest.registered_nodes[deco.decoration]
|
|
if nod and nod.groups and nod.groups.flower then
|
|
deco.flower = true
|
|
end
|
|
|
|
loud_walking.decorations[#loud_walking.decorations+1] = deco
|
|
end
|
|
end
|
|
end
|
|
|
|
minetest.clear_registered_decorations()
|
|
|
|
-- Create and initialize a table for a schematic.
|
|
function loud_walking.schematic_array(width, height, depth)
|
|
-- Dimensions of data array.
|
|
local s = {size={x=width, y=height, z=depth}}
|
|
s.data = {}
|
|
|
|
for z = 0,depth-1 do
|
|
for y = 0,height-1 do
|
|
for x = 0,width-1 do
|
|
local i = z*width*height + y*width + x + 1
|
|
s.data[i] = {}
|
|
s.data[i].name = "air"
|
|
s.data[i].param1 = 000
|
|
end
|
|
end
|
|
end
|
|
|
|
s.yslice_prob = {}
|
|
|
|
return s
|
|
end
|
|
|
|
|
|
dofile(loud_walking.path.."/deco_trees.lua")
|
|
|
|
|
|
local function register_flower(name, desc, biomes, chance)
|
|
local groups = {}
|
|
groups.snappy = 3
|
|
groups.flammable = 2
|
|
groups.flower = 1
|
|
groups.flora = 1
|
|
groups.attached_node = 1
|
|
|
|
minetest.register_node("loud_walking:" .. name, {
|
|
description = desc,
|
|
drawtype = "plantlike",
|
|
waving = 1,
|
|
tiles = {"loud_walking_" .. name .. ".png"},
|
|
inventory_image = "loud_walking_" .. name .. ".png",
|
|
wield_image = "flowers_" .. name .. ".png",
|
|
sunlight_propagates = true,
|
|
paramtype = "light",
|
|
walkable = false,
|
|
buildable_to = true,
|
|
stack_max = 99,
|
|
groups = groups,
|
|
sounds = default.node_sound_leaves_defaults(),
|
|
selection_box = {
|
|
type = "fixed",
|
|
fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
|
|
}
|
|
})
|
|
|
|
local bi = {}
|
|
if biomes then
|
|
bi = {}
|
|
for _, b in pairs(biomes) do
|
|
bi[b] = true
|
|
end
|
|
end
|
|
|
|
loud_walking.decorations[#loud_walking.decorations+1] = {
|
|
deco_type = "simple",
|
|
place_on = {"default:dirt_with_grass"},
|
|
biomes = bi,
|
|
fill_ratio = chance,
|
|
flower = true,
|
|
decoration = "loud_walking:"..name,
|
|
}
|
|
end
|
|
|
|
register_flower("orchid", "Orchid", {"rainforest", "rainforest_swamp"}, 0.025)
|
|
register_flower("bird_of_paradise", "Bird of Paradise", {"rainforest", "desertstone_grassland"}, 0.025)
|
|
register_flower("gerbera", "Gerbera", {"savanna", "rainforest", "desertstone_grassland"}, 0.005)
|
|
|
|
|
|
local function register_decoration(deco, place_on, biomes, chance)
|
|
local bi = {}
|
|
if biomes then
|
|
bi = {}
|
|
for _, b in pairs(biomes) do
|
|
bi[b] = true
|
|
end
|
|
end
|
|
|
|
loud_walking.decorations[#loud_walking.decorations+1] = {
|
|
deco_type = "simple",
|
|
place_on = place_on,
|
|
biomes = bi,
|
|
fill_ratio = chance,
|
|
decoration = deco,
|
|
}
|
|
end
|
|
|
|
if crops then
|
|
register_decoration(
|
|
"crops:pumpkin_plant_4",
|
|
{ "default:dirt_with_grass" },
|
|
{"stone_grassland", "sandstone_grassland", "deciduous_forest",
|
|
"coniferous_forest"},
|
|
0.002
|
|
)
|
|
register_decoration(
|
|
"crops:melon_plant_4",
|
|
{ "default:dirt_with_grass" },
|
|
{"deciduous_forest", "coniferous_forest", "tundra"},
|
|
0.002
|
|
)
|
|
register_decoration(
|
|
"crops:tomato_plant_4",
|
|
{ "default:dirt_with_grass" },
|
|
{"rainforest"},
|
|
0.002
|
|
)
|
|
end
|