#include <MaceratorRule/OreToDustMaceratorRule/OreToDustMaceratorRule.hpp>
#include <Item/StatefulItem/BlockItem/BlockItem.hpp>
#include <ItemRegistry/ItemRegistry.hpp>

ItemStack OreToDustMaceratorRule::getMaceratorOutput(ItemStack &input)
{
    BlockItem *blockItem = input.getItemAs<BlockItem>();
    if (blockItem == nullptr)
    {
        return ItemStack();
    }

    Block &block = blockItem->getBlockInStack(input);
    if (!block.isSuffixed("Ore"))
    {
        return ItemStack();
    }

    std::string dustName = block.name.substr(0, block.name.size()-3) + "Dust";
    if (itemRegistry.getItemByName(dustName) == nullptr)
    {
        return ItemStack();
    }

    return ItemStack(dustName, 2);
}