I would like a system that can count how many items of a type there is in a chest. The input comes from a hopper, but items can be removed manually. I would be happey if anyone can help.
Iv never worked with scoreboards before but would the '/testfor @e' work, having the items: dropped into a chamber, counted, scored and picked up by hopper again could work if you can make '/testfor @e' work on scoreboards. just thoughts tho.
the if and unless statements from the /execute command are the new /testfor. You can count how many items (in entity form) there are like this:
/execute if entity @e[type=item,nbt={Item:{id:"minecraft:diamond"}},distance=..5]
^ this command will display the number of items in chat. You can also store this output into a scoreboard objective like this:
/execute store result score <objective_holder> <objective> run execute if entity @e[type=item,nbt={Item:{id:"minecraft:diamond"}},distance=..5]
Note that a stack of diamonds will be counted as 1 entity instead of 64 because that's how the game works. To get around this you can store the number of items in that stack into the stack's objective like so:
execute as @e[type=item,nbt={Item:{id:"minecraft:diamond"}},tag=!counted,distance=..5] store result score @s <objective> run data get entity @s Item.Count
increment a fake player's objective by the amount stored in the stack's objective (the stack size)
execute as @e[type=minecraft:item,distance=..5,tag=!counted] run scoreboard players operation global <objective> += @s <objective>
in this example, I'm using a fake player called "global" but you can use a player or entity if you want. And finally, tag the item so it doesn't constantly increment global's objective while the hopper is collecting the item/stack.
tag @e[type=minecraft:item,distance=..5] add counted
My problem is a bit different. I have a chest that is filled with iron ingots from a hopper. There is a player that can take the iron ingots out from this chest manually. I would like a scoreboard to show how many iron ingots there is in the chest. It would also be nice if a redstone lamp can turn on if there are less than 12 iron ingots ind the chest.
The concept of this system is to store the number of iron ingots in each slot into the corresponding objective (27 objectives, 1 for each slot) and then sum it all up into one main objective which you can then use for amount detection. The tower of command blocks you see is required for each item type you want to detect. The lapis block that I have placed marks where your detection command(s) should be.
This is how I would go about doing it but maybe someone else has a better concept.
Hi
I would like a system that can count how many items of a type there is in a chest. The input comes from a hopper, but items can be removed manually. I would be happey if anyone can help.
I use ver 1.15.2.
If you know the items you plan on putting in the chest would adding an item sorter with comparator outputs to count the filtered items work for you?
Maybe. The thing I really would like is a scoreboard that shows how many eg. iron ingots there is in a chest real time.
Iv never worked with scoreboards before but would the '/testfor @e' work, having the items: dropped into a chamber, counted, scored and picked up by hopper again could work if you can make '/testfor @e' work on scoreboards. just thoughts tho.
The '/testfor' has been removed, and I can't see how I can make the count with '/execute' Anyone that know how?
the if and unless statements from the /execute command are the new /testfor. You can count how many items (in entity form) there are like this:
^ this command will display the number of items in chat. You can also store this output into a scoreboard objective like this:
Note that a stack of diamonds will be counted as 1 entity instead of 64 because that's how the game works. To get around this you can store the number of items in that stack into the stack's objective like so:
increment a fake player's objective by the amount stored in the stack's objective (the stack size)
in this example, I'm using a fake player called "global" but you can use a player or entity if you want. And finally, tag the item so it doesn't constantly increment global's objective while the hopper is collecting the item/stack.
In case you have no idea what I'm saying, here is a world download: https://www.dropbox.com/sh/jq8de3qdzcu2yi2/AADFeflCJVXEG_JwAj8tqlZoa?dl=0
Command block engineer // Developer // #TeamTrees
Thank you so much
I think I understand what you show.
My problem is a bit different. I have a chest that is filled with iron ingots from a hopper. There is a player that can take the iron ingots out from this chest manually. I would like a scoreboard to show how many iron ingots there is in the chest. It would also be nice if a redstone lamp can turn on if there are less than 12 iron ingots ind the chest.
Do you know if that is possible?
I have a world download here:
https://www.dropbox.com/sh/6k6l3a9af49tpfb/AACmyCi93Vzm_KrFgOZgIgbca?dl=0
I have implemented a system into the save you provided. here is the download link: https://www.dropbox.com/sh/swi7vznb54l371b/AACjaSH5M-rLemPUBsUtTbyAa?dl=0.
The concept of this system is to store the number of iron ingots in each slot into the corresponding objective (27 objectives, 1 for each slot) and then sum it all up into one main objective which you can then use for amount detection. The tower of command blocks you see is required for each item type you want to detect. The lapis block that I have placed marks where your detection command(s) should be.
This is how I would go about doing it but maybe someone else has a better concept.
Command block engineer // Developer // #TeamTrees
Thank you so much. It is a shame that one can't check all slot at once. You are a star.