Page 1 of 1

Help with creating another inventory (modding)

Posted: Mon Mar 16, 2020 22:46
by LC Creations
Hello, I'm working on a mod that allows players to put a single item from their inventory in a formspec list (for one item only). I dont know how to create another inventory that is attached to the player. How do I do this. I know to to create formspecs and show the original inventory but how to I create a secondary inventory for the player?

Re: Help with creating another inventory (modding)

Posted: Tue Mar 17, 2020 08:01
by Eran
You'll want to use detached inventories. You can use their callbacks to make it so a player can only put in a single item. Keep in mind you'll have to save these manually in player meta, mod storage or a file. You can save using detached inventory callbacks aswell.
To get a detached inventory to show up in a formspec see here.

Re: Help with creating another inventory (modding)

Posted: Tue Mar 17, 2020 08:49
by rubenwardy

Re: Help with creating another inventory (modding)

Posted: Wed Mar 18, 2020 03:27
by CBugDCoder
This might be the completely wrong way of doing it but I have been able to create a custom inventory bound to the player simply by setting the size of a new list in the player inventory on join e.g.
minetest.register_on_joinplayer(player)
local inv = player:get_player_inventory()
inv:set_size("antimater_chest", 8*4)
end
This creates a inventory that I use for a enderchest like node.

Re: Help with creating another inventory (modding)

Posted: Wed Mar 18, 2020 07:33
by Eran
CBugDCoder wrote:This might be the completely wrong way of doing it but I have been able to create a custom inventory bound to the player simply by setting the size of a new list in the player inventory on join e.g.
minetest.register_on_joinplayer(player)
local inv = player:get_player_inventory()
inv:set_size("antimater_chest", 8*4)
end
This creates a inventory that I use for a enderchest like node.
Huh, neat, I didn't know that was possible.