Inventory interface (what would be nice for mods) ADD YOUR OPINION!

sapier
Member
 
Posts: 763
Joined: Tue Aug 16, 2011 18:17

Inventory interface (what would be nice for mods) ADD YOUR OPINION!

by sapier » Mon Jan 02, 2012 14:37

When trying to add or remove items/nodes from players inventory the current lua api doesn't provide a very conveniant way. This thread is meant to collect opinions of what would be best for mods so please add your comment!


Suggestion (names used are simplified to pronounce what the function is doing!):

inventory->has_items(<itemname>,<count>)
returning true if player has at least count items/nodes of type itemname, doesn't change (players) inventory

inventory->remove_items(<itemname>,<count>)
returns true on succes false otherwise. removes count elements of type itemname from (players) inventory

inventory_>add_items(<itemname>,<count>) --already present
adds count of itemname elements to (players) inventory
Last edited by sapier on Mon Jan 02, 2012 14:37, edited 1 time in total.
DON'T mention coding style!
(c) sapier all rights reserved
 

User avatar
xyz
Member
 
Posts: 449
Joined: Thu Nov 10, 2011 14:25

by xyz » Mon Jan 02, 2012 15:31

That, of course, could be implemented with lua, you don't need to touch any .cpp files.
 

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Mon Jan 02, 2012 15:37

I would also need a nicer routine for my throwing/bow-and-arrow mod. In that mod I use a quite dirty way to do these things by scanning the inventory list for certain strings.
Redstone for minetest: Mesecons (mesecons.net)
 

User avatar
sfan5
Member
 
Posts: 3636
Joined: Wed Aug 24, 2011 09:44
GitHub: sfan5
IRC: sfan5

by sfan5 » Mon Jan 02, 2012 15:56

+1
Mods: Mesecons | WorldEdit | Nuke
Minetest builds for Windows (32-bit & 64-bit)
 

sapier
Member
 
Posts: 763
Joined: Tue Aug 16, 2011 18:17

by sapier » Tue Jan 03, 2012 02:42

@xyz yes it can be implemented in lua but
either nearly every mod would require to implement it or
there would be some sort of generic tool collection like add_tools

but either way search and remove list operations would be implemented in lua which is a huge speed difference to c++ code.
at least I've been told so
DON'T mention coding style!
(c) sapier all rights reserved
 

randomproof
Member
 
Posts: 214
Joined: Thu Nov 17, 2011 06:31

by randomproof » Tue Jan 03, 2012 17:31

There needs to be a way to solve craft recipe conflicts. That is two or more mods using the same recipe to make different things. In a perfect world there would be a drop down to select the crafting target from the different possible choices.
 

User avatar
Hackeridze
Member
 
Posts: 310
Joined: Thu Nov 03, 2011 13:35

by Hackeridze » Tue Jan 03, 2012 17:59

randomproof wrote:There needs to be a way to solve craft recipe conflicts. That is two or more mods using the same recipe to make different things. In a perfect world there would be a drop down to select the crafting target from the different possible choices.

+1
My game: RTMG
GENTOO USER
 

kahrl
Member
 
Posts: 236
Joined: Fri Sep 02, 2011 07:51

by kahrl » Sat Jan 07, 2012 13:52

sapier wrote:inventory->has_items(<itemname>,<count>)
returning true if player has at least count items/nodes of type itemname, doesn't change (players) inventory

inventory->remove_items(<itemname>,<count>)
returns true on succes false otherwise. removes count elements of type itemname from (players) inventory


Just implemented those (with slightly different names and parameters). This is part of my huge inventory-related patchset, so I don't know when it is ready to be included, but hopefully very soon.
 

randomproof
Member
 
Posts: 214
Joined: Thu Nov 17, 2011 06:31

by randomproof » Sat Jan 07, 2012 23:48

sapier wrote:inventory->has_items(<itemname>,<count>)
returning true if player has at least count items/nodes of type itemname, doesn't change (players) inventory

inventory->remove_items(<itemname>,<count>)
returns true on succes false otherwise. removes count elements of type itemname from (players) inventory

inventory_>add_items(<itemname>,<count>) --already present
adds count of itemname elements to (players) inventory

+1
 

kahrl
Member
 
Posts: 236
Joined: Fri Sep 02, 2011 07:51

by kahrl » Thu Jan 12, 2012 14:05

Last edited by kahrl on Thu Jan 12, 2012 14:05, edited 1 time in total.
 

randomproof
Member
 
Posts: 214
Joined: Thu Nov 17, 2011 06:31

by randomproof » Thu Jan 12, 2012 16:02

It would also be nice if you could add a button to craft the max amount of something. For example when crafting brick nodes I put 4 stacks of clay bricks 99 and I have to double-click 99 times to craft 99 brick nodes.
 

User avatar
redcrab
Member
 
Posts: 831
Joined: Tue Dec 13, 2011 13:45

by redcrab » Thu Jan 12, 2012 17:43

randomproof wrote:It would also be nice if you could add a button to craft the max amount of something. For example when crafting brick nodes I put 4 stacks of clay bricks 99 and I have to double-click 99 times to craft 99 brick nodes.

