Hello. I have a capability that is attached to all entities in my world and it works great. Here is the problem, in the method that reads the data from NBT I need an instance of the entity the capability is attached to in order to properly initialize one of the fields that the capability contains. Is there a getter method I could use to get the entity? Here is what I have for me storage class:
public class EntityMs3DataStorage implements IStorage<IEntityMs3Data> {
@Override
public NBTBase writeNBT(Capability<IEntityMs3Data> capability, IEntityMs3Data instance, EnumFacing side) {
NBTTagCompound tag = new NBTTagCompound();
// Write the attached scripts.
NBTTagList nbtList = new NBTTagList();
for(AttachedScript as : instance.getScriptList()) {
nbtList.appendTag(as.getLocation().writeToNbt());
}
tag.setTag("scriptList", nbtList);
return tag;
}
@Override
public void readNBT(Capability<IEntityMs3Data> capability, IEntityMs3Data instance, EnumFacing side, NBTBase nbt){
NBTTagCompound tag = (NBTTagCompound) nbt;
// Read the attached scripts.
NBTTagList nbtList = tag.getTagList("scriptList", 10);
AttachedScriptList list = instance.getScriptList();
for (int i = 0; i < nbtList.tagCount(); i++) {
// Here is where I need a reference to the entity.
// To load a script, I need to know what entity the script is attached to.
list.add(GET_ENTITY(), new AttachedScript(nbtList.getCompoundTagAt(i)));
}
}
}
Hello. I have a capability that is attached to all entities in my world and it works great. Here is the problem, in the method that reads the data from NBT I need an instance of the entity the capability is attached to in order to properly initialize one of the fields that the capability contains. Is there a getter method I could use to get the entity? Here is what I have for me storage class:
Thank you.