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 //
// 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<CompoundTag> *tileEntityTags = (ListTag<CompoundTag> *) tag->getList(L"TileEntities");
ListTag<Tag> *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<TileEntity> te = TileEntity::loadStatic(teTag);
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)
{
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<DoubleTag> *pos = (ListTag<DoubleTag> *) 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<Tag> *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 )
{

View file

@ -283,12 +283,13 @@ void BrewingStandTileEntity::load(CompoundTag *base)
{
TileEntity::load(base);
ListTag<CompoundTag> *inventoryList = (ListTag<CompoundTag> *) base->getList(L"Items");
delete [] items.data;
ListTag<Tag> *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<TileEntity> BrewingStandTileEntity::clone()
}
}
return result;
}
}

View file

@ -95,7 +95,11 @@ int ChestTileEntity::getName()
void ChestTileEntity::load(CompoundTag *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 )
{
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<TileEntity> ChestTileEntity::clone()
}
}
return result;
}
}

View file

@ -100,11 +100,14 @@ int FurnaceTileEntity::getName()
void FurnaceTileEntity::load(CompoundTag *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());
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<TileEntity> FurnaceTileEntity::clone()
}
}
return result;
}
}