Page 1 of 1

How to test for "air-like"node not filling the entire voxel?

Posted: Sun Jan 06, 2019 00:19
by michael314
I'm trying to write some code which tests if a block is air. But I have discovered that some blocks look like air even though they are not - for instance, grass_2. I do not know what these are called, but I need to treat any blocks that are air-like, that is, they have a block which isn't a cube which completely fills the voxel, the same as air.

How can I test for this?

Re: How to test for "air-like"node not filling the entire vo

Posted: Sun Jan 06, 2019 09:26
by Krock
In terms of light: Check against `sunlight_propagates = true` in the node definition
AFAIK all nodes which are smaller than 1x1x1m have this property to not look weird.

In terms of replacement: Check against `buildable_to = true` in the node definition. Those nodes are replaced when placing another node at the same spot.

If this solved your question, please add the [Solved] tag in front of your main post's title.

Re: How to test for "air-like"node not filling the entire vo

Posted: Thu Jan 10, 2019 12:56
by sorcerykid
Based on Krock's excellent answer, here's a quick function that will test if a node is airlike

Code: Select all

local function is_node_airlike( pos )
     local node = minetest.get_node( pos )
     return node ~= "ignore" and minetest.registered_nodes[ node.name ].sunlight_propagates == true
end
Afaik, this might not work with doors (I haven't tested, but it looks like sunlight_propagates is always true), so you would have to do another check for minetest.get_meta( pos ):get_int( "state" ) % 2 == 1 to ensure the door is actually open.

There are also some interesting corner cases with slabs and stairs (no pun intended), but I'll leave that as an exercise for you ;)

Re: How to test for "air-like"node not filling the entire vo

Posted: Wed Jan 16, 2019 04:55
by michael314
Thanks!

[Solved]How to test for "air-like"node not filling the entir

Posted: Wed Jan 16, 2019 05:02
by michael314
Krock wrote:If this solved your question, please add the [Solved] tag in front of your main post's title.
Sorry for being dense here, but... how do I do this? If I try to "edit" the main post, it ignores anything I try to type in the Subject line. I can edit the subject in *this* reply, but I'm not sure if that will do any good. (I'll try it here, if it works, disregard my question :-) Also, I can't really search very effectively for how to mark "solved" because I get lots of results of unrelated solved problems.

thanks!

Re: How to test for "air-like"node not filling the entire vo

Posted: Wed Jan 16, 2019 10:56
by rubenwardy
sorcerykid wrote:

Code: Select all

local function is_node_airlike( pos )
     local node = minetest.get_node( pos )
     return node ~= "ignore" and minetest.registered_nodes[ node.name ].sunlight_propagates == true
end
This won't work with unknown or aliased nodes.
The latter doesn't matter too much, but the former should be fixed by checking whether minetest.registered_nodes[ node.name ] is nil or not