faulty casts of templated classes

This commit is contained in:
Nikita Edel 2026-03-11 03:45:56 +01:00
parent e76ec32824
commit caadcfe9db
4 changed files with 33 additions and 18 deletions

View file

@ -109,13 +109,15 @@ void ConsoleSchematicFile::load(DataInputStream *dis)
} }
// READ TAGS // // 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); CompoundTag *tag = NbtIo::read(dis);
ListTag<CompoundTag> *tileEntityTags = (ListTag<CompoundTag> *) tag->getList(L"TileEntities"); ListTag<Tag> *tileEntityTags = tag->getList(L"TileEntities");
if (tileEntityTags != NULL) if (tileEntityTags != NULL)
{ {
for (int i = 0; i < tileEntityTags->size(); i++) for (int i = 0; i < tileEntityTags->size(); i++)
{ {
CompoundTag *teTag = tileEntityTags->get(i); CompoundTag *teTag = (CompoundTag*) tileEntityTags->get(i);
std::shared_ptr<TileEntity> te = TileEntity::loadStatic(teTag); std::shared_ptr<TileEntity> te = TileEntity::loadStatic(teTag);
if(te == NULL) if(te == NULL)
@ -131,18 +133,23 @@ void ConsoleSchematicFile::load(DataInputStream *dis)
} }
} }
} }
ListTag<CompoundTag> *entityTags = (ListTag<CompoundTag> *) tag->getList(L"Entities");
// 4jcraft, fixed cast of templated List to get the tag list
// and cast it to CompoundTag inside the loop
ListTag<Tag> *entityTags = tag->getList(L"Entities");
if (entityTags != NULL) if (entityTags != NULL)
{ {
for (int i = 0; i < entityTags->size(); i++) 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")); eINSTANCEOF type = EntityIO::getType(eTag->getString(L"id"));
ListTag<DoubleTag> *pos = (ListTag<DoubleTag> *) eTag->getList(L"Pos");
double x = pos->get(0)->data; // 4jcraft, same here
double y = pos->get(1)->data; ListTag<Tag> *pos = eTag->getList(L"Pos");
double z = pos->get(2)->data;
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 ) if( type == eTYPE_PAINTING || type == eTYPE_ITEM_FRAME )
{ {

View file

@ -283,12 +283,13 @@ void BrewingStandTileEntity::load(CompoundTag *base)
{ {
TileEntity::load(base); TileEntity::load(base);
ListTag<CompoundTag> *inventoryList = (ListTag<CompoundTag> *) base->getList(L"Items"); ListTag<Tag> *inventoryList = base->getList(L"Items");
delete [] items.data;
delete [] items.data;
items = ItemInstanceArray(getContainerSize()); items = ItemInstanceArray(getContainerSize());
for (int i = 0; i < inventoryList->size(); i++) 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"); int slot = tag->getByte(L"Slot");
if (slot >= 0 && slot < items.length) items[slot] = ItemInstance::fromTag(tag); if (slot >= 0 && slot < items.length) items[slot] = ItemInstance::fromTag(tag);
} }

View file

@ -95,7 +95,11 @@ int ChestTileEntity::getName()
void ChestTileEntity::load(CompoundTag *base) void ChestTileEntity::load(CompoundTag *base)
{ {
TileEntity::load(base); TileEntity::load(base);
ListTag<CompoundTag> *inventoryList = (ListTag<CompoundTag> *) base->getList(L"Items");
// 4jcraft, fixed cast of templated List to get the tag list
// and cast it to CompoundTag inside the loop
ListTag<Tag> *inventoryList = base->getList(L"Items");
if( items ) if( items )
{ {
delete [] items->data; delete [] items->data;
@ -104,7 +108,7 @@ void ChestTileEntity::load(CompoundTag *base)
items = new ItemInstanceArray(getContainerSize()); items = new ItemInstanceArray(getContainerSize());
for (int i = 0; i < inventoryList->size(); i++) 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; unsigned int slot = tag->getByte(L"Slot") & 0xff;
if (slot >= 0 && slot < items->length) (*items)[slot] = ItemInstance::fromTag(tag); if (slot >= 0 && slot < items->length) (*items)[slot] = ItemInstance::fromTag(tag);
} }

View file

@ -100,11 +100,14 @@ int FurnaceTileEntity::getName()
void FurnaceTileEntity::load(CompoundTag *base) void FurnaceTileEntity::load(CompoundTag *base)
{ {
TileEntity::load(base); TileEntity::load(base);
ListTag<CompoundTag> *inventoryList = (ListTag<CompoundTag> *) base->getList(L"Items"); // 4jcraft, fixed cast of templated List to get the tag list
// and cast it to CompoundTag inside the loop
ListTag<Tag> *inventoryList = base->getList(L"Items");
items = new ItemInstanceArray(getContainerSize()); items = new ItemInstanceArray(getContainerSize());
for (int i = 0; i < inventoryList->size(); i++) 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"); unsigned int slot = tag->getByte(L"Slot");
if (slot >= 0 && slot < items->length) (*items)[slot] = ItemInstance::fromTag(tag); if (slot >= 0 && slot < items->length) (*items)[slot] = ItemInstance::fromTag(tag);
} }