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?
How to test for "air-like"node not filling the entire voxel?
-
- Member
- Posts: 12
- Joined: Fri Jan 12, 2018 03:39
- Krock
- Developer
- Posts: 4650
- 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
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.
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>
- sorcerykid
- Member
- Posts: 1847
- 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
Based on Krock's excellent answer, here's a quick function that will test if a node is airlike
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 ;)
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
There are also some interesting corner cases with slabs and stairs (no pun intended), but I'll leave that as an exercise for you ;)
-
- Member
- Posts: 12
- Joined: Fri Jan 12, 2018 03:39
-
- Member
- Posts: 12
- Joined: Fri Jan 12, 2018 03:39
[Solved]How to test for "air-like"node not filling the entir
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.Krock wrote:If this solved your question, please add the [Solved] tag in front of your main post's title.
thanks!
- rubenwardy
- Moderator
- Posts: 6978
- Joined: Tue Jun 12, 2012 18:11
- GitHub: rubenwardy
- IRC: rubenwardy
- In-game: rubenwardy
- Location: Bristol, United Kingdom
- Contact:
Re: How to test for "air-like"node not filling the entire vo
This won't work with unknown or aliased nodes.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
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
Who is online
Users browsing this forum: No registered users and 1 guest