I'm running a server for a group of friends with a significant number of custom items which give an effect when in the player's inventory (NOT just when held, which minecraft supports natively). Unfortunately, the command block /execute
processes for these commands are quite expensive, even with optimizations like Lithium.
This is one example of a command I'm currently using, ran in a repeating command block targeting an item with a custom texture:
/execute if @a[nbt={Inventory:[{id:"minecraft:raw_gold",display:{Name:'{"Cursed Ruby"}',Lore:['{"text":"When In Inventory:","color":"gray"},{"text":" Blindness","color":"red"}']}}]}] at @a[nbt={Inventory:[{id:"minecraft:raw_gold",display:{Name:'{"Cursed Ruby"}',Lore:['{"text":"When In Inventory:","color":"gray"},{"text":" Blindness","color":"red"}']}}]}] run effect give @p minecraft:blindness 5 1 true
Selector is below:
@a[
nbt={
Inventory:[{
id:"minecraft:raw_gold",
display:{
Name:'{"Cursed Ruby"}',
Lore:['
{"text":"When In Inventory:","color":"gray"},
{"text":" Blindness","color":"red"}
']
}
}]
}
]
With around 20 similar items in numerous quantities across multiple player inventories, this gets expensive fast. You might notice that I've attempted using an if
keyword to reduce the impact of the command; it seems to have helped a little bit, but this is still taking roughly 40% of my server's resources.
Is there a way to minimize the performance impact of inventory-based checks, similar to how Minecraft's native When In Hand
applies it? I can use mods if necessary, but a vanilla solution is preferred.
inventory_changed
advancement trigger. Also, general performance stuff: github.com/Neylz/opti-mcfunction