#include <Block/SpriteBlock/TallGrass/TallGrass.hpp>
#include <World/LocalWorld/LocalWorld.hpp>
#include <BlockRegistry/BlockRegistry.hpp>

TallGrass::TallGrass(std::string name) : SpriteBlock(
    name,
    "Tall grass",
    1.0f,
    "<invalid>",
    std::vector<Sprite>{
        Sprite{
            {"<invalid>", "<invalid>", "<invalid>", "<invalid>", "<invalid>", "<invalid>"},
            {},
            "default"
        }
    }
)
{}

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

bool TallGrass::isIntersectedBy(World &world, glm::ivec3 pos, const BoundingBox<wfixed> &box)
{
    // Allow players to walk through tall grass.
    return false;
}

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

void TallGrass::onNeighborUpdated(LocalWorld &world, glm::ivec3 pos, Side side)
{
    // If the block below us changed, break.
    if (side == Side::Bottom)
    {
        world.breakBlock(pos);
    }
}

bool TallGrass::canSweepAway()
{
    return true;
}