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

Fix object:punch(puncher, ... should allow nil for puncher #14319

Merged
merged 7 commits into from Apr 28, 2024

Conversation

sfence
Copy link
Contributor

@sfence sfence commented Jan 28, 2024

To do

This PR is a Ready for Review.

How to test

Add entity callback:callback_puncher and punch it.

@sfence sfence changed the title Fix #3837 object:punch(puncher, ... should allow nil for puncher Fix object:punch(puncher, ... should allow nil for puncher Jan 28, 2024
@wsor4035 wsor4035 added @ Script API Bugfix 🐛 PRs that fix a bug labels Jan 28, 2024
@sfan5 sfan5 self-assigned this Feb 17, 2024
games/devtest/mods/callbacks/players.lua Outdated Show resolved Hide resolved
src/script/cpp_api/s_entity.cpp Outdated Show resolved Hide resolved
src/script/lua_api/l_object.cpp Outdated Show resolved Hide resolved
src/script/lua_api/l_object.cpp Outdated Show resolved Hide resolved
src/server/luaentity_sao.cpp Outdated Show resolved Hide resolved
src/server/player_sao.cpp Outdated Show resolved Hide resolved
src/tool.cpp Outdated Show resolved Hide resolved
@Zughy Zughy added the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Feb 17, 2024
@Zughy Zughy removed the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Feb 22, 2024
Copy link
Member

@sfan5 sfan5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just some minor stuff, looks good otherwise

src/script/lua_api/l_object.cpp Outdated Show resolved Hide resolved
src/server/player_sao.cpp Outdated Show resolved Hide resolved
src/server/player_sao.cpp Outdated Show resolved Hide resolved
@Zughy Zughy added Action / change needed Code still needs changes (PR) / more information requested (Issues) and removed Action / change needed Code still needs changes (PR) / more information requested (Issues) labels Feb 22, 2024
@SmallJoker
Copy link
Member

SmallJoker commented Mar 3, 2024

Why do we need a nil puncher?


Discussed in the meeting: https://irc.minetest.net/minetest-dev/2024-03-03#i_6156874

  • likely causes problems 3d_armor until it's fixed
  • on_rightclick does yet not seem to allow nil ObjectRefs?
  • this is generally an OK change to have it consistent

@sfence
Copy link
Contributor Author

sfence commented Mar 3, 2024

Why do we need a nil puncher?

Why do we need a nil puncher?
Why #3837 has been labeled a bug and not closed to these days?

In #3837 is said: "The API clearly states in several places that nil is allowed. And this would be useful for mods to add "environment" damage that isn't attributable to objects."

@appgurueu
Copy link
Contributor

I agree that we want to support a nil puncher, API-wise. But causing regressions in very popular mods like 3d_armor is a significant concern. We will probably want to run a zipgrep to see which other mods may be affected.

@sfan5
Copy link
Member

sfan5 commented Mar 9, 2024

This might sound obvious, but this only causes problems if some mod uses a nil puncher. So I think it's not that bad.
Delaying this change for the sake of 3d_armor doesn't make much sense (who will fix it and how long do we wait?).

@appgurueu
Copy link
Contributor

appgurueu commented Mar 11, 2024

So I think it's not that bad.

It's not as bad as mods that outright crash, yes. It requires another mod to use the feature. But once mods start using this feature, there will be worse cross-mod compatibility.

I've opened an issue on the 3d armor repo to notify them - I think they're probably the most popular, potentially affected mod - and additionally asked for a zipgrep of on_punchplayer on ContentDB. Crashing on a nil puncher should be relatively easy to fix (in mods).

I'm fine with merging this for 5.9. I will make an effort to notify at least the maintainers of a couple of the most popular mods.

As far as this PR goes, I think it should make clear that puncher can be nil in register_on_punchplayer (technically this may follow from the docs on :punch, but modders are likely to miss that).

Do we have some kind of place to advertise such changes that may lead to (in this case cross-mod) compatibility issues in the future? Add another section to the changelog?

@SmallJoker
Copy link
Member

SmallJoker commented Mar 17, 2024

Why #3837 has been labeled a bug and not closed to these days?

There's so many issues that it's hard to keep track of whether they're still valid.
That issue was opened in 2016. set_hp got support for PlayerHPChangeReason in 2018 and can since be used to specify details of the damage type (as an alternative to punching). I'd assume mods would use different damage groups in ObjectRef:punch to specify the origin of the punch.

The API clearly states in several places that nil is allowed.

(from the issue)
I looked up some callbacks in the documentation and builtin code: (✔ = may be nil, ✘ = only ObjectRef mentioned)

  • node can_dig ✔ (used by core.dig_node)
  • node register_on_placenode ✔ (used by core.place_node)
  • node on_rightclick
  • node on_punch ✘ but core.punch_node passes nil anyway
  • register_on_punchnode ?? not documented
  • node on_dig ?? not documented (core.node_dig accepts and forwards nil, but is not documented either)
  • register_on_dignode ?? not documented
  • node after_dig_node ✘ but may get nil anyway due to core.node_dig callbacks
  • node inventory callbacks: ?? not documented
  • object on_rightclick
  • register_on_rightclickplayer argument clicker
  • object on_punch
  • register_on_punchplayer argument hitter ✘ (but may anyway due to this PR)

Whenever something's not documented, I'd assume that ObjectRef is provided.

mckaygerhard added a commit to minenux/minetest-mod-3d_armor that referenced this pull request Mar 27, 2024
doc/lua_api.md Outdated Show resolved Hide resolved
Copy link
Contributor

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sfence could you please also document that hitter may be nil in register_on_punchplayer now?

I think we should merge this and

  • Keep an eye out for potential issues;
  • Highlight this change in the release notes

At least in 3d_armor this should be addressed now.

games/devtest/mods/callbacks/entities.lua Outdated Show resolved Hide resolved
src/script/lua_api/l_object.cpp Show resolved Hide resolved
src/server/player_sao.cpp Show resolved Hide resolved
Copy link
Contributor

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with the provided entity, works.

@sfan5 sfan5 added the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Apr 20, 2024
@appgurueu appgurueu merged commit 72cb4e9 into minetest:master Apr 28, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Action / change needed Code still needs changes (PR) / more information requested (Issues) Bugfix 🐛 PRs that fix a bug @ Script API >= Two approvals ✅ ✅
Projects
None yet
Development

Successfully merging this pull request may close these issues.

object:punch(puncher, ... should allow nil for puncher
6 participants