#ifndef SAPLING_HPP_
#define SAPLING_HPP_

#include <Block/SpriteBlock/SpriteBlock.hpp>
#include <Decoration/Tree/Tree.hpp>
#include <string>

class Sapling final : public SpriteBlock
{
private:
    /*
        #             Sapling Meta Byte
        +-------+---+---+---+---+---+---+---+---+
        | Bit   | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
        +-------+---+---+---+---+---+---+---+---+
        | Field |        Water level        | D |
        +-------+---+---+---+---+---+---+---+---+

        D
            If set, the sapling is dead.
    */

    Tree::Sculpture &sculpture;

    static constexpr uint32_t sigGrow = 0;
    static constexpr int growthTimeVariation = 60 * 3;
    static constexpr int growthTimePerMalnutrition = World::cycleDuration / 128;

    static constexpr uint8_t metaDead = 1;

public:
    Sapling(std::string name, std::string displayName, Tree::Sculpture &sculpture);

    virtual bool canManuallyDig() override;
    virtual bool canPlace(LocalWorld &world, IWorldActor &actor, glm::ivec3 pos, Side side, uint8_t &meta) override;
    virtual bool isIntersectedBy(World &world, glm::ivec3 pos, const BoundingBox<wfixed> &box) override;
    virtual void onNeighborUpdated(LocalWorld &world, glm::ivec3 pos, Side side) override;
    virtual void onPlaced(LocalWorld &world, Chunk &chunk, glm::ivec3 pos) override;
    virtual void onSignal(LocalWorld &world, glm::ivec3 pos, uint32_t code) override;
    virtual void getHarvestedStacks(LocalWorld &world, glm::ivec3 pos, std::vector<ItemStack> &stacks) override;
};

#endif