minetest-mm/mods/plantlife_modpack/bushes/init.lua

317 lines
9.2 KiB
Lua
Raw Normal View History

2020-10-26 17:38:53 +01:00
-- Bushes Mod by Mossmanikin, Evergreen, & Neuromancer
-- The initial code for this was taken from Mossmanikin's Grasses Mod,
-- then heavilly modified by Neuromancer for this mod.
-- Mossmanikin also greatly helped with providing samples for coding.
-- bush leaf textures are from VannessaE's moretrees mod.
-- (Leaf texture created by RealBadAngel or VanessaE)
-- Branch textures created by Neuromancer.
-- support for i18n
local S = minetest.get_translator("bushes")
2021-12-27 15:08:16 +01:00
2024-12-19 12:55:40 +01:00
local bush_rarity = minetest.settings:get("bushes.bush_rarity") or 0.008
local youngtree_rarity = minetest.settings:get("youngtree.bush_rarity") or 0.006
2021-12-27 15:08:16 +01:00
minetest.register_node("bushes:youngtree2_bottom", {
2020-10-26 17:38:53 +01:00
description = S("Young Tree 2 (bottom)"),
2021-12-27 15:08:16 +01:00
drawtype="nodebox",
tiles = {"bushes_youngtree2trunk.png"},
2020-10-26 17:38:53 +01:00
inventory_image = "bushes_youngtree2trunk_inv.png",
wield_image = "bushes_youngtree2trunk_inv.png",
2021-12-27 15:08:16 +01:00
paramtype = "light",
2020-10-26 17:38:53 +01:00
walkable = false,
is_ground_content = true,
2021-12-27 15:08:16 +01:00
node_box = {
type = "fixed",
fixed = {
{-0.0612,-0.500000,-0.500000,0.0612,0.500000,-0.375000}, --NodeBox 1
}
},
2021-06-27 17:39:50 +02:00
groups = {snappy=3,flammable=2,attached_node=1},
2020-10-26 17:38:53 +01:00
sounds = default.node_sound_leaves_defaults(),
drop = 'default:stick'
})
2024-12-19 12:55:40 +01:00
local BushBranchCenter = { {1,1}, {3,2} }
2020-10-26 17:38:53 +01:00
for i in pairs(BushBranchCenter) do
2024-12-19 12:55:40 +01:00
local Num = BushBranchCenter[i][1]
local TexNum = BushBranchCenter[i][2]
2020-10-26 17:38:53 +01:00
minetest.register_node("bushes:bushbranches"..Num, {
description = S("Bush Branches @1", Num),
drawtype = "nodebox",
tiles = {
"bushes_leaves_"..TexNum..".png",
"bushes_branches_center_"..TexNum..".png"
},
2024-12-19 12:55:40 +01:00
use_texture_alpha = "clip",
2020-10-26 17:38:53 +01:00
node_box = {
type = "fixed",
fixed = {
{0, -1/2, -1/2, -1/4, 1/2, 1/2},
{0, -1/2, -1/2, 1/4, 1/2, 1/2}
},
},
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, 1/2, 1/2},
},
inventory_image = "bushes_branches_center_"..TexNum..".png",
paramtype = "light",
2021-12-27 15:08:16 +01:00
paramtype2 = "facedir",
sunlight_propagates = true,
2020-10-26 17:38:53 +01:00
groups = {
-- tree=1, -- MM: disabled because some recipes use group:tree for trunks
snappy=3,
flammable=2,
2021-06-27 17:39:50 +02:00
leaves=1,
attached_node=1
2020-10-26 17:38:53 +01:00
},
sounds = default.node_sound_leaves_defaults(),
drop = 'default:stick 4'
})
end
2024-12-19 12:55:40 +01:00
local BushBranchSide = { {2,1}, {4,2} }
2020-10-26 17:38:53 +01:00
for i in pairs(BushBranchSide) do
2024-12-19 12:55:40 +01:00
local Num = BushBranchSide[i][1]
local TexNum = BushBranchSide[i][2]
2020-10-26 17:38:53 +01:00
minetest.register_node("bushes:bushbranches"..Num, {
description = S("Bush Branches @1", Num),
drawtype = "nodebox",
tiles = {
--[[top]] "bushes_leaves_"..TexNum..".png",
--[[bottom]]"bushes_branches_center_"..TexNum..".png",
--[[right]] "bushes_branches_left_"..TexNum..".png",
--[[left]] "bushes_branches_right_"..TexNum..".png", -- MM: We could also mirror the previous here,
2021-12-27 15:08:16 +01:00
--[[back]] "bushes_branches_center_"..TexNum..".png",-- unless U really want 'em 2 B different
2020-10-26 17:38:53 +01:00
--[[front]] "bushes_branches_right_"..TexNum..".png"
},
2024-12-19 12:55:40 +01:00
use_texture_alpha = "clip",
2020-10-26 17:38:53 +01:00
node_box = {
type = "fixed",
fixed = {
2021-12-27 15:08:16 +01:00
-- { left , bottom , front, right , top , back }
{0.137748,-0.491944, 0.5 ,-0.125000,-0.179444,-0.007790}, --NodeBox 1
{0.262748,-0.185995, 0.5 ,-0.237252, 0.126505,-0.260269}, --NodeBox 2
{0.500000, 0.125000, 0.5 ,-0.500000, 0.500000,-0.500000}, --NodeBox 3
2020-10-26 17:38:53 +01:00
},
},
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, 1/2, 1/2},
},
inventory_image = "bushes_branches_right_"..TexNum..".png",
paramtype = "light",
2021-12-27 15:08:16 +01:00
paramtype2 = "facedir",
sunlight_propagates = true,
2020-10-26 17:38:53 +01:00
groups = {
-- tree=1, -- MM: disabled because some recipes use group:tree for trunks
snappy=3,
flammable=2,
2021-06-27 17:39:50 +02:00
leaves=1,
attached_node=1
2020-10-26 17:38:53 +01:00
},
sounds = default.node_sound_leaves_defaults(),
drop = 'default:stick 3'
})
end
2024-12-19 12:55:40 +01:00
local BushLeafNode = { {1}, {2}}
2020-10-26 17:38:53 +01:00
for i in pairs(BushLeafNode) do
local Num = BushLeafNode[i][1]
minetest.register_node("bushes:BushLeaves"..Num, {
description = S("Bush Leaves @1", Num),
drawtype = "allfaces_optional",
tiles = {"bushes_leaves_"..Num..".png"},
2024-12-19 12:55:40 +01:00
use_texture_alpha = "clip",
2020-10-26 17:38:53 +01:00
paramtype = "light",
groups = { -- MM: Should we add leafdecay?
snappy=3,
flammable=2,
2024-12-19 12:55:40 +01:00
attached_node=1,
leaves=1
2020-10-26 17:38:53 +01:00
},
sounds = default.node_sound_leaves_defaults(),
})
end
2024-12-19 12:55:40 +01:00
local function grow_bush_node(pos, dir, leaf_type)
2020-10-26 17:38:53 +01:00
local right_here = {x=pos.x, y=pos.y+1, z=pos.z}
local above_right_here = {x=pos.x, y=pos.y+2, z=pos.z}
local bush_branch_type = 2
if dir ~= 5 and leaf_type == 1 then
bush_branch_type = 2
end
if dir ~= 5 and leaf_type == 2 then
bush_branch_type = 4
end
if dir == 5 and leaf_type == 1 then
bush_branch_type = 1
dir = 1
end
if dir == 5 and leaf_type == 2 then
bush_branch_type = 3
dir = 1
end
2024-12-19 12:55:40 +01:00
local nodename = minetest.get_node(right_here).name
if nodename == "air" or nodename == "default:junglegrass" then -- instead of check_air = true,
2020-10-26 17:38:53 +01:00
minetest.swap_node(right_here, {name="bushes:bushbranches"..bush_branch_type , param2=dir})
minetest.swap_node(above_right_here, {name="bushes:BushLeaves"..leaf_type})
2024-12-19 12:55:40 +01:00
2020-10-26 17:38:53 +01:00
local chance_of_high_leaves = math.random(1,10)
2024-12-19 12:55:40 +01:00
if chance_of_high_leaves > 5 then
2020-10-26 17:38:53 +01:00
local two_above_right_here = {x=pos.x, y=pos.y+3, z=pos.z}
minetest.swap_node(two_above_right_here, {name="bushes:BushLeaves"..leaf_type})
end
end
end
2024-12-19 12:55:40 +01:00
local function grow_bush(pos)
-- replace possible grass nodes
minetest.swap_node({x=pos.x, y=pos.y+1, z=pos.z}, {name="air"})
2020-10-26 17:38:53 +01:00
2024-12-19 12:55:40 +01:00
local leaf_type = math.random(1,2)
local bush_side_height = math.random(0,1)
2020-10-26 17:38:53 +01:00
2024-12-19 12:55:40 +01:00
local chance_of_bush_node_right = math.random(1,10)
if chance_of_bush_node_right > 5 then
local right_pos = {x=pos.x+1, y=pos.y+bush_side_height, z=pos.z}
grow_bush_node(right_pos,3,leaf_type)
end
local chance_of_bush_node_left = math.random(1,10)
if chance_of_bush_node_left > 5 then
local left_pos = {x=pos.x-1, y=pos.y+bush_side_height, z=pos.z}
grow_bush_node(left_pos,1,leaf_type)
end
local chance_of_bush_node_front = math.random(1,10)
if chance_of_bush_node_front > 5 then
local front_pos = {x=pos.x, y=pos.y+bush_side_height, z=pos.z+1}
grow_bush_node(front_pos,2,leaf_type)
end
local chance_of_bush_node_back = math.random(1,10)
if chance_of_bush_node_back > 5 then
local back_pos = {x=pos.x, y=pos.y+bush_side_height, z=pos.z-1}
grow_bush_node(back_pos,0,leaf_type)
end
grow_bush_node(pos,5,leaf_type)
2020-10-26 17:38:53 +01:00
end
2024-12-19 12:55:40 +01:00
minetest.register_decoration({
name = "bushes:bush",
decoration = {
"air"
},
fill_ratio = bush_rarity,
y_min = 1,
y_max = 40,
place_on = {
"default:dirt_with_grass",
"stoneage:grass_with_silex",
"sumpf:peat",
"sumpf:sumpf"
},
deco_type = "simple",
flags = "all_floors",
})
--[[
this is purposefully wrapped in a on mods loaded callback to that it gets the proper ids
if other mods clear the registered decorations
]]
local did
minetest.register_on_mods_loaded(function()
did = minetest.get_decoration_id("bushes:bush")
minetest.set_gen_notify("decoration", {did})
end)
minetest.register_on_generated(function(minp, maxp, blockseed)
local g = minetest.get_mapgen_object("gennotify")
local locations = {}
local deco_locations = g["decoration#" .. did] or {}
for _, pos in pairs(deco_locations) do
locations[#locations+1] = pos
end
if #locations == 0 then return end
for _, pos in ipairs(locations) do
grow_bush(pos)
end
end)
2020-10-26 17:38:53 +01:00
2024-12-19 12:55:40 +01:00
local function grow_youngtree_node2(pos, height)
2020-10-26 17:38:53 +01:00
local right_here = {x=pos.x, y=pos.y+1, z=pos.z}
local above_right_here = {x=pos.x, y=pos.y+2, z=pos.z}
local two_above_right_here = {x=pos.x, y=pos.y+3, z=pos.z}
local three_above_right_here = {x=pos.x, y=pos.y+4, z=pos.z}
2024-12-19 12:55:40 +01:00
local nodename = minetest.get_node(right_here).name
if nodename == "air" or nodename == "default:junglegrass" then -- instead of check_air = true,
2020-10-26 17:38:53 +01:00
if height == 4 then
2021-12-27 15:08:16 +01:00
local two_above_right_here_south = {x=pos.x, y=pos.y+3, z=pos.z-1}
local three_above_right_here_south = {x=pos.x, y=pos.y+4, z=pos.z-1}
2024-12-19 12:55:40 +01:00
2021-12-27 15:08:16 +01:00
minetest.swap_node(right_here, {name="bushes:youngtree2_bottom"})
minetest.swap_node(above_right_here, {name="bushes:youngtree2_bottom"})
minetest.swap_node(two_above_right_here, {name="bushes:bushbranches2" , param2=2})
minetest.swap_node(two_above_right_here_south, {name="bushes:bushbranches2" , param2=0})
minetest.swap_node(three_above_right_here, {name="bushes:BushLeaves1" })
minetest.swap_node(three_above_right_here_south, {name="bushes:BushLeaves1" })
2020-10-26 17:38:53 +01:00
end
end
end
2024-12-19 12:55:40 +01:00
local function grow_youngtree2(pos)
local height = math.random(4,5)
grow_youngtree_node2(pos,height)
end
2020-10-26 17:38:53 +01:00
2024-12-19 12:55:40 +01:00
minetest.register_decoration({
name = "bushes:youngtree",
decoration = {
"air"
},
fill_ratio = youngtree_rarity,
y_min = 1,
y_max = 40,
place_on = {
"default:dirt_with_grass",
"stoneage:grass_with_silex",
"sumpf:peat",
"sumpf:sumpf"
2020-10-26 17:38:53 +01:00
},
2024-12-19 12:55:40 +01:00
deco_type = "simple",
flags = "all_floors",
})
--[[
this is purposefully wrapped in a on mods loaded callback to that it gets the proper ids
if other mods clear the registered decorations
]]
local did2
minetest.register_on_mods_loaded(function()
did2 = minetest.get_decoration_id("bushes:youngtree")
minetest.set_gen_notify("decoration", {did2})
end)
minetest.register_on_generated(function(minp, maxp, blockseed)
local g = minetest.get_mapgen_object("gennotify")
local locations = {}
local deco_locations = g["decoration#" .. did2] or {}
for _, pos in pairs(deco_locations) do
locations[#locations+1] = pos
end
if #locations == 0 then return end
for _, pos in ipairs(locations) do
grow_youngtree2(pos)
end
end)