Entity set to NoAI 1.16.1

Viewed 550

I can't bound these entityTag to my entity. Can anybody help? This worked in 1.12 but not anymore in 1.16.1

public Builder setNoAI(boolean noAI) {
        NBTTagCompound tag = new NBTTagCompound();
        entityS.c(tag);
        tag.setBoolean("NoAI", noAI);
        EntityLiving el = (EntityLiving) entityS;
        el.a(tag);
        return this;
    }

Thanks

1 Answers

In PaperMC/Spigot (1.16.1) method to set NBT data of entity is: Entity#loadData.

public Builder setNoAI(boolean noAI) {
    // create tag, and set its data
    NBTTagCompound tag = new NBTTagCompound();
    tag.setBoolean("NoAI", noAI);
    
    // only then you can add those data to entity
    entityS.loadData(tag);
    // why did you recast this entity to EntityLiving and then called a?
    /*
    EntityLiving el = (EntityLiving) entityS;
    el.a(tag);
    */
    return this;
}

And you don't have to work with NBT, as long as you are able to cast this entity to any insentient entity. There's method provided for that: EntityInsentient#setNoAI

Related