A function to detect if a node is inside the active block radius?

Post Reply
User avatar
Hume2
Member
Posts: 709
Joined: Tue Jun 19, 2018 08:24
GitHub: Hume2
In-game: Hume2
Location: Czech Republic

A function to detect if a node is inside the active block radius?

by Hume2 » Post

Is there any such function to do this? Of course that I can iterate over all players and check the distance ... but ... there should be a better option. Minetest should somehow know which chunks are active and which aren't so I shouldn't need to calculate it myself.
If you lack the reality, go on a trip or find a job.

CalebJ
Member
Posts: 407
Joined: Sat Dec 29, 2018 19:21
GitHub: KaylebJay
IRC: KaylebJay
In-game: CalebJ
Location: Tunnelers' Abyss

Re: A function to detect if a node is inside the active block radius?

by CalebJ » Post

You can use an Active Block Modifier? Maybe I'm misunderstanding.

User avatar
Hume2
Member
Posts: 709
Joined: Tue Jun 19, 2018 08:24
GitHub: Hume2
In-game: Hume2
Location: Czech Republic

Re: A function to detect if a node is inside the active block radius?

by Hume2 » Post

No, I have a postion and I want to check if the node at the position is active, regardless of what kind of node it is.
If you lack the reality, go on a trip or find a job.

CalebJ
Member
Posts: 407
Joined: Sat Dec 29, 2018 19:21
GitHub: KaylebJay
IRC: KaylebJay
In-game: CalebJ
Location: Tunnelers' Abyss

Re: A function to detect if a node is inside the active block radius?

by CalebJ » Post

Ah, to check if it is *inside* the active block range. Not sure there :/

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

Re: A function to detect if a node is inside the active block radius?

by sorcerykid » Post

It might be best to just check minetest.get_node_or_nil(). That won't tell if the mapblock is in the active block radius, but it will at least tell if the mapblock is loaded which is usually the same thing iirc.

User avatar
Hume2
Member
Posts: 709
Joined: Tue Jun 19, 2018 08:24
GitHub: Hume2
In-game: Hume2
Location: Czech Republic

Re: A function to detect if a node is inside the active block radius?

by Hume2 » Post

It's not quite the same. The default radius of loaded chunks is 10 while the radius of active chunks is 3.
If you lack the reality, go on a trip or find a job.

Termos
Member
Posts: 417
Joined: Sun Dec 16, 2018 12:50

Re: A function to detect if a node is inside the active block radius?

by Termos » Post

You could iterate over connected players and return true on the first found within 3 block radius.

User avatar
Hume2
Member
Posts: 709
Joined: Tue Jun 19, 2018 08:24
GitHub: Hume2
In-game: Hume2
Location: Czech Republic

Re: A function to detect if a node is inside the active block radius?

by Hume2 » Post

That's what I wrote in the OP. I'm asking if there is a better solution because Minetest somehow has to know that anyway so I see no point of calculating it myself.
If you lack the reality, go on a trip or find a job.

User avatar
sirrobzeroone
Member
Posts: 593
Joined: Mon Jul 16, 2018 07:56
GitHub: sirrobzeroone
Contact:

Re: A function to detect if a node is inside the active block radius?

by sirrobzeroone » Post

I googled into this thread as I had a similar question. Just spent a bit of time trawling the API and I think this may tell you if a pos is "active" inside a mapblock.

Code: Select all

minetest.compare_block_status(pos, condition)

Checks whether the mapblock at positition pos is in the wanted condition.
condition may be one of the following values:
      "unknown": not in memory
      "emerging": in the queue for loading from disk or generating
      "loaded": in memory but inactive (no ABMs are executed)
      "active": in memory and active

Other values are reserved for future functionality extensions
Return value, the comparison status:
false: Mapblock does not fulfil the wanted condition
true: Mapblock meets the requirement
nil: Unsupported condition value

Info may go out of date over time but at least the next person who stumbles on this thread will have somewhere to look :).

loosewheel
Member
Posts: 155
Joined: Mon Dec 28, 2020 01:19
GitHub: loosewheel
In-game: loosewheel

Re: A function to detect if a node is inside the active block radius?

by loosewheel » Post

Thanks for that @sirrobzeroone. I was looking for this a little while ago. I found a work-around, but its handy to know.

User avatar
Hume2
Member
Posts: 709
Joined: Tue Jun 19, 2018 08:24
GitHub: Hume2
In-game: Hume2
Location: Czech Republic

Re: A function to detect if a node is inside the active block radius?

by Hume2 » Post

I'm surprised that this function exists, thanks!
If you lack the reality, go on a trip or find a job.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests