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

Include a predicate argument for MC_EXECUTE_CMD #629

Open
EliteMasterEric opened this issue Feb 10, 2025 · 2 comments
Open

Include a predicate argument for MC_EXECUTE_CMD #629

EliteMasterEric opened this issue Feb 10, 2025 · 2 comments

Comments

@EliteMasterEric
Copy link

Currently, registering a callback for the MC_EXECUTE_CMD does not allow for an additional argument to filter by what command used. Mods registering to this callback should be able to optionally filter by the command being used.

Example:

-- This adds a callback which is only executed if the "cmd" argument to the callback matches "spawn_item"
mod:AddCallback(ModCallbacks.MC_EXECUTE_CMD, debug_spawn_item, "spawn_item")

This would eliminate the need for mods using Repentogon to include if cmd == "spawn_item" at the beginning of every command's callback. It would also be a minor performance save as the comparison would be made before executing the Lua callback.

@im-tem
Copy link
Collaborator

im-tem commented Feb 10, 2025

  1. It will NOT be a saving as optional arguments checks are done within Lua ever since the official callback rework and due to the function not being called that often for it to be an issue
  2. I personally don't think it's THAT big of an issue to do the check yourself? Though I am not entirely opposed to the idea of this little QoL thingy.

@EliteMasterEric
Copy link
Author

EliteMasterEric commented Feb 10, 2025

It will NOT be a saving as optional arguments checks are done within Lua ever since the official callback rework and due to the function not being called that often for it to be an issue

Fair enough.

I still think that adding something to do a comparison for you makes sense, considering that comparison is probably made 99.9% of the time the callback is used,

It also helps prevent bugs. I had to fix an issue with my mod where any use of any console command would trigger all my debug commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants