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 convenience functions for overriding ABMs, LBMs and entities #14178

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sfence
Copy link
Contributor

@sfence sfence commented Dec 28, 2023

  • Extend Lua API for mod and game creators.
  • It adds override Lua functions for ABM, LBM, and entities.
  • This should fix Add minetest.override_entity() #6909 at least.
  • This also adds some checks to generate an error message when some mod tries to call some functions like register_node, register_lbm, etc after mod loading is finished.

To do

This PR is a Ready for Review

How to test

Run detest game. minetest.override_entity is tested in unittests. Test for minetest.override_abm and minetest.override_lbm can be done by placing nodes testabms:override and testlbms:onload_change from mods testabms and testlbms.

@Zughy Zughy added @ Script API Roadmap The change matches an item on the current roadmap Feature ✨ PRs that add or enhance a feature labels Dec 28, 2023
@Zughy
Copy link
Contributor

Zughy commented Dec 28, 2023

(only entities are in the roadmap, but I guess it won't hurt 🤷‍♀️ ; unsubscribing)

@grorp
Copy link
Member

grorp commented Dec 28, 2023

Of course, that doesn't make this PR invalid. It's more convenient to have API functions for this purpose.

@kromka-chleba
Copy link
Contributor

It adds override Lua functions for ABM, LBM, and entities.

I guess this resolves my issue? #13112
TL;DR Will this let me unregister and change ABMs/LBMs?

@grorp
Copy link
Member

grorp commented Dec 28, 2023

I guess this resolves my issue? #13112
TL;DR Will this let me unregister and change ABMs/LBMs?

It doesn't allow doing that "on the fly", so it probably doesn't resolve your issue.

@sfence
Copy link
Contributor Author

sfence commented Dec 28, 2023

@kromka-chleba

This only allows a change of abm/lbm at loading time. After mods are loaded, the Lua tables registered_abm and registered_lbm are loaded by C++ and converted to C++ class/structures which are used by the engine to proceed abm and lbm calls.

Supporting dynamic changing of lbm/abm during the game running will be more difficult to implement.

@sfence
Copy link
Contributor Author

sfence commented Dec 28, 2023

  • Adding error messages about calling registration functions after load time could go into a dedicated bugfix PR.

If this PR is closed without merging, I can create a specific PR for this. But because it takes time to merge PR, I would like to keep it here, instead of creating a separate PR and setting this PR to be blocked/waiting for it to be merged.

You are right. But in this way, with added error message it will be a more foolproof/error-proof way to override. This is too reason why do not create separate bugfix PR, I think.

This even works after load time AFAIK. So this PR only makes it more convenient.

Yes, but at least adding override_entity is in the roadmap. If actual solution is enough, Issue #6909 should in the closed state.

  • Shouldn't overriding ABMs and LBMs by modifying minetest.registered_abms/minetest.registered_lbms at load time already work as well?

Yes, it is possible. But you have to go through register_abms or registered_lbms tables manually in every situation where you want to override abm or lbm.

Of course, that doesn't make this PR invalid. It's more convenient to have API functions for this purpose.

@sfence
Copy link
Contributor Author

sfence commented Dec 29, 2023

Overriding of biomes will require changes and method adding in C++, so I will not implement it here. It should be a separate PR.

@sfence
Copy link
Contributor Author

sfence commented Dec 29, 2023

I have added the possibility of testing override functionality.

So, this is now prepared for review.

@lhofhansl
Copy link
Contributor

I like the idea. Nice tests!
I find myself not in a position to really review it. It looks right, and nothing obviously bad.

Once question, could one also do this with a helper mod that implements override_abm? It seems all this does it looking through the list of registered ABMs/LBMs and then modifies them.

@sfence
Copy link
Contributor Author

sfence commented Dec 30, 2023

I like the idea. Nice tests! I find myself not in a position to really review it. It looks right, and nothing obviously bad.

Once question, could one also do this with a helper mod that implements override_abm? It seems all this does it looking through the list of registered ABMs/LBMs and then modifies them.

Yes, all of this can be done by external mod with an exception for checking the is_mods_loaded field.
I have added and documented an optional new field name for ABM. It is checked in register_abm calls, if is provided, and allows ABM to be overridden.
It cannot be a required field because of backward compatibility.

But, my opinion is that It will be better to have this as part of the official modding API.

@grorp grorp changed the title Add override posibility for abm, lbm and entities. Add convenience functions for overriding ABMs, LBMs and entities Feb 4, 2024
@sfence sfence force-pushed the sfence_more_override_calls branch from 4e9cdf3 to 02f6071 Compare August 11, 2024 11:16
@sfan5 sfan5 added the Rebase needed The PR needs to be rebased by its author label Aug 16, 2024
@sfence sfence force-pushed the sfence_more_override_calls branch from 02f6071 to 445cf55 Compare August 18, 2024 10:52
@Zughy
Copy link
Contributor

Zughy commented Sep 23, 2024

@sfence more rebase needed (then please remove the label when you're done)

@Zughy Zughy closed this Nov 3, 2024
@Zughy Zughy added the Adoption needed The pull request needs someone to adopt it. Adoption welcomed! label Nov 3, 2024
@sfence sfence reopened this Nov 4, 2024
@sfence sfence force-pushed the sfence_more_override_calls branch from 445cf55 to 227c304 Compare November 4, 2024 08:04
@sfence sfence removed Rebase needed The PR needs to be rebased by its author Adoption needed The pull request needs someone to adopt it. Adoption welcomed! labels Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature ✨ PRs that add or enhance a feature Roadmap The change matches an item on the current roadmap @ Script API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add minetest.override_entity()
6 participants