0

Version 1.14.4:
I am trying to make a commands system that forces a player to drop whatever item is in their main hand. Because I can't use commands to make a player press Q and drop the original item, I need to copy the NBT into a new item on the ground and remove the old one from the player. I obviously want any NBT, including enchantments, names, lore, etc. to be copied over exactly.

I know that I can use /data to get the NBT from the SelectedItem of a player, and execute store can put NBT into an entity. However, /data get only returns numeric data, and execute store only allows me to set one NBT path at a time, so my plan of summoning a generic item on the ground and then just copying the NBT over (including the item ID) does not work.

Am I going about this wrong and there is a way to do this, or is this just impossible? My eventual plan is to implement this into a datapack, so if a method requires moving items into tile entities or something similar involving setting aside a space to spawn blocks in I'd rather avoid that. Of course, if you know a method like that by all means put it as an answer because someone else with the same question may find it useful for their situation.

  • You can add a tag to the item in the players hand and then ask the player to drop it. If the player doesn't, you have every opportunity to react via command, e.g. confining them to an area they can't leave or many other things. – Polygnome Jul 23 '19 at 21:29
  • Thanks for the suggestion: I think that would work in an adventure map, but it's supposed to be like the expelliarmus spell from Harry Potter, so asking them to drop it is pretty much out of the question because they are under no restrictions to obey (and I can't put any on them due to the situations it would be used in), and they would probably just hex their opponent first. – Nik3141 Jul 23 '19 at 21:37
  • @arghtype Why did you move the version to the body? – Nik3141 Jul 23 '19 at 21:38
  • 1
  • @pppery The linked post only describes tags, and there is no tag for version 1.14, or any Minecraft version for that matter, and I prefer prefacing questions with the version number so all of my questions are uniform in where they have the version info. I know that minecraft-commands refers exclusively to Java edition, so it is unnecessary in the title, but if I'm going to put the version in doesn't change much to put in the words 'Java Minecraft' too. – Nik3141 Jul 23 '19 at 21:53
3

You can copy the entire SelectedItem tag to the Item tag of the item entity:

/data modify entity @e[type=item,limit=1] Item set from entity @s SelectedItem

The existing item can be anything, it gets overwritten anything. Example summoning command:

/summon item ~ ~ ~ {Item:{id:"stone",Count:1}}

Just /summon item does not work, because it would be a stack of air with size 0.

More information about /data modify is in my other answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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