1

I'm trying to clear a player's inventory of an unstackable item if they have two of them in their inventory. This is a system to prevent duplication, while at the same time guaranteeing they still have this item and can't get rid of it.

The problem is: using an NBT tag selector for if the player has this item in their inventory only works for one item. Writing another entry within this NBT tag selector (like {Inventory:[{id:"minecraft:example"},{id:"minecraft:example"}]}) still treats it like one item and using {id:"minecraft:example",Count:2b} doesn't work either since these items can't be stacked.

How can I make this work the way I want it to? I'd rather not make 600+ different NBT tag selectors for each combination of possible {Slot:#b}'s if I can avoid it.

  • "This is a system to prevent duplication" What does that mean? Does some aspect of your map cause items to be duplicated? Then you should fix that instead of fixing the symptoms. – Fabian Röling Jan 14 '18 at 0:45
  • You can use /clear @p <item> 0 and then use that result in a /stats command. But since I'm not good with /stats, I'll let someone else answer, for example IronAnvil. – Fabian Röling Jan 14 '18 at 1:04
  • You mention /modifyitem - are you looking for an answer applicable to 1.12 or 1.13? The answers will be completely different based on the version you're using. – Skylinerw Jan 14 '18 at 1:49
  • "This is a system to prevent duplication, 'while at the same time guaranteeing they still have this item and can't get rid of it.' " – OnePointZero Jan 14 '18 at 3:44
  • I wrote in that add-on specifically to avoid confusion on this. The thing is, I want them to be able to put the item in chest inventories and throw them on the ground, but there must be one of that item existing in the world at any given moment. I have to give the player the item back if it doesn't exist anywhere, but that's hard to do since players can simply mouse-click pick-up the item in their inventory to have it disappear from both inventory and world. – OnePointZero Jan 14 '18 at 3:51
0

DUH.

All I have to do is merge {Age:0s} with the item I don't want to disappear. Then I have no need to give the player the item back. And if I have no need to give the player the item back, I have no need to worry if I give the player too many.

DUH.

Not the answer you're looking for? Browse other questions tagged or ask your own question.