Solved Clone entity data into existing entities

Discussion in 'Spigot Plugin Development' started by HotDoctor, Jul 18, 2020.

Thread Status:
Not open for further replies.
  1. Title says everything that I need..

    For example, if I make an ArmorStand with custom name, if is small, colored leather armor... how to clone it and paste it in another ArmorStand? or I have to make the same code as I did before with the first ArmorStand? there is a way for clone entities?
     
  2. Why exactly are you doing this?
     
  3. Depends on what it is exactly you want... if you simply want to spawn an ArmorStand that has certain attributes every time you spawn the stand, factor out the initialization in some sort of method:
    Code (Java):
    public void initStand(ArmorStand stand) {
        stand.setVisible(false);
        stand.setSmall(true);
        ...
    }
    and then just call it whenever you spawn a stand:
    Code (Java):
    ArmorStand as = world.spawn(loc, ArmorStand.class);
    initStand(as);
    or, fancier:
    Code (Java):
    ArmorStand as = world.spawn(loc, ArmorStand.class, this::initStand);
    If you want to copy your stand from a random one, bukkit/spigot offers nothing as far as I can tell. You‘ll have to either use NMS or copy all relevant attributes yourself.
     
    • Friendly Friendly x 1
  4. Thanks alot, this worked fdor me
     
Thread Status:
Not open for further replies.