2

Inventory check (Help me pls)perm_data_setting

vb1dra6847 2/16/24 10:47 am
322
2/16/2024 11:57 am
How can I check, that player has 4+ items (flint or custom item for example) in the inventory?

When I use
execute if data entity @s {Inventory:[{id:minecraft:flint,Count:4b}]} run <...>it works only when player has exactly 4 items in one of slots (other slots can contain not 4, so, if you have 64 and 4, it would work)
Posted by
vb1dra6847
Level 26 : Expert Caveman
5

  Have something to say?

JoinSign in

1

michaelo
02/16/2024 11:57 am
Level 36 : Artisan Taco Chef
history
If you want to check if something is greater or less than a value, you usually store the value in a score from /data get, then run an /execute if score command. If you want to check data values, you use /data get instead of /execute if data.

However, in this scenario when specifically checking items in the inventory, you can use a cool quirk of the /clear command, where if you clear 0 items of something, it returns the number of items you have. It would look like this:

execute store result score <name> <scoreboard> run clear @s minecraft:flint 0

execute if score test itemstats matches 4.. run say yes

You can add nbt to this as well for custom items, e.g. clear @s minecraft:flint{customtag:1b} 0

Hope that helps!
3

Welcome