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

Chest registration overrides definition fields, including inventory callbacks #3152

Open
DustyBagel opened this issue Aug 30, 2024 · 2 comments

Comments

@DustyBagel
Copy link

Minetest version

Minetest-5.9.0-stable

Irrlicht device

win32

Operating system and version

Windows 11 home

CPU model

No response

GPU model

No response

Active renderer

No response

Summary

I am using the allow_put node callable and it doesn't seem to be running:

default.chest.register_chest("modname:nodename", {
    --other callbacks
    allow_put = function(inv, listname, index, stack, player)
        minetest.chat_send_all("This is running")
        return stack:get_count()
    end
})

I do have a theory that this function that is connected to the allow_put callback is being overwritten by the register_chests function which can be found here:
https://github.com/minetest/minetest_game/blob/master/mods/default/chests.lua#L89

Steps to reproduce

Run test mod:
allow_put_test.zip

@appgurueu
Copy link
Contributor

appgurueu commented Aug 30, 2024

  1. It's allow_metadata_inventory_put for nodes. allow_put is for detached inventories. Our docs could be clearer about this.
  2. You are correct that default.chest.register_chest overrides a bunch of definition fields. If def.protected is truthy, allow_metadata_inventory_put will be overridden. Instead we should call the original allow handler if the protection check succeeds.

This is no engine issue however, it's a Minetest Game dehardcoding request.

@appgurueu appgurueu transferred this issue from minetest/minetest Aug 30, 2024
@appgurueu appgurueu changed the title allow_put not running? Chests override definition fields, including allow inventory callbacks when chest is protected Aug 30, 2024
@appgurueu appgurueu changed the title Chests override definition fields, including allow inventory callbacks when chest is protected Chest registration overrides definition fields, including inventory callbacks Aug 30, 2024
@DustyBagel
Copy link
Author

Ah, I see, the docs were confusing because the line:

The engine docs should be changed to reflect the difference between them.

Maybe we can change how defs are handled in the default.chest.register_chest function, Something like this:

default.chest.register_chest(nodename, {
    --other defs
    if def.protected then
        if def.allow_metadata_inventory_put then
            local old_func = def.allow_metadata_inventory_put
            def.allow_metadata_inventory_put = function (pos, listname, index, stack, player)
                if not default.can_interact_with_node(player, pos) then
                     return 0
                end
                old_func()
                return stack:get_count()
            end
        else
              def.allow_metadata_inventory_put = function (pos, listname, index, stack, player)
              if not default.can_interact_with_node(player, pos) then
                   return 0
              end
              return stack:get_count()
        end
    end
})

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

No branches or pull requests

2 participants