2

Inventory check (Help me pls)perm_data_setting

vb1dra6847's Avatar vb1dra68472/16/24 10:47 am
2/16/2024 11:57 am
michaelo's Avatar michaelo
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's Avatar
vb1dra6847
Level 20 : Expert Caveman
3

Create an account or sign in to comment.

1

michaelo
02/16/2024 11:57 am
Level 32 : Artisan Chef
history
michaelo's Avatar
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
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome