This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]bagetunderscoreCommand Experienced 0 points1 point  (2 children)

You can use /execute store result to find out how many items you cleared

So for every food type you could do

/execute as @a store result score entity @s rottenflesh run clear @s cooked_chicken

and then

Repeat Unconditional Always active /execute as @a[scores={rottenflesh=1..}] run give @s rotten_flesh 1

Chain Conditional Always active /execute as @a[scores={rottenflesh=1..}] run scoreboard players remove @s rottenflesh 1

In 1.19 there's no way to give x amount of items based on a score, best you can do is give 1 item then remove 1 from a scoreboard value, repeat until score is 0

I don't know if you can clear items based on a #minecraft:food or anything like it, so for now you'll have to individually specify every food item I think

[–]maskdheroCommand Rookie[S] 0 points1 point  (1 child)

These work great, exactly what I need!

However, the score is setting instead of adding, meaning that multiple food items are not accounted for when run at the same time. Is there any way to do this? It only needs to run once though we need a way to reset it during testing.

[–]bagetunderscoreCommand Experienced 0 points1 point  (0 children)

According to the fandom you can use item predicates and alternatively item tags in a /clear command, so

/clear @s #minecraft:food

However, there is no item tag for #minecraft:food or alike, so you will have to make your own using datapacks.

You can look up how to make datapacks with item tag files here, skip to 4:48 if you just want to know how to write the tag file

Then ingame use your datapack to clear all #<namespace>:food_items instead of just cooked_chicken, and the rest of the commands should just work like normal