#include <Block/SpriteBlock/BasicBlock/GrassBlock/GrassBlock.hpp>
#include <BlockRegistry/BlockRegistry.hpp>
#include <World/LocalWorld/LocalWorld.hpp>
#include <TextureVoxelizer/TextureVoxelizer.hpp>

GrassBlock::GrassBlock(std::string name) :
    BasicBlock(name, "Grass", 90.0f, {
        "grass/side", "grass/side", "grass/side", "grass/side",
        "dirt", "grass/top"
    })
{
    withPlacingSound(Sound::placingDust);
    withBreakingSound(Sound::breakingDust);
    withFallingSound(Sound::fallingOnGrass);

    withFootstepSound(Sound::grassFootsteps1);
    withFootstepSound(Sound::grassFootsteps2);
    withFootstepSound(Sound::grassFootsteps3);
}

void GrassBlock::getHarvestedStacks(LocalWorld &world, glm::ivec3 pos, std::vector<ItemStack> &stacks)
{
    stacks.push_back(blockRegistry.getBlockByName("main:dirt").toItemStack(1));
}

bool GrassBlock::canManuallyDig()
{
    return true;
}

void GrassBlock::onNeighborUpdated(LocalWorld &world, glm::ivec3 pos, Side side)
{
    if (side == Side::Top)
    {
        // If a fully opaque block is placed above us, turn into dirt.
        if (world.getBlockAt(pos + glm::ivec3(0, 0, 1))->isFullyOpaque())
        {
            world.setBlockAt(pos, "main:dirt");
            return;
        }
    }
}

Sound& GrassBlock::getManualDiggingSound()
{
    return Sound::dirtDigging;
}