Register ABM that affects all nodes

Post Reply
chaosomnium
Member
Posts: 29
Joined: Sat Aug 08, 2020 21:35

Register ABM that affects all nodes

by chaosomnium » Post

I would like to register an abm that preferably would affect all nodes, like nodenames = {"allnodes"} without having to refer to all nodes.
There are two alternative methods I can think of to do this, one would be to register an abm for every single node in game, or to register an abm with a list of all nodenames manually gathered.
Is there an easier way to register an abm and optimally set it to group:all or something? Or do I have to do one of the two alternative methods?

User avatar
TenPlus1
Member
Posts: 3715
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: Register ABM that affects all nodes

by TenPlus1 » Post

You could always use something like {"group:stone", "group:soil", "group:leaves", "group:water"} but there are too many nodes to think of... This is one of the use cases for the param:walkable group I pitched here: https://github.com/minetest/minetest/issues/10125

User avatar
Skamiz Kazzarch
Member
Posts: 613
Joined: Fri Mar 09, 2018 20:34
GitHub: Skamiz
In-game: Skamiz
Location: la lojbaugag.

Re: Register ABM that affects all nodes

by Skamiz Kazzarch » Post

variant A:

Code: Select all

minetest.register_on_mods_loaded(function()
	local nodes = {}
	for node_name, _ in pairs(minetest.registered_nodes) do
		table.insert(nodes, node_name)
	end

	minetest.register_abm({
		nodenames = nodes,
		-- other required stuff here
	})
end)
variant B:

Code: Select all

minetest.register_abm({
	nodenames = {"group:all_the_nodes"},
	-- other required stuff here
})
minetest.register_on_mods_loaded(function()
	for node_name, node_definition in pairs(minetest.registered_nodes) do
		local g = table.copy(node_definition.groups)
		g.all_the_nodes = 1
		minetest.override_item(node_name,{
			groups = g
		})
	end
end)

chaosomnium
Member
Posts: 29
Joined: Sat Aug 08, 2020 21:35

Re: Register ABM that affects all nodes

by chaosomnium » Post

Skamiz Kazzarch wrote:
Mon May 03, 2021 17:29
variant A:

Code: Select all

minetest.register_on_mods_loaded(function()
	local nodes = {}
	for node_name, _ in pairs(minetest.registered_nodes) do
		table.insert(nodes, node_name)
	end

	minetest.register_abm({
		nodenames = nodes,
		-- other required stuff here
	})
end)
variant B:

Code: Select all

minetest.register_abm({
	nodenames = {"group:all_the_nodes"},
	-- other required stuff here
})
minetest.register_on_mods_loaded(function()
	for node_name, node_definition in pairs(minetest.registered_nodes) do
		local g = table.copy(node_definition.groups)
		g.all_the_nodes = 1
		minetest.override_item(node_name,{
			groups = g
		})
	end
end)
I've already tried variant A but it ends up not working, but variant B works great!
Thank you :)

chaosomnium
Member
Posts: 29
Joined: Sat Aug 08, 2020 21:35

Re: Register ABM that affects all nodes

by chaosomnium » Post

TenPlus1 wrote:
Mon May 03, 2021 15:56
You could always use something like {"group:stone", "group:soil", "group:leaves", "group:water"} but there are too many nodes to think of... This is one of the use cases for the param:walkable group I pitched here: https://github.com/minetest/minetest/issues/10125
something like that would make a lot of modding more convenient

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

Re: Register ABM that affects all nodes

by rubenwardy » Post

It's a really really bad idea to register ABMs for all nodes. This will kill performance

It's better to use global steps and manually check around players with LVMs when you want to do lots of updates
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

chaosomnium
Member
Posts: 29
Joined: Sat Aug 08, 2020 21:35

Re: Register ABM that affects all nodes

by chaosomnium » Post

rubenwardy wrote:
Mon May 03, 2021 18:30
It's a really really bad idea to register ABMs for all nodes. This will kill performance

It's better to use global steps and manually check around players with LVMs when you want to do lots of updates
It did kill performance, but the group ABM idea above works quite fast compared to registering abms for every node.

There is a specific reason I'm using ABMs in this case.

User avatar
TenPlus1
Member
Posts: 3715
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: Register ABM that affects all nodes

by TenPlus1 » Post

Maybe if you tell us what you are trying to do there may be another way of doing it :)

User avatar
Linuxdirk
Member
Posts: 3216
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: Register ABM that affects all nodes

by Linuxdirk » Post

rubenwardy wrote:
Mon May 03, 2021 18:30
This will kill performance
Please correct me if I'm wrong, but registering ABMs "for all nodes" would mean that there are 4096 affected nodes per map block (either directly by name or indirectly via group), right?

Lets assume 8 map blocks loaded in each direction, that means 512 map blocks are loaded, each having 4096 affected nodes, meaning that there are 2,097,152 nodes affected by an "all nodes" ABM when having 8 map blocks viewing distance (128 nodes in each direction, which is not much).

Maybe we should ask NASA to borrow one of their super computers for testing purposes :)

Calicelechat
New member
Posts: 8
Joined: Wed Oct 11, 2023 07:08
GitHub: Calicelechat
IRC: Calice
In-game: Calice

Re: Register ABM that affects all nodes

by Calicelechat » Post

Bonjour,
J'ai un probleme de timer j'ai besoin pour une machine que si un bloc se trouve sur un autre chaque seconde un action s'effectue et au bout de 16 secondes le bloc du dessus se casse comme un extracteur qui extrait les sediment du blocs. Voici mon premier code merci :)

if "default:sand" place_on "magic_tech:sediment_extractor_enable" then
local content_value = minetest.get_node_timer(pos)
for content_value ~= 16 do
timer:start(1)
content_value == content_value + 1
sediment_extracted == sediment_extracted + 1
end
content_value = nil
end

User avatar
Mantar
Member
Posts: 584
Joined: Thu Oct 05, 2017 18:46
Contact:

Re: Register ABM that affects all nodes

by Mantar » Post

Try something like:

Code: Select all

minetest.register_node("magic_tech:sediment_extractor_enable", {
... -- node definition goes here
on_construct = function(pos)
   minetest.get_node_timer(pos):start(1)
end,
on_timer = function(pos, elapsed)
   local above = vector.add(pos, vector.new(0,1,0))
   local anode = minetest.get_node(above)
   if anode.name == "default:sand" then
    node.param2 == node.param2 + 1 -- param2 to store progress
    if node.param2 >= 16 then
      extract_sediment() -- however that works
    end
    minetest.set_node(above, anode)
   else -- no sand? switch off
     minetest.set_node(pos, {name = "magic_tech:sediment_extractor_disable"})
   end
end,
}
Lead dev of Exile, git repo: https://codeberg.org/Mantar/Exile

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests