From de26cd1000033d3a6049a13ab5193ec93823f938 Mon Sep 17 00:00:00 2001 From: preble Date: Thu, 14 Oct 2010 22:25:18 -0400 Subject: [PATCH] Added code to fix broken Minecraft level.dat files with Inventory list type of byte. --- Classes/IJMinecraftLevel.m | 9 +++++++++ Classes/NBTContainer.m | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/Classes/IJMinecraftLevel.m b/Classes/IJMinecraftLevel.m index bf308fa..ed598f9 100644 --- a/Classes/IJMinecraftLevel.m +++ b/Classes/IJMinecraftLevel.m @@ -56,6 +56,15 @@ { NSMutableArray *newChildren = [NSMutableArray array]; NBTContainer *inventoryList = [self inventoryList]; + + if (inventoryList.listType != NBTTypeCompound) + { + // There appears to be a bug in the way Minecraft writes empty inventory lists; it appears to + // set the list type to 'byte', so we will correct it here. + NSLog(@"%s Fixing inventory list type; was %d.", __PRETTY_FUNCTION__, inventoryList.listType); + inventoryList.listType = NBTTypeCompound; + } + for (IJInventoryItem *invItem in newInventory) { NSArray *listItems = [NSArray arrayWithObjects: diff --git a/Classes/NBTContainer.m b/Classes/NBTContainer.m index 10c9983..bfe9cc8 100644 --- a/Classes/NBTContainer.m +++ b/Classes/NBTContainer.m @@ -270,6 +270,10 @@ { [self appendDouble:[item doubleValue] toData:data]; } + else if (listType == NBTTypeByte) + { + [self appendByte:[item unsignedCharValue] toData:data]; + } else { NSLog(@"Unhandled list type: %d", listType);