#include <Block/SpriteBlock/Tulip/Tulip.hpp>
#include <World/World.hpp>
#include <World/LocalWorld/LocalWorld.hpp>

std::vector<Tulip::Sprite> Tulip::makeSprites()
{
    return std::vector<Sprite>{
        Sprite{
            {
                "<invalid>",
                "<invalid>",
                "<invalid>",
                "<invalid>",
                "<invalid>",
                "<invalid>",
            },
            {},
            "default"
        },
    };
}

Tulip::Tulip(std::string name) :
    SpriteBlock(
        name,
        "Tulip",
        1.0f,
        "<invalid>",
        makeSprites()
    )
{}

bool Tulip::canPlace(LocalWorld &world, IWorldActor &actor, glm::ivec3 pos, Side side, uint8_t &meta)
{
    Block *blockUnder = world.getBlockAt(pos + glm::ivec3(0, 0, -1));
    if (blockUnder == nullptr)
    {
        return false;
    }

    return blockUnder->name == "main:dirt" || blockUnder->name == "main:grass";
}

bool Tulip::isIntersectedBy(World &world, glm::ivec3 pos, const BoundingBox<wfixed> &box)
{
    return false;
}

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

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

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