Fixed NPE in writeNBT