I want to create an item which you cannot get rid of, so if you throw it on the ground that item (snowball) will be deleted. But I don't want to kill all items using /kill @e[type=Item]
, I just want to kill just the snowball. Can anyone help?
-
I get the basics of what you want, but it's hard for me to tell exactly what it is you want to do. Can you edit your question to be a little more specific and clearer?– MBraedleyCommented Aug 22, 2015 at 19:32
-
i mean if u throw a diamond on the ground and then the snowball which will kill only the snowball and not kill the diamond thats what im trying to do right now im using /kill @e[type=Item]– GuestCommented Aug 24, 2015 at 3:04
5 Answers
You will have to use scoreboards for this:
Setup a dummy scoreboard (ex.
/scoreboard objectives add Sample_OBJ dummy
)Add this command to at the most a 4 tick clock (hopper or fill clock will do):
/scoreboard players set @e[type=Item] Sample_OBJ 1 {Item:{id:minecraft:wool}}
Add Another command block that needs To be on a clock:
/kill @e[type=Item,score_Sample_OBJ_min=1]
You need a scoreboard because you can't put NBT in selectors/there is no ID tag in item selectors.
Here is a solution that uses scoreboard tags. It will tag any item matching the exact criteria which could include custom names, lore, enchantments, any NBT information. This tag can then be used to target only those items to be killed. In my example, a snowball named Test will be the only item that gets killed. You can throw out unnamed snowballs and they will be safe.
You need two command blocks in a chain.
The first command block is RepeatUnconditionalAlways Active and it's command is:
scoreboard players tag @e[type=Item] add KillItem {Item:{id:"minecraft:snowball",tag:{display:{Name:Test}}}}
The second command block is ChainUnconditionalAlways Active and it's command is:
kill @e[tag=KillItem]
To destroy a certain item, rename it and use
/kill @e[type=Item, name={item name here}]
That should do the trick. You could also look up a way to destroy all of one item.
-
Have you tested this? I'm pretty sure the name tag in selectors doesn't work with the Item entity. Commented Aug 24, 2015 at 9:51
-
@Judge2020 I'm pretty sure it does, but I have not tested it. If it doesn't then take out the
type=Item
and just use the name selector. Commented Aug 24, 2015 at 13:28 -
This does not work. The default display name of item entities contains periods, which cannot be used in target selectors. The custom display name within the item data is not used as its display name for the entity. You also cannot have spaces. Commented Jan 2, 2016 at 21:09
/kill @e[Type=Item.{Item or Block}.{Item}]
Example : /kill @e[Type=Item.Item.leather]
In version 1.11.2, data tags were added to /kill
!
/kill @e[type=Item] {Item:{id:minecraft:wool}}