Realistic Trees

Post Reply
User avatar
Neuromancer
Member
Posts: 958
Joined: Tue Jun 12, 2012 22:28
GitHub: Neuromancer56

Realistic Trees

by Neuromancer » Post

This is my attempt to make realistic trees like in this video https://youtu.be/PXmNnnk690s?t=230.
The code is mostly taken from Bushy Leaves mod by erlehmann, but uses plantlike drawtypes so it does not have the performance hit that Bushy Leaves mod does.
Download here: https://github.com/Neuromancer56/RealisticTrees
Screenshot: Image

User avatar
Neuromancer
Member
Posts: 958
Joined: Tue Jun 12, 2012 22:28
GitHub: Neuromancer56

Re: Realistic Trees

by Neuromancer » Post

Does anyone know why the following code (especially the place_param2 = 4 + 0x10) does not result in a "#" shaped node rather than an "x" shaped node? Does minetest.override_item(node_name, new_node_def) not override the place_param2 value? Here's a thread discussing the issue: viewtopic.php?t=22087

Code: Select all

local def = {
drawtype = "plantlike",
--tiles = {"default_leaves.png"},
--paramtype = "light",
paramtype2 = "meshoptions",
place_param2 = 4 + 0x10
--sunlight_propagates = true,
--walkable = false,
--buildable_to = true,
--drop = "",
--groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2}
}

local get_node_def = function(node_name, node_def)
	local new_node_def

	if (
		 (string.match(node_name, "leaves") and not(string.match(node_name, "with_leaves") ))or
		string.match(node_name, "needles")
	) then
		 new_node_def  = table.copy(def)
	end
	return new_node_def
end


local add_bushy_leaves = function()
	for node_name, node_def in pairs(minetest.registered_nodes) do
		local new_node_def = get_node_def(node_name, node_def)
		if  nil ~= new_node_def then
			minetest.override_item(node_name, new_node_def)
		end
	end
end

minetest.register_on_mods_loaded(add_bushy_leaves)

ShadMOrdre
Member
Posts: 1118
Joined: Mon Dec 29, 2014 08:07
Location: USA

Re: Realistic Trees

by ShadMOrdre » Post

I see you used the sample code I posted in that thread.

The last post, by Nathan, and the one just previous gave this example.

Code: Select all

drawtype = "plantlike",
tiles = {"starfire_fire.png"},
paramtype = "light",
paramtype2 = "meshoptions",
place_param2 = 3,
sunlight_propagates = true,
walkable = false,
buildable_to = true,
drop = "",
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2}
It looks like place_param2 = 3.

Nathan suggested this should work. No hex bits.


Shad

User avatar
Neuromancer
Member
Posts: 958
Joined: Tue Jun 12, 2012 22:28
GitHub: Neuromancer56

Re: Realistic Trees

by Neuromancer » Post

ShadMOrdre wrote:
Thu Jun 01, 2023 01:06
I see you used the sample code I posted in that thread.

The last post, by Nathan, and the one just previous gave this example.

Code: Select all

drawtype = "plantlike",
tiles = {"starfire_fire.png"},
paramtype = "light",
paramtype2 = "meshoptions",
place_param2 = 3,
sunlight_propagates = true,
walkable = false,
buildable_to = true,
drop = "",
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2}
It looks like place_param2 = 3.

Nathan suggested this should work. No hex bits.


Shad
I tried that, here's an even more explicit version and set place_param2 = 3, but it still doesn't work. I think it has something to do with the minetest.override_item() not working with the place_param2 no matter what you set it to. In his case he's not using the minetest.override_item() method.

Code: Select all

local add_bushy_leaves = function()
	for node_name, node_def in pairs(minetest.registered_nodes) do
		local new_node_def = get_node_def(node_name, node_def)
		if  nil ~= new_node_def then
			minetest.override_item(node_name, {
				drawtype = "plantlike",
				paramtype2 = "meshoptions",
				place_param2 = 3
}
)
			minetest.override_item(node_name, new_node_def)
		end
	end
end

User avatar
LMD
Member
Posts: 1386
Joined: Sat Apr 08, 2017 08:16
GitHub: appgurueu
IRC: appguru[eu]
In-game: LMD
Location: Germany
Contact:

Re: Realistic Trees

by LMD » Post

No, this will change place_param2 just fine. The problem is that place_param2 doesn't do what you think it does: It merely changes the default param2 values leaves modes will get when they are placed (by players). The param2 of all existing nodes in the world definitely won't be affected, and mapgen won't be affected either, just player placed nodes will be affected.

