Browse Source

Added code to fix broken Minecraft level.dat files with Inventory list type of byte.

preble 13 years ago
parent
commit
de26cd1000
2 changed files with 13 additions and 0 deletions
  1. 9 0
      Classes/IJMinecraftLevel.m
  2. 4 0
      Classes/NBTContainer.m

+ 9 - 0
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:

+ 4 - 0
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);