+99
0.4 for serious builder click here
Dedicated Minetest redcrab server forum at http://minetestbb.suret.net

It's nice to be important but it is more important to be nice.
 

Nemo08
Member
 
Posts: 132
Joined: Mon Dec 26, 2011 04:59

by Nemo08 » Thu Jan 12, 2012 17:56


Metadata still set to default when you put item in inventary?
 

kahrl
Member
 
Posts: 236
Joined: Fri Sep 02, 2011 07:51

by kahrl » Thu Jan 12, 2012 17:59

Nemo08 wrote:

Metadata still set to default when you put item in inventary?

What kind of metadata do you mean? If you mean node metadata, that is unrelated to item metadata.
 

Nemo08
Member
 
Posts: 132
Joined: Mon Dec 26, 2011 04:59

by Nemo08 » Thu Jan 12, 2012 18:03

kahrl wrote:
Nemo08 wrote:

Metadata still set to default when you put item in inventary?

What kind of metadata do you mean? If you mean node metadata, that is unrelated to item metadata.

Item meta
I think we needed at least some sort of id for which we can uniquely identify an object or item. Item meta don't?
Last edited by Nemo08 on Thu Jan 12, 2012 18:04, edited 1 time in total.
 

sapier
Member
 
Posts: 763
Joined: Tue Aug 16, 2011 18:17

by sapier » Thu Jan 12, 2012 18:12

When attaching something like metadata to each individual item we have to consider that nodes may be in inventory too. Operations like "lookup_by_id" might take very long if you need to find a specific item within thousands of objects.
DON'T mention coding style!
(c) sapier all rights reserved
 

Nemo08
Member
 
Posts: 132
Joined: Mon Dec 26, 2011 04:59

by Nemo08 » Thu Jan 12, 2012 18:29

sapier wrote:When attaching something like metadata to each individual item we have to consider that nodes may be in inventory too. Operations like "lookup_by_id" might take very long if you need to find a specific item within thousands of objects.

Maybe I'm wrong said, rather than a unique id, but the data that is constantly saved in item, wherever it was. As an example of implementation - the key to the lock and the lock. How we may can connect them to each other? Maybe some inner id, which is stored in the key and lock. And so on
Last edited by Nemo08 on Thu Jan 12, 2012 18:35, edited 1 time in total.
 

kahrl
Member
 
Posts: 236
Joined: Fri Sep 02, 2011 07:51

by kahrl » Thu Jan 12, 2012 18:43

That is possible with item metadata, provided you find some way to generate a sufficiently unique ID.

If the player picks the key and lock up via item objects (created with minetest.add_item): Item objects can store item metadata.

If you give the key and lock to the player by calling player:get_inventory():add_item(...), just pass an item with metadata.

If key and lock are picked up as nodes, it's not possible, sadly.

Remember to set stack_max = 1, since item metadata belongs to a whole stack, not a single item in a stack.
Last edited by kahrl on Thu Jan 12, 2012 18:44, edited 1 time in total.
 

sapier
Member
 
Posts: 763
Joined: Tue Aug 16, 2011 18:17

by sapier » Thu Jan 12, 2012 18:48

the data that is constantly saved in item
Without a unique id, how do you want to ensure data is linked to specific object when you can't decide which of the thousands of objects (all beeing identical) is the object ot belongs to?

EDIT1:
entities support user defined variables, but by now they aren't preserved throughout server reboots. (there's a hacky way to save them by using staticdata but you need to serialize them manualy). Probably improvemts in this area might suite your needs
Last edited by sapier on Thu Jan 12, 2012 18:52, edited 1 time in total.
DON'T mention coding style!
(c) sapier all rights reserved
 

Nemo08
Member
 
Posts: 132
Joined: Mon Dec 26, 2011 04:59

by Nemo08 » Thu Jan 12, 2012 18:59

sapier wrote:
the data that is constantly saved in item
Without a unique id, how do you want to ensure data is linked to specific object when you can't decide which of the thousands of objects (all beeing identical) is the object ot belongs to?

EDIT1:
entities support user defined variables, but by now they aren't preserved throughout server reboots. (there's a hacky way to save them by using staticdata but you need to serialize them manualy). Probably improvemts in this area might suite your needs

Yes, this is problem, maybe in future we will have a way to show additional data as it is now tooltips to item, or can be a field of "additional description", or showing a further description, together with the name of the object. here we must think. Or change interface via lua for such things
Last edited by Nemo08 on Thu Jan 12, 2012 19:06, edited 1 time in total.
 

Nemo08
Member
 
Posts: 132
Joined: Mon Dec 26, 2011 04:59

by Nemo08 » Thu Jan 12, 2012 19:03

"throughout server reboots" and then they stay inactive. And the entity to distinguish from the nodes, crafts player can not put to inventory.
Last edited by Nemo08 on Thu Jan 12, 2012 19:05, edited 1 time in total.
 


Return to Minetest Features

Who is online

Users browsing this forum: Bing [Bot] and 15 guests

cron