/* * ===================================================================================== * * Filename: Registry.cpp * * Description: * * Created: 23/06/2018 22:43:56 * * Author: Quentin Bazin, * * ===================================================================================== */ #include "ItemBlock.hpp" #include "Registry.hpp" #include "BlockFurnace.hpp" #include "BlockWater.hpp" #include "BlockWorkbench.hpp" Registry *Registry::s_instance = nullptr; void Registry::registerBlocks() { registerBlock(BlockType::Air, 0); registerBlock(BlockType::Dirt, 37); registerBlock(BlockType::Cobblestone, 38); registerBlock(BlockType::Grass, 226); registerBlock(BlockType::Leaves, 266); registerBlock(BlockType::Wood, 277); registerBlock(BlockType::Stone, 402); registerBlock(BlockType::Sand, 369); registerBlock(); registerBlock(BlockType::Glass, 168); registerBlock(BlockType::CoalOre, 36); registerBlock(BlockType::Planks, 316); registerBlock(BlockType::Glowstone, 218); registerBlock(); registerBlock(); registerBlock(BlockType::IronOre, 254); } void Registry::registerItems() { registerItem(ItemType::Air, BlockType::Air, ""); registerItem(ItemType::Dirt, BlockType::Dirt, "Dirt"); registerItem(ItemType::Cobblestone, BlockType::Cobblestone, "Cobblestone"); registerItem(ItemType::Grass, BlockType::Grass, "Grass"); registerItem(ItemType::Leaves, BlockType::Leaves, "Leaves"); registerItem(ItemType::Wood, BlockType::Wood, "Wood"); registerItem(ItemType::Stone, BlockType::Stone, "Stone"); registerItem(ItemType::Sand, BlockType::Sand, "Sand"); registerItem(ItemType::Water, BlockType::Water, "Water"); registerItem(ItemType::Glass, BlockType::Glass, "Glass"); registerItem(ItemType::CoalOre, BlockType::CoalOre, "Coal Ore"); registerItem(ItemType::Planks, BlockType::Planks, "Planks"); registerItem(ItemType::Glowstone, BlockType::Glowstone, "Glowstone"); registerItem(ItemType::Workbench, BlockType::Workbench, "Workbench"); registerItem(ItemType::Furnace, BlockType::Furnace, "Furnace"); registerItem(ItemType::IronOre, BlockType::IronOre, "Iron Ore"); registerItem(ItemType::Stick, 324, "Stick"); registerItem(ItemType::StoneAxe, 325, "Stone Axe"); registerItem(ItemType::StoneHoe, 326, "Stone Hoe"); registerItem(ItemType::StonePickaxe, 327, "Stone Pickaxe"); registerItem(ItemType::StoneShovel, 328, "Stone Shovel"); registerItem(ItemType::StoneSword, 329, "Stone Sword"); Item &itemCoal = registerItem(ItemType::Coal, 111, "Coal"); itemCoal.setIsFuel(true); itemCoal.setBurnTime(1600); registerItem(ItemType::IronIngot, 232, "Iron Ingot"); // FIXME: Move this to Application or load from XML file registerRecipes(); } void Registry::registerRecipes() { // m_recipes.emplace_back(std::array{2, 2, 0, 2, ItemType::Stick, 0, 0, ItemType::Stick, 0}, ItemStack{ItemType::StoneAxe}); // m_recipes.emplace_back(std::array{2, 2, 0, 0, ItemType::Stick, 0, 0, ItemType::Stick, 0}, ItemStack{ItemType::StoneHoe}); // m_recipes.emplace_back(std::array{2, 2, 2, 0, ItemType::Stick, 0, 0, ItemType::Stick, 0}, ItemStack{ItemType::StonePickaxe}); // m_recipes.emplace_back(std::array{0, 2, 0, 0, ItemType::Stick, 0, 0, ItemType::Stick, 0}, ItemStack{ItemType::StoneShovel}); // m_recipes.emplace_back(std::array{0, 2, 0, 0, 2, 0, 0, ItemType::Stick, 0}, ItemStack{ItemType::StoneSword}); // // m_recipes.emplace_back(std::array{ItemType::Wood, 0, 0, 0, 0, 0, 0, 0, 0}, ItemStack{ItemType::Planks, 4}, true); // m_recipes.emplace_back(std::array{ItemType::Planks, ItemType::Planks, 0, 0, 0, 0, 0, 0, 0}, ItemStack{ItemType::Stick, 4}, true); // // m_recipes.emplace_back(std::array{ // ItemType::Cobblestone, ItemType::Cobblestone, ItemType::Cobblestone, // ItemType::Cobblestone, 0, ItemType::Cobblestone, // ItemType::Cobblestone, ItemType::Cobblestone, ItemType::Cobblestone, // }, ItemStack{ItemType::Furnace}); // // // FIXME: This recipe will only for in the top-left corner // // Find a way to handle recipe size // m_recipes.emplace_back(std::array{ // ItemType::Planks, ItemType::Planks, 0, // ItemType::Planks, ItemType::Planks, 0, // 0, 0, 0 // }, ItemStack{ItemType::Workbench}); m_recipes.emplace_back(std::vector{ "##", "#|", " |" }, std::map>{ {'#', {ItemType::Cobblestone}}, {'|', {ItemType::Stick}}, }, ItemStack{ItemType::StoneAxe}); m_recipes.emplace_back(std::vector{ "##", " |", " |" }, std::map>{ {'#', {ItemType::Cobblestone}}, {'|', {ItemType::Stick}}, }, ItemStack{ItemType::StoneHoe}); m_recipes.emplace_back(std::vector{ "###", " | ", " | " }, std::map>{ {'#', {ItemType::Cobblestone}}, {'|', {ItemType::Stick}}, }, ItemStack{ItemType::StonePickaxe}); m_recipes.emplace_back(std::vector{ "#", "|", "|" }, std::map>{ {'#', {ItemType::Cobblestone}}, {'|', {ItemType::Stick}}, }, ItemStack{ItemType::StoneShovel}); m_recipes.emplace_back(std::vector{ "#", "#", "|" }, std::map>{ {'#', {ItemType::Cobblestone}}, {'|', {ItemType::Stick}}, }, ItemStack{ItemType::StoneSword}); m_recipes.emplace_back(std::vector{ "#", "#", }, std::map>{ {'#', {ItemType::Planks}}, }, ItemStack{ItemType::Stick, 4}); m_recipes.emplace_back(std::vector{ "#", }, std::map>{ {'#', {ItemType::Wood}}, }, ItemStack{ItemType::Planks, 4}); m_recipes.emplace_back(std::vector{ "##", "##", }, std::map>{ {'#', {ItemType::Planks}}, }, ItemStack{ItemType::Workbench}); m_recipes.emplace_back(std::vector{ "###", "# #", "###", }, std::map>{ {'#', {ItemType::Cobblestone}}, }, ItemStack{ItemType::Furnace}); } const CraftingRecipe *Registry::getRecipe(const Inventory &inventory) const { for (const CraftingRecipe &recipe : m_recipes) { if (recipe.isMatching(inventory)) return &recipe; } return nullptr; }