#ifndef ITEM_DEPLOYER_HPP_
#define ITEM_DEPLOYER_HPP_

#include <Block/SpriteBlock/SpriteBlock.hpp>
#include <Block/MachineBlockMixin.hpp>
#include <Machine/MItemDeployer/MItemDeployer.hpp>

class ItemDeployer : public SpriteBlock, public MachineBlockMixin<MItemDeployer>
{
private:
    /*

        #           Item Deployer Meta Byte
        +-------+---+---+---+---+---+---+---+---+
        | Bit   | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
        +-------+---+---+---+---+---+---+---+---+
        | Field |   |   |use| A | frame | orient|
        +-------+---+---+---+---+---+---+---+---+

        orient
            The side towards which the conveyor belt points.
        
        frame
            The frame offset to apply to the animation.
        
        A
            If set, the belt is active.
        
        use
            The side of the other axis, on which the item will be used.
            (0 = negative, 1 = positive).

    */

    static constexpr uint8_t metaActive = 1 << 4;
    static constexpr uint8_t metaUseSign = 1 << 5;
    static constexpr uint8_t numStates = 1 << 6;

    static constexpr Side getMetaOrientation(uint8_t meta)
    {
        return Side(meta & 3);
    }

    static constexpr int getMetaFrameOffset(uint8_t meta)
    {
        return (meta >> 2) & 3;
    }

    static const std::vector<std::string>& getStateNames();

public:
    ItemDeployer(std::string name);

    virtual bool canManuallyDig() override;
    virtual void onInteract(LocalWorld &world, Player &player, glm::ivec3 pos, Side side, const RGBABytes &collisionKey) override;
    virtual bool canPlace(LocalWorld &world, IWorldActor &actor, glm::ivec3 pos, Side side, uint8_t &meta) override;

    friend class MItemDeployer;
};

#endif