Metadata in EnityZombie

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

HamAndRock

New Member
Mar 11, 2017
5
0
0
23
Good day skript community. Few days back i started with NMS part of Minecraft i want to add totally customizable entities. Now i only need to check from config when spawning them what behaviour set them. So i store the ID/Name of entity in it's metadata.

Java:
@Override
    public void spawnEntity(Object entity, Location loc, String ID) {
        net.minecraft.server.v1_11_R1.Entity ent = (net.minecraft.server.v1_11_R1.Entity) entity;
        ent.getBukkitEntity().setMetadata("ID", new FixedMetadataValue(AnerCraftRPG.getInstance(),ID));
        ent.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
        ((CraftWorld)loc.getWorld()).getHandle().addEntity(ent);
        System.out.println(ent.getBukkitEntity().getMetadata("ID").get(0).asString()); //Return ID
    }

Before this i create a new instance of customZombie class - That's works nice. But problem is when i try to acces the MetaData value from the customZombie class.

Java:
public class customZombie extends EntityZombie {

    public customZombie(World world) {
        super(world);
    }

    @Override
    protected void r() {
        if (!AnerCraftRPG.mobs.getYml().getBoolean("Customer.Pushable")) {
            return;
        } else {
            super.r();
        }
    }

    @Override
    protected void i() { //This trigger when the entity is initialized
        System.out.println(this.getBukkitEntity().getMetadata("ID")); //Return empty array
        super.i();
    }
}

Can you please help me ?
Thanks for any help, HamAndRock.
 
I already solved the problem by adding ID to Queue and then when create a class looking into that Queue and get current ID. Problem was taht the class was initialized before the Metada was set :emoji_slight_smile:.

Sorry, for late answear.