• 0

    posted a message on On serializeNBT() call -> "Null string not allowed"

    Hello there,

    I want to test the save/write function from the nbt feature of a player simplyfied with this:

    	public void onPlayerLoggedInEvent(PlayerLoggedInEvent event) {
                    //load stuff with deserializeNBT()
                    //print original nbt
                    //change nbt to something different
    		event.player.serializeNBT(); //<-- exception here
                    //deserializeNBT stuff again
                    //read changes and print

     But I'll get a NullPointerException:

    java.lang.NullPointerException: Null string not allowed
    	at java.util.Objects.requireNonNull(Unknown Source)
    	at net.minecraft.nbt.NBTTagString.<init>(NBTTagString.java:20)
    	at net.minecraft.nbt.NBTTagCompound.setString(NBTTagCompound.java:172)
    	at net.minecraft.entity.Entity.serializeNBT(Entity.java:3574)

     I attached the capability normally to the player with the AttachCapabilitiesEvent.


    The provider also looks quite normal to me:

    	private final ITeleportCapability cap;
    	private static final DefaultTeleportStorage<ITeleportCapability> STORAGE 
                       = new DefaultTeleportStorage<>();
    	public NBTBase serializeNBT() {
    		return STORAGE.writeNBT(CAPABILITY_TELEPORT, cap, null);

     The writeNBT method from DefaultTeleportStorage looks like this:

    	public NBTBase writeNBT(Capability<T> capability, T instance, EnumFacing side) {
    		if((instance instanceof ITeleportCapability) == false) {
    			throw new RuntimeException(instance.getClass().getName() 
                             + "does not implement ITeleportCapability");
    		NBTTagCompound nbt = new NBTTagCompound();
    		ITeleportCapability cap = (ITeleportCapability) instance;
    		nbt.setTag("integerPartition", new NBTTagInt(instance.getFlags()));
    		return nbt;

    Does somebody know what I am doing wrong?
    Thank you in advantage!

    Posted in: Mod Development
  • To post a comment, please or register a new account.