}
@SuppressWarnings("unchecked")
public static ManagedChunk loadChunk(CompoundTag tag, ChunkManager manager)
{
CompoundTag level = (CompoundTag) tag.get("Level");
ListTag<CompoundTag> sections = (ListTag<CompoundTag>) level.get("Sections");
IntArrayTag heightmap = (IntArrayTag) level.get("HeightMap");
ByteArrayTag biome = (ByteArrayTag) level.get("Biomes");
IntTag xPos = (IntTag) level.get("xPos");
IntTag zPos = (IntTag) level.get("zPos");
ManagedChunk chunk;
chunk = new ManagedChunk(xPos.data, zPos.data, heightmap.data, biome.data, manager);
// TODO: create ManagedSection to catch Section changes?
// TODO: alternatively, hide sections from interface
chunk.loadSections(sections);
EntityFactory factory = manager.getEntityFactory();
Tag tagEntities = level.get("Entities");
if(tagEntities != null)
{
ListTag<CompoundTag> list = (ListTag<CompoundTag>)tagEntities;
for(int i=0; i<list.size(); i++)
chunk.entities.add(factory.createEntity(list.get(i)));
}
Tag tagTileEntities = level.get("TileEntities");
if(tagEntities != null)
{
ListTag<CompoundTag> list = (ListTag<CompoundTag>)tagTileEntities;
for(int i=0; i<list.size(); i++)
chunk.tileEntities.add(factory.createTileEntity(list.get(i)));