To "upgrade" older (and freshly mapgen'd) leaf nodes to the new param2, you will need to use minetest.register_lbm.

Careful, though: Leaves currently hackily (ab)use param2 to determine whether leaf decay should apply to them (in order to not apply leaf decay to player-placed leaves):

Code: Select all

-- Prevent decay of placed leaves

default.after_place_leaves = function(pos, placer, itemstack, pointed_thing)
	if placer and placer:is_player() then
		local node = minetest.get_node(pos)
		node.param2 = 1
		minetest.set_node(pos, node)
	end
end

-- Leafdecay
local function leafdecay_after_destruct(pos, oldnode, def)
	for _, v in pairs(minetest.find_nodes_in_area(vector.subtract(pos, def.radius),
			vector.add(pos, def.radius), def.leaves)) do
		local node = minetest.get_node(v)
		local timer = minetest.get_node_timer(v)
		if node.param2 ~= 1 and not timer:is_started() then
			timer:start(math.random(20, 120) / 10)
		end
	end
end
If you don't need strong MTG compatibility, you could register new nodes for player-placed leaves which don't decay, and again upgrade MTG leaves using a LBM; you could also provide a LBM for "downgrading" them in case players decide to remove your mod (they would then have to enable another mod).

This might introduce incompatibilities with mods which check exactly for default leaves.

If you want to avoid registering another node for each leaf, you could also use a higher bit. This would require modifying MTG though since it explicitly checks for node.param2 ~= 1. Again you would need both an "upgrade" and a "downgrade" LBM, but they would only have to touch param2.
My stuff: Projects - Mods - Website

User avatar
Blockhead
Member
Posts: 1622
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: Realistic Trees

by Blockhead » Post

LMD wrote:
Thu Jun 01, 2023 08:05
This would require modifying MTG though since it explicitly checks for node.param2 ~= 1.
Sounds like a failing of MTG, especially with the bitop library present.
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

User avatar
LMD
Member
Posts: 1386
Joined: Sat Apr 08, 2017 08:16
GitHub: appgurueu
IRC: appguru[eu]
In-game: LMD
Location: Germany
Contact:

Re: Realistic Trees

by LMD » Post

Blockhead wrote:
Thu Jun 01, 2023 10:22
LMD wrote:
Thu Jun 01, 2023 08:05
This would require modifying MTG though since it explicitly checks for node.param2 ~= 1.
Sounds like a failing of MTG, especially with the bitop library present.
Well, this feature of MTG is much older than the addition of the bitop library.

That said, I can't really blame them for not having this use-case in mind; it's hard to design "forward-compatible" software - who knows whether these paramtype2s even existed when the code was written?
My stuff: Projects - Mods - Website

User avatar
Desour
Member
Posts: 1469
Joined: Thu Jun 19, 2014 19:49
GitHub: Desour
IRC: Desour
In-game: DS
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.

Re: Realistic Trees

by Desour » Post

FYI, there is already a plantlike leaves mod: <viewtopic.php?t=13433>
(If you enable rotated leaves, it also suffers from mtg leafdecay using param2.)
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

User avatar
j0j0n4th4n
Member
Posts: 249
Joined: Tue Jan 26, 2021 06:45

Re: Realistic Trees

by j0j0n4th4n » Post

I changed the drawtype to "firelike" and I think it looks better:
Screenshot at 2023-06-01 13-31-45.png
Screenshot at 2023-06-01 13-31-45.png (594.46 KiB) Viewed 773 times
cdb_894a100ddd76

Astrobe
Member
Posts: 571
Joined: Sun Apr 01, 2018 10:46

Re: Realistic Trees

by Astrobe » Post

j0j0n4th4n wrote:
Thu Jun 01, 2023 16:33
I changed the drawtype to "firelike" and I think it looks better:
Did that too in my game. There are pros and cons. One cons is that you see the "trick" with dynamic shadows when the sun (or the moon) is at noon. One can apply a small sun orbit tilt (15 degrees) to hide it (this enhances a bit shadows too, as they are not perfectly aligned with blocks anymore). One still sees the sky when standing right below foliage though.

The bushy leaves mod does an interesting thing at a price; if only we a layout fit for that use... It is on of the feature requests I did last weekend.

Back to the earlier problem of param2 and leave decay, AFAIK leave decay of player-placed leaves will only happen if they remove the corresponding type of tree log near the leaves. It seems to me that it is a minor issue.

BTW the Luscious mod has a similar issue.

Addendum: the topic reminded me of an old mod that present a possible alternative solution. Some of them use nodeboxes, but others use a mesh.
My game? It's Minefall.

User avatar
Neuromancer
Member
Posts: 958
Joined: Tue Jun 12, 2012 22:28
GitHub: Neuromancer56

Re: Realistic Trees

by Neuromancer » Post

j0j0n4th4n wrote:
Thu Jun 01, 2023 16:33
I changed the drawtype to "firelike" and I think it looks better:
Screenshot at 2023-06-01 13-31-45.png
I like the way it looks much better than the standard plantlike, but they don't wave anymore, so I'm going to see if I can get the "#" or "*" shaped plantlike working.

Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests