A mod that adds mailboxes, based on the "old" xdecor mailboxes.
Thanks to @SmallJoker AKA Krock for helping me with the minetest.swap_node part of the mod!
There is a "global storage" option in mailboxes that shares items between multiple mailboxes. The inventories for these mailboxes are stored in mod storage and temporarily loaded into a player inventory list for online players.
mailbox.room_for_item(player_or_name, item)
: Checks ifplayer_or_name
's global mailbox inventory can fititem
. This may returnfalse
for offline players without a global mailbox inventory.mailbox.send_to_player(player_or_name, item)
: Sendsitem
toplayer_or_name
's global mailbox inventory. Returns an ItemStack containing whatever couldn't fit into the mailbox.mailbox.get_mailbox_inv_list(name)
: Similar toplayer:get_inventory():get_list("mailbox")
, however also works with offline players.mailbox.set_mailbox_inv_list(name, list)
: Similar toplayer:get_inventory():set_list("mailbox", new_list)
, however also works with offline players and saves the inventory list correctly.
Note that setting a player's mailbox
list directly (with
inventory:set_list()
) will not update the mod storage copy, and if the
server crashes or is shut down before the player logs out, the changes will not
be stored.
Other mods can use mailbox.get_mailbox_inv_list(name)
and
mailbox.set_mailbox_inv_list(name, list)
to manipulate these inventories.
These functions are similar to InvRef:get_list()
, however do not take a
list
parameter, and set_mailbox_inv_list()
accepts ItemStrings as well.