Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'on (first) load' option to ABMs or LBMs (or new 'on load ABM' API) #5303

Closed
MarkuBu opened this issue Feb 25, 2017 · 6 comments
Closed
Labels
Feature request Issues that request the addition or enhancement of a feature @ Script API

Comments

@MarkuBu
Copy link
Contributor

MarkuBu commented Feb 25, 2017

Let me bring this up in a different way. I know that the LBM's original purpose is to replace old nodes with new versions in existing maps. They are useless in new maps, except a mod will be updated (e.g. replace 2d torches with 3d)

But how about if they can also act like a one time ABM? I know that I can use register_on_generated in some cases, but it becomes more complicated if I want to search for nodes with a neighbor. I need to run find_node_near for each found node in a list. Even if Lua is fast this will be inefficient

Some examples for use cases:

  • Start a node timer (e.g. to replace the grass spread or grass covered ABM. Node timer only needs to run if air is around)
  • Spawn mobs only once, not in an interval.

To keep compatibility I propose a parameter like one_time_ABM = true, that is set to false by default. If the parameter is set to true the LBM behaves like an ABM, but just one time on each load or once at first load of the map

Because the reason for this issue is mainly the search for neighbors, I will open a second issue to add neighbor search to find_node_near and find_nodes_in_area

@paramat paramat added Feature request Issues that request the addition or enhancement of a feature @ Script API labels Feb 25, 2017
@sorcerykid
Copy link
Contributor

sorcerykid commented Feb 27, 2017

I can foresee many advantages to expanding the functionality of ABMs. However, if the goal is to only execute an ABM once, then wouldn't it be more straightforward to just allow an "interval" of 0 with a chance of 1, then the ABM would execute for all the specified nodes exactly one time as soon as the mapblock is loaded or reloaded? Changing the implementation of LBMs as described does not seem in fitting with their intended purpose.

minetest.register_abm{
        label = "lava cooling",
	nodenames = {"group:lava"},
	neighbors = {"group:water"},
	interval = 0,
	chance = 1,
	action = function(pos)
		minetest.set_node(pos, {name = "default:cobblestone"})
	end,
}

As an alternative, a specialized block modifier could be introduced for this purpose, with on_load( ) and on_unload( ) callbacks that are guaranteed to execute immediately after a mapblock is loaded or immediately before a mapblock is unloaded within the environment. The mapblock boundaries could be passed as a parameter to both callbacks. I'm just using XBM here for sake of example:

minetest.register_xbm{
        label = "mob spawner",
	on_load = function(pos1, pos2)
		...spawn mob entities in area...
	end,
}

I understand that exposing mapblocks in this way is regarded by some core devs as bad form. So this latter solution might be deemed unacceptable.

@est31
Copy link
Contributor

est31 commented Feb 28, 2017

One of the reasons I did LBMs separate from ABMs and not just added it to ABMs was the neighbour search. Its computationally expensive and doesn't make sense when replacing nodes.

@MarkuBu
Copy link
Contributor Author

MarkuBu commented Feb 28, 2017

I understand why it is like it is. But I think there is a need for something like l a "on load ABM"

So maybe it is the wrong approach to modify the LBM. Maybe it is the better way to add some kind of "on (first) load) behavior to ABM's or to add some kind of new ABM that only run's on load

@sorcerykid
Copy link
Contributor

Personally speaking, I would like to the reliability of LBMs addressed before modifying them for other purposes (right now LBMs are effectively broken, and basically useless).

@rubenwardy
Copy link
Member

#4050

@paramat paramat changed the title Let LBMs behave like a one time ABM Add 'on first load' option to ABMs Nov 27, 2017
@paramat paramat changed the title Add 'on first load' option to ABMs Add 'on (first) load' option to ABMs Nov 27, 2017
@paramat paramat changed the title Add 'on (first) load' option to ABMs Add 'on (first) load' option to ABMs or LBMs Nov 27, 2017
@paramat paramat changed the title Add 'on (first) load' option to ABMs or LBMs Add 'on (first) load' option to ABMs or LBMs (or new 'on load ABM' API) Sep 20, 2018
@paramat
Copy link
Contributor

paramat commented Sep 20, 2018

1+ year bump. Any core dev support?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature request Issues that request the addition or enhancement of a feature @ Script API
Projects
None yet
Development

No branches or pull requests

5 participants