I'm in 1.19.2 of Java edition. I would like to clone something in random coordinates so I searched for plugins or answers but I don't found anything. I don't realy know how to do something like that so I need some help, thanks in advance !
1 Answer
Because you cannot use variables in commands, the way to do it is to execute from an entity that you positioned randomly.
Here are relevant answers to various parts of this question:
- Getting a random number: What sources of randomness can be made with commands in Minecraft?
- Teleporting an entity to a number in a scoreboard: https://gaming.stackexchange.com/a/339010/172377
Now that you've teleported that entity to the random location, you can now use /clone
to clone something that is positioned at a fixed location to the entity.
/execute at <the entity> run clone <coordinates of area to clone> ~ ~ ~
Potential pitfalls
Depending on your situation, there are a bunch of things you need to keep in mind:
- Is the area where you want to clone to loaded? If not, you'll run into multiple issues:
- You'll loose the entity if you didn't use functions
as
the entity (once it's in unloaded chunks it won't be found by@e
anymore). - You aren't able to clone to an unloaded area. You can alleviate that by using
/forceload
to load the area and checking withexecute if block
(or if you're in 1.19.4+execute if loaded
) if it has finished loading. Make sure to unload the area again afterwards.
- You'll loose the entity if you didn't use functions
- Having source and destination be variable. If you want to have two random positions to clone from and to, you'll need to take a step in between: Cloning it from the first entity to a known fixed position, then cloning it from there to the second entity. Same limitations on loaded world apply as above.
Pos
NBT of an entity, clone to that entity. If you want source AND destination to be variable, you need two entities, clone from first to something fixed (0 0 0 or so) and from there to second. Chunks need to be loaded, of course, otherwise it gets a bit complicated withforceload
and checking when that is actually finished withexecute if loaded
(new in 1.19.4 snapshots) or with some trickery (Google helps with that, I thinkexecute if block
might do it). Someone with more spare time can write a proper answer.