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

Post Reply
michael314
Member
Posts: 12
Joined: Fri Jan 12, 2018 03:39

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

by michael314 » Post

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?

User avatar
Krock
Developer
Posts: 4524
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

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

by Krock » Post

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.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
sorcerykid
Member
Posts: 1311
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

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

by sorcerykid » Post

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 ;)

michael314
Member
Posts: 12
Joined: Fri Jan 12, 2018 03:39

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

by michael314 » Post

Thanks!

michael314
Member
Posts: 12
Joined: Fri Jan 12, 2018 03:39

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

by michael314 » Post

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!

User avatar
rubenwardy
Moderator
Posts: 6149
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: United Kingdom
Contact:

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

by rubenwardy » Post

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

Post Reply

Who is online

Users browsing this forum: Lejo, Majestic-12 [Bot] and 1 guest