#include <LiveSculptor/LiveSculptor.hpp>

LiveSculptor::LiveSculptor(LocalWorld &world, glm::ivec3 basePos, int maxHeight) : world(world)
{
    glm::ivec3 chunkBase;
    for (chunkBase.z = basePos.z & ~0xF; chunkBase.z >= basePos.z + maxHeight; chunkBase.z += 16)
    {
        for (chunkBase.x = (basePos.x - 8) & ~0xF; chunkBase.x < ((basePos.x + 8 + 15) & ~0xF); chunkBase.x += 16)
        {
            for (chunkBase.y = (basePos.y - 8) & ~0xF; chunkBase.y < ((basePos.y + 8 + 15) & ~0xF); chunkBase.y += 16)
            {
                auto chunk = world.requestChunk(chunkBase);
                if (!chunk->isReady())
                {
                    ready = false;
                    break;
                }
            }
        }
    }
}

bool LiveSculptor::isReady()
{
    return ready;
}

void LiveSculptor::place(glm::ivec3 pos, std::string name, uint8_t meta)
{
    world.setBlockAt(pos, name, meta);
}