Register ABM that affects all nodes
-
- Member
- Posts: 29
- Joined: Sat Aug 08, 2020 21:35
Register ABM that affects all nodes
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?
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?
Re: Register ABM that affects all nodes
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
- 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
variant A:
variant B:
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)
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)
-
- Member
- Posts: 29
- Joined: Sat Aug 08, 2020 21:35
Re: Register ABM that affects all nodes
I've already tried variant A but it ends up not working, but variant B works great!Skamiz Kazzarch wrote: ↑Mon May 03, 2021 17:29variant A:variant B: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)
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)
Thank you :)
-
- Member
- Posts: 29
- Joined: Sat Aug 08, 2020 21:35
Re: Register ABM that affects all nodes
something like that would make a lot of modding more convenientTenPlus1 wrote: ↑Mon May 03, 2021 15:56You 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
- 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
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's better to use global steps and manually check around players with LVMs when you want to do lots of updates
-
- Member
- Posts: 29
- Joined: Sat Aug 08, 2020 21:35
Re: Register ABM that affects all nodes
It did kill performance, but the group ABM idea above works quite fast compared to registering abms for every node.rubenwardy wrote: ↑Mon May 03, 2021 18:30It'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
There is a specific reason I'm using ABMs in this case.
Re: Register ABM that affects all nodes
Maybe if you tell us what you are trying to do there may be another way of doing it :)
- Linuxdirk
- Member
- Posts: 3217
- Joined: Wed Sep 17, 2014 11:21
- In-game: Linuxdirk
- Location: Germany
- Contact:
Re: Register ABM that affects all nodes
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 :)
-
- 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
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
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
Re: Register ABM that affects all nodes
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
Who is online
Users browsing this forum: No registered users and 5 guests