/** * CRAFTING RECIPES * Defines all crafting recipes for basic items and tools * Format: { id, name, ingredients: [{item, amount}], result: {item, amount}, category } */ const CRAFTING_RECIPES = { // ================================== // BONE TOOLS (New!) // ================================== 'bone_pickaxe': { id: 'bone_pickaxe', name: 'Bone Pickaxe', ingredients: [ { item: 'bone', amount: 3 }, { item: 'wood', amount: 2 } ], result: { item: 'bone_pickaxe', amount: 1 }, category: 'tools', description: 'Weak pickaxe made from bones. Better than nothing!' }, 'bone_axe': { id: 'bone_axe', name: 'Bone Axe', ingredients: [ { item: 'bone', amount: 3 }, { item: 'wood', amount: 2 } ], result: { item: 'bone_axe', amount: 1 }, category: 'tools', description: 'Crude axe for chopping wood.' }, 'bone_hoe': { id: 'bone_hoe', name: 'Bone Hoe', ingredients: [ { item: 'bone', amount: 2 }, { item: 'wood', amount: 2 } ], result: { item: 'bone_hoe', amount: 1 }, category: 'tools', description: 'Farming tool for tilling soil.' }, 'bone_sword': { id: 'bone_sword', name: 'Bone Sword', ingredients: [ { item: 'bone', amount: 2 }, { item: 'wood', amount: 1 } ], result: { item: 'bone_sword', amount: 1 }, category: 'weapons', description: 'Sharp bone weapon. +5 damage.' }, // ================================== // BASIC TOOLS (Existing) // ================================== 'wooden_pickaxe': { id: 'wooden_pickaxe', name: 'Wooden Pickaxe', ingredients: [ { item: 'wood', amount: 3 }, { item: 'stick', amount: 2 } ], result: { item: 'wooden_pickaxe', amount: 1 }, category: 'tools', description: 'Basic mining tool.' }, 'stone_pickaxe': { id: 'stone_pickaxe', name: 'Stone Pickaxe', ingredients: [ { item: 'stone', amount: 3 }, { item: 'stick', amount: 2 } ], result: { item: 'stone_pickaxe', amount: 1 }, category: 'tools', description: 'Improved mining tool.' }, // ================================== // BASIC ITEMS // ================================== 'stick': { id: 'stick', name: 'Stick', ingredients: [ { item: 'wood', amount: 1 } ], result: { item: 'stick', amount: 4 }, category: 'materials', description: 'Basic crafting material.' }, 'torch': { id: 'torch', name: 'Torch', ingredients: [ { item: 'stick', amount: 1 }, { item: 'coal', amount: 1 } ], result: { item: 'torch', amount: 4 }, category: 'lighting', description: 'Provides light in darkness.' }, // ================================== // BUILDINGS // ================================== 'chest': { id: 'chest', name: 'Chest', ingredients: [ { item: 'wood', amount: 8 } ], result: { item: 'chest', amount: 1 }, category: 'storage', description: 'Storage container.' }, 'furnace': { id: 'furnace', name: 'Furnace', ingredients: [ { item: 'stone', amount: 8 }, { item: 'coal', amount: 4 } ], result: { item: 'furnace', amount: 1 }, category: 'workstation', description: 'Smelts ores into bars.' } }; /** * Helper function to get recipe by ID */ function getCraftingRecipe(recipeId) { return CRAFTING_RECIPES[recipeId] || null; } /** * Helper function to check if player has ingredients */ function canCraft(recipeId, playerInventory) { const recipe = getCraftingRecipe(recipeId); if (!recipe) return false; for (const ingredient of recipe.ingredients) { const playerAmount = playerInventory.getItemCount(ingredient.item); if (playerAmount < ingredient.amount) { return false; // Missing ingredient } } return true; } /** * Helper function to craft item (consumes ingredients) */ function craftItem(recipeId, playerInventory) { if (!canCraft(recipeId, playerInventory)) { console.warn('⚠️ Cannot craft - missing ingredients!'); return false; } const recipe = getCraftingRecipe(recipeId); // Consume ingredients for (const ingredient of recipe.ingredients) { playerInventory.removeItem(ingredient.item, ingredient.amount); } // Add result playerInventory.addItem(recipe.result.item, recipe.result.amount); console.log(`✅ Crafted ${recipe.result.amount}x ${recipe.name}`); return true; } // Export for use in other systems if (typeof module !== 'undefined' && module.exports) { module.exports = { CRAFTING_RECIPES, getCraftingRecipe, canCraft, craftItem }; }