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

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 » Sun Jan 06, 2019 00:19

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: 4409
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

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

by Krock » Sun Jan 06, 2019 09:26

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: 1061
Joined: Fri Aug 26, 2016 15:36
Location: Illinois, USA
GitHub: sorcerykid
In-game: Nemo

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

by sorcerykid » Thu Jan 10, 2019 12:56

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
 

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 » Wed Jan 16, 2019 05:02

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: 5886
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

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

by rubenwardy » Wed Jan 16, 2019 10:56

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
 


Return to Problems



Who is online

Users browsing this forum: No registered users and 3 guests