Inventory Change Callback

Description

Inventory Change Callback 🔗

Provide a universal global callback for handling player inventory changes.

Information for GAME developers 🔗

The mod can handle all types of natural events ("move", "put", "take", "dig", "place", "pickup", "eat"), except the changes made manually in code. So please don't forget to call rr.handle_player_inventory_changes(player) after using inventory changing functions:

local name = player:get_player_name()
local inv = player:get_inventory()
local list = inv:get_list("main")

-- Your changes example:
list[1] = ItemStack("")
inv:set_list("main", list)

Now trigger handlers manually:

-- "custom" is optional action name
rr.handle_player_inventory_changes(player, "custom")

OR just update cache (if you don't want to trigger them for some reason):

rr.player_inventory_main_lists[name] = list

Information for MOD developers 🔗

It is actually not necessary to add a handler to every custom event in the game. Alternatively, you can just use this workaround, which will check the inventory of all players in the game every second:

minetest.register_on_mods_loaded(rr.auto_detect_inventory_changes)

Usage 🔗

See test.lua.

Debug mode 🔗

Uncomment lines at the bottom of init.lua.


This mod was created in Rustroot Forge.

All my mods uses Luanti LSP-API annotations, StyLua and Luacheck.

Reviews

Review

Do you recommend this mod?

  • No reviews, yet.

Releases

1.1.1

Download

Luanti 5.6+

2023-09-03 02:13 UTC

1.1.1 🔗

No release notes

1.1.1

Download

Luanti 5.6+

2023-05-13 04:51 UTC

1.1.1 🔗

No release notes

1.1.0

Download

Luanti 5.6+

2023-05-13 04:10 UTC

1.1.0 🔗

No release notes

1.0.0

Download

Luanti 5.6+

2023-05-12 21:43 UTC

1.0.0 🔗

No release notes

All releases