#include <Block/SpriteBlock/FluidDispenser/FluidDispenser.hpp>
#include <Block/SpriteBlock/SpriteBlock.hpp>
#include <BoundingBox/BoundingBox.hpp>
#include <Side/Side.hpp>
#include <Utilities/Utilities.hpp>
#include <Entity/PhysicsEntity/CameraEntity/Player/Player.hpp>
#include <World/LocalWorld/LocalWorld.hpp>

FluidDispenser::FluidDispenser(std::string name) : SpriteBlock(
    name,
    "Fluid Dispenser",
    60.0f,
    {"outputWest", "outputEast", "outputSouth", "outputNorth", "outputBottom", "outputTop"}
)
{
    withMetalSounds();
}

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

void FluidDispenser::onInteract(LocalWorld &world, Player &player, glm::ivec3 pos, Side side, const RGBABytes &collisionKey)
{
    if (!player.isHoldingScrewdriver())
    {
        return;
    }

    world.setBlockMeta(pos, (*world.getBlockMeta(pos) + 1) % 6, true);
}

bool FluidDispenser::canPlace(LocalWorld &world, IWorldActor &actor, glm::ivec3 pos, Side side, uint8_t &meta)
{
    meta = side.opposite().asNumber();
    return true;
}
