#Best way to track items in an inventory

1 messages · Page 1 of 1 (latest)

sage shoal
#

Hello!
I'm currently deciding how to approach a new project, one which relies heavily on passive items in a player's inventory. I've been thinking of ways to track what items a player is currently holding, and I have a few approaches I'll list, but the main thing I'm looking for is advice as to what methods you would use to minimize server load. (the passive items are identified through nbt tags)

The first and worst way is to just loop the player's inventory periodically. This is inefficient and bad, but has the benefits of being very reliable and takes minimal effort to code.
The second way I was considering was to keep a running list of what slots are important, updated in inventory click/drag, pickup, drop, and interact events. This is much more efficient, but more prone to bugs and oversights, and requires a lot more effort to code.
Finally, I was considering adding a specific little inventory to place these passive items in. This would be very efficient, but also really limiting in terms of gameplay impact. I'd prefer not to use this method, if possible.

Any comments, suggestions, alternative methods, anything is welcome!

sharp shadow
#

When I read the first part of this message the first thing that came to my mind was option 2. It is really prone to bugs so it’ll require a lot of testing

sage shoal
#

oh i forgot to update this
I realised i could probably just use Paper's PlayerInventorySlotChangeEvent, which makes option 2 really easy to implement

#

I'm still open to other methods, but that's what I'm going with for now

modest shard
#

Honestly it’s probably most efficient to just check if the thing is there when you want to know

twilit marsh
#

What type of passive items are you adding? Gives me some more insight on how often you'd have to check it

sage shoal
sage shoal
twilit marsh
#

Hmm that's pretty often...
I indeed think option 2 would be the best/most efficient way unless you changed your mind about option 3

modest shard
#

what are you actually doing with this thing

sage shoal
#

I'm adding a system of tech-based baubles that require energy to function
The player carries batteries that store this energy, which the baubles draw from
Basically I'm checking if the baubles have enough energy to function every 10 ticks, as well as updating the batteries by drawing power from them (updating lore/NBT)

sage shoal
modest shard
#

I'd recommend cheating

sage shoal
#

in what way?

modest shard
#

it depends if you can use bukkit to do it or if you have to use skript

#

doing things with inventories is very quick in bukkit as long as you're not engaging a material switch

sage shoal
#

I'd love to be able to use bukkit but the people I'm working with don't know java
Might be able to spin up a small addon for it though

sage shoal
modest shard
#

yeah

#

it's a giant class so the switch is super slow

sage shoal
#

Makes sense

#

Thanks for the tips
I'll see if the skript version sucks, and if so I'll try using bukkit

modest shard
#

I have a thing that loops about 60 chest inventories per tick checking for something and it doesn't have an impact that I can detect

#

if it does become a problem what you can do is assume the player has the thing and just check periodically to make sure