From caadcfe9db9b9d791ac3babeb1298eee3c72d2a4 Mon Sep 17 00:00:00 2001 From: Nikita Edel Date: Wed, 11 Mar 2026 03:45:56 +0100 Subject: [PATCH] faulty casts of templated classes --- .../Common/GameRules/ConsoleSchematicFile.cpp | 23 ++++++++++++------- .../TileEntities/BrewingStandTileEntity.cpp | 9 ++++---- .../Blocks/TileEntities/ChestTileEntity.cpp | 10 +++++--- .../Blocks/TileEntities/FurnaceTileEntity.cpp | 9 +++++--- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp index f8af5039a..c4111da11 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp @@ -109,13 +109,15 @@ void ConsoleSchematicFile::load(DataInputStream *dis) } // READ TAGS // + // 4jcraft, fixed cast of templated List to get the tag list + // and cast it to CompoundTag inside the loop CompoundTag *tag = NbtIo::read(dis); - ListTag *tileEntityTags = (ListTag *) tag->getList(L"TileEntities"); + ListTag *tileEntityTags = tag->getList(L"TileEntities"); if (tileEntityTags != NULL) { for (int i = 0; i < tileEntityTags->size(); i++) { - CompoundTag *teTag = tileEntityTags->get(i); + CompoundTag *teTag = (CompoundTag*) tileEntityTags->get(i); std::shared_ptr te = TileEntity::loadStatic(teTag); if(te == NULL) @@ -131,18 +133,23 @@ void ConsoleSchematicFile::load(DataInputStream *dis) } } } - ListTag *entityTags = (ListTag *) tag->getList(L"Entities"); + + // 4jcraft, fixed cast of templated List to get the tag list + // and cast it to CompoundTag inside the loop + ListTag *entityTags = tag->getList(L"Entities"); if (entityTags != NULL) { for (int i = 0; i < entityTags->size(); i++) { - CompoundTag *eTag = entityTags->get(i); + CompoundTag *eTag = (CompoundTag*) entityTags->get(i); eINSTANCEOF type = EntityIO::getType(eTag->getString(L"id")); - ListTag *pos = (ListTag *) eTag->getList(L"Pos"); - double x = pos->get(0)->data; - double y = pos->get(1)->data; - double z = pos->get(2)->data; + // 4jcraft, same here + ListTag *pos = eTag->getList(L"Pos"); + + double x = ((DoubleTag*) pos->get(0))->data; + double y = ((DoubleTag*) pos->get(1))->data; + double z = ((DoubleTag*) pos->get(2))->data; if( type == eTYPE_PAINTING || type == eTYPE_ITEM_FRAME ) { diff --git a/Minecraft.World/Blocks/TileEntities/BrewingStandTileEntity.cpp b/Minecraft.World/Blocks/TileEntities/BrewingStandTileEntity.cpp index c035176d7..9a9971b25 100644 --- a/Minecraft.World/Blocks/TileEntities/BrewingStandTileEntity.cpp +++ b/Minecraft.World/Blocks/TileEntities/BrewingStandTileEntity.cpp @@ -283,12 +283,13 @@ void BrewingStandTileEntity::load(CompoundTag *base) { TileEntity::load(base); - ListTag *inventoryList = (ListTag *) base->getList(L"Items"); - delete [] items.data; + ListTag *inventoryList = base->getList(L"Items"); + + delete [] items.data; items = ItemInstanceArray(getContainerSize()); for (int i = 0; i < inventoryList->size(); i++) { - CompoundTag *tag = inventoryList->get(i); + CompoundTag *tag = (CompoundTag*) inventoryList->get(i); int slot = tag->getByte(L"Slot"); if (slot >= 0 && slot < items.length) items[slot] = ItemInstance::fromTag(tag); } @@ -430,4 +431,4 @@ std::shared_ptr BrewingStandTileEntity::clone() } } return result; -} \ No newline at end of file +} diff --git a/Minecraft.World/Blocks/TileEntities/ChestTileEntity.cpp b/Minecraft.World/Blocks/TileEntities/ChestTileEntity.cpp index 834ff4ed5..820aa482d 100644 --- a/Minecraft.World/Blocks/TileEntities/ChestTileEntity.cpp +++ b/Minecraft.World/Blocks/TileEntities/ChestTileEntity.cpp @@ -95,7 +95,11 @@ int ChestTileEntity::getName() void ChestTileEntity::load(CompoundTag *base) { TileEntity::load(base); - ListTag *inventoryList = (ListTag *) base->getList(L"Items"); + + // 4jcraft, fixed cast of templated List to get the tag list + // and cast it to CompoundTag inside the loop + ListTag *inventoryList = base->getList(L"Items"); + if( items ) { delete [] items->data; @@ -104,7 +108,7 @@ void ChestTileEntity::load(CompoundTag *base) items = new ItemInstanceArray(getContainerSize()); for (int i = 0; i < inventoryList->size(); i++) { - CompoundTag *tag = inventoryList->get(i); + CompoundTag *tag = (CompoundTag*) inventoryList->get(i); unsigned int slot = tag->getByte(L"Slot") & 0xff; if (slot >= 0 && slot < items->length) (*items)[slot] = ItemInstance::fromTag(tag); } @@ -286,4 +290,4 @@ std::shared_ptr ChestTileEntity::clone() } } return result; -} \ No newline at end of file +} diff --git a/Minecraft.World/Blocks/TileEntities/FurnaceTileEntity.cpp b/Minecraft.World/Blocks/TileEntities/FurnaceTileEntity.cpp index 879f13237..39aa67b5b 100644 --- a/Minecraft.World/Blocks/TileEntities/FurnaceTileEntity.cpp +++ b/Minecraft.World/Blocks/TileEntities/FurnaceTileEntity.cpp @@ -100,11 +100,14 @@ int FurnaceTileEntity::getName() void FurnaceTileEntity::load(CompoundTag *base) { TileEntity::load(base); - ListTag *inventoryList = (ListTag *) base->getList(L"Items"); + // 4jcraft, fixed cast of templated List to get the tag list + // and cast it to CompoundTag inside the loop + ListTag *inventoryList = base->getList(L"Items"); + items = new ItemInstanceArray(getContainerSize()); for (int i = 0; i < inventoryList->size(); i++) { - CompoundTag *tag = inventoryList->get(i); + CompoundTag *tag = (CompoundTag*) inventoryList->get(i); unsigned int slot = tag->getByte(L"Slot"); if (slot >= 0 && slot < items->length) (*items)[slot] = ItemInstance::fromTag(tag); } @@ -347,4 +350,4 @@ std::shared_ptr FurnaceTileEntity::clone() } } return result; -} \ No newline at end of file +}