How can I create a copy of an entity using command blocks?

How can I create a copy of an entity using command blocks? - Crop faceless toddler sitting on bed with colorful wooden building blocks while mother sitting with legs crossed doing remote work with laptop on knees on background

More specifically, say there's a pile of items on the ground, for instance after someone dies, and I want to create an exact copy of each of those items (NBT tags and all), but in a different (specific) location. How would I go about doing that?

Taking the naive approach, the math gets pretty horrifying pretty quickly. For instance, adding a command block for every combination of every enchantment on every item that can hold those enchantments quickly becomes unmanageable. For instance, there are 6 enchantments that can be applied to every type of armour, there are 5 armour grades, 4 armor pieces at each grade, and at least 3 enchantment levels (with default enchanting) for these enchantments. That alone would take 720 command blocks (considering I need 2 command blocks to do the clone), to say nothing of the various combinations of enchantments that can be had within those 6, plus other enchantments available to individual armour pieces, and durability (oh god, the durability) of the items. Obviously, writing thousands (millions?) of command blocks with testfor @e[type=Item] {NBT:"some long and nested NBT tag} and summon Item x y z {NBT:"the same long and nested NBT tag} isn't feasible (and won't even produce the correct result). No, I need another way.

I've been through the commands page on the Minecraft wiki, and nothing jumped out at me. The closest command I could see is the clone command, but that only works on blocks and tile entities (i.e. chests, furnaces, and the like). Also, I know I can edit the NBT data directly, but the point is to be able to do this while the game is running.



Best Answer

One option would be to use armor stands or wither skulls to be placeholders and teleport the items back and forth.

Or you could place hoppers and chests with /setblock, copy the chest with clone and then take the items out with hoppers and droppers. I can't remember if you can break a chest so it drops items with /setblock. If you need to, use /entitydata to add/remove tags to stop items from despawning.

Hope that helps.




Pictures about "How can I create a copy of an entity using command blocks?"

How can I create a copy of an entity using command blocks? - From above unrecognizable woman in gray sweater sitting at wooden table with food in bowl and creating document while working on remote project at home
How can I create a copy of an entity using command blocks? - From above of crop anonymous worker sitting at wooden table with instruments and browsing laptop while working in carpenter studio in daytime
How can I create a copy of an entity using command blocks? - Adult thoughtful writer creating new article



Quick Answer about "How can I create a copy of an entity using command blocks?"

  • First, spawn an armor stand (as a marker) in the location of the entity to be cloned.
  • Move the entity to a predefined location.
  • Clone it with the structure blocks.
  • Then move the entity back to the marker, and the new one where you want it.
  • Finally remove the marker.


  • How do you duplicate an entity in Minecraft?

    To copy drawing entities: Click Modify > Copy (or type Copy). Specify the entities you want to duplicate and press Enter. Specify a source base point for the copy.

    How do you duplicate entities?

    Simply use Shift and the arrow keys to select the command. Then use Ctrl + C to copy the command and Ctrl + V to paste it in the new command block. On a Mac, use Cmd instead of Ctrl . To copy the entirety of a certain Command block or Text press Ctrl+A to select it all then Ctrl+C to copy it.

    How do you use command blocks to copy?

    The way you clone a mob is to first craft a new item called the syringe. After that, you will need to extract some of the mob's blood with the syringe. Then inject that mob with the blood inside the syringe to impregnate it with its own species.



    How I Made AI-like Following Work with Any Entity | Minecraft Java 1.17+ | Command Toolbox #9




    More answers regarding how can I create a copy of an entity using command blocks?

    Answer 2

    The only way to do this reliably currently is to teleport all the items to a hopper and put them into a chest. This can be speed up using the /blockdata command to negate the cooldown of the hopper, but will still take some time for a large number of items (320 ticks or 16 seconds for a full hopper). The chest can then be cloned to the required location, and using /setblock x y z air 0 destroy with the doTileDrops gamerule set to false, the contents but not the chest will be dropped.

    Answer 3

    I'm surprised no one suggested this, but if /teleporting rather than cloning is an option, you can target the items directly:

    /scoreboard objectives add itemCount dummy (only execute once)

    1. /scoreboard players tag @r[type=Item] add item0 {OnGround:1b} (in a repeating or clocked command block with next commands chained)
    2. /scoreboard players set @e[tag=item0] itemCount 0
    3. /execute @e[tag=item0] ~ ~ ~ execute @e[r=3,type=Item,tag=!item0] ~ ~ ~ scoreboard players add @e[tag=item0,r=3] itemCount 1
    4. /execute @e[tag=item0,score_itemCount_min=5] teleport @e[type=Item,r=3] <x> <y> <z>

    Here's what this is doing:

    1. pick a random item on the ground to check.
    2. set its score in the 'itemCount' objective to zero.
    3. have any items on the ground within 3 blocks of it add 1 to its score.
    4. if its score is over 4, teleport it and any other item within 3 blocks to the location x,y,z.

    This will teleport any group of 5 or more distinct item stacks to that location. If you want to make sure not to teleport items that, say, popped out of a broken chest, you can also use the same method to check for a certain number of XPOrbs in addition to Items. I can't think of anything other than a player that might drop more than 3 or 4 xporbs and more than 5 items.

    Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

    Images: Tatiana Syrikova, EKATERINA BOLOVTSOVA, Ono Kosuki, Andrea Piacquadio