#include <Block/SpriteBlock/BasicBlock/Pebble/Pebble.hpp>
#include <World/World.hpp>
#include <World/LocalWorld/LocalWorld.hpp>

Pebble::Pebble(std::string name) : BasicBlock(name, "Pebble", 8.0f, "pebble", {3, 3, 0, 5, 5, 2})
{
    withBreakingSound(Sound::NONE);
}

bool Pebble::canPlace(LocalWorld &world, IWorldActor &actor, glm::ivec3 pos, Side side, uint8_t &meta)
{
    Block *block = world.getBlockAt(pos + glm::ivec3(0, 0, -1));
    return block != nullptr && block->isFullyOpaque();
}

void Pebble::onNeighborUpdated(LocalWorld &world, glm::ivec3 pos, Side side)
{
    // If the block below us changed, break.
    if (side == Side::Bottom && !world.getBlockAt(pos + glm::ivec3(0, 0, -1))->isFullyOpaque())
    {
        world.breakBlock(pos);
    }
}

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

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