实体设置为NoAI 1.16.1

问题描述

我无法将这些entityTag绑定到我的实体。有人可以帮忙吗?这在1.12中有效,但在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;
    }

谢谢

解决方法

在PaperMC / Spigot(1.16.1)方法中,设置实体的NBT数据为: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;
}

并且您不必与NBT合作,只要您能够将此实体转换为任何固有的实体即可。为此提供了一种方法:EntityInsentient#setNoAI