From 087064999473e83389fb28d74ebcaaf5d119320a Mon Sep 17 00:00:00 2001 From: Mattes D Date: Mon, 7 Nov 2016 21:16:55 +0100 Subject: Fixed TrappedChest saving. (#3423) Vanilla uses "Chest" in NBT for trapped chests. --- src/WorldStorage/WSSAnvil.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/WorldStorage/WSSAnvil.cpp') diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 3fd104004..2bf11d3f4 100755 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -980,13 +980,24 @@ cBlockEntity * cWSSAnvil::LoadBrewingstandFromNBT(const cParsedNBT & a_NBT, int cBlockEntity * cWSSAnvil::LoadChestFromNBT(const cParsedNBT & a_NBT, int a_TagIdx, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_ChestBlockType) { // Check if the data has a proper type: - // TODO: Does vanilla use "TrappedChest" or not? MCWiki says no, but previous code says yes - // Ref.: http://minecraft.gamepedia.com/Trapped_Chest - // https://github.com/cuberite/cuberite/blob/d0551e2e0a98a28f31a88d489d17b408e4a7d38d/src/WorldStorage/WSSAnvil.cpp#L637 - if (!CheckBlockEntityType(a_NBT, a_TagIdx, "Chest") && !CheckBlockEntityType(a_NBT, a_TagIdx, "TrappedChest")) + // Note that older Cuberite code used "TrappedChest" for trapped chests; new code mimics vanilla and uses "Chest" throughout, but we allow migration here: + if (a_NBT.GetType(a_TagIdx) != TAG_Compound) + { + return nullptr; + } + int TagID = a_NBT.FindChildByName(a_TagIdx, "id"); + if ((TagID < 0) || (a_NBT.GetType(TagID) != TAG_String)) { return nullptr; } + auto BlockEntityType = a_NBT.GetString(TagID); + if ((BlockEntityType != "Chest") && (BlockEntityType != "TrappedChest")) + { + LOGWARNING("Block entity type mismatch at {%d, %d, %d}: got \"%s\", expected \"Chest\". Chest contents will be lost.", + a_BlockX, a_BlockY, a_BlockZ, BlockEntityType.c_str() + ); + return nullptr; + } int Items = a_NBT.FindChildByName(a_TagIdx, "Items"); if ((Items < 0) || (a_NBT.GetType(Items) != TAG_List)) -- cgit v1.2.3