-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Allow optional actor ObjectRef value in node interaction calls #14505
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The three changed functions can be changed to use a pattern like this instead of duplicating code for the nil case and the ObjectRef case:
ServerActiveObject *placer = nullptr;
if (!lua_isnoneornil(L, 3)) {
ObjectRef *ref = checkObject<ObjectRef>(L, 3);
placer = ObjectRef::getobject(ref);
}
bool success = scriptIfaceItem->item_OnPlace(item, placer, pointed);
lua_pushboolean(L, success);
I'm wondering about something: Suppose you want to use minetest.dig_node
in an automation mod. With this PR, you can specify a player so that the automation machine can dig in areas protected by the player. But if you specify a player, the items dug by the automation machine will end up directly in the player's inventory, instead of as dropped items or in the automation machine's inventory. How can this be solved / how is this solved in automation mods?
I think it could be useful to allow customizing the other parameters as well. For example, being able to set a custom pointed_thing for minetest.place_node might allow mods to fix #11335. (I saw you already have this on the to-do list.)
Resolves: luanti-org#14505 (comment) Resolves: luanti-org#14505 (review)
Fixed in cafeb62
This PR will not cover this entirely as that would require creating a "virtual player" object type. However, this PR still helps in area protection checks (e.g. minetest-mods/areas#54) and player operation extension (e.g. optimizing the code of Technic Mining Drills).
The main problem is the lack of an existing function to convert a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behavior difference between place_node (nullptr = nil ObjectRef) and dig_node/punch_node (nullptr = invalid ObjectRef) is weird, but it already existed before this PR, so 🤷
This PR adds an optional operator (ObjectRef) parameter to node interaction calls in
l_env.cpp
.Previously, mimicking all the behaviors when a player digs a node was complex when specifying an ObjectRef. With this PR, the operator can be passed onto the callbacks.
This will be the true solution to programmed node interactions needing interaction checks, e.g. minetest-mods/areas#54.
Fixes #13563
Related to #11336
Related to #14004 (comment)
Related to minetest-mods/areas#54
To do
This PR is Ready for Review.
minetest.place_node
minetest.dig_node
minetest.punch_node
Potential to-dos and issues
minetest.punch_node
custompointed_thing
How to test
I use
//luatransform
in WorldEdit to test my modifications. For example, to testdig_node
:This code may help visualize the calls:
Example
https://github.com/C-C-Minetest-Server/twi_mods/blob/2e658d0df4e404dccb43d48934b631762ac80055/func_areas_limitations/init.lua#L27-L37