Explorar o código

Fix a recipe bug

JunWang %!s(int64=8) %!d(string=hai) anos
pai
achega
d48885dbdb

+ 26 - 26
data/crafting.txt

@@ -177,39 +177,39 @@ CraftingTable		  = WoodPlanks^-1, 1:1, 1:2, 2:1, 2:2
 ##
 #
 ## Axes:
-#DiamondAxe = Stick, 2:2, 2:3 | Diamond,     2:1, 1:1, 1:2
-#DiamondAxe = Stick, 2:2, 2:3 | Diamond,     2:1, 3:1, 3:2
-#GoldenAxe  = Stick, 2:2, 2:3 | GoldIngot,   2:1, 1:1, 1:2
-#GoldenAxe  = Stick, 2:2, 2:3 | GoldIngot,   2:1, 3:1, 3:2
-#IronAxe    = Stick, 2:2, 2:3 | IronIngot,   2:1, 1:1, 1:2
-#IronAxe    = Stick, 2:2, 2:3 | IronIngot,   2:1, 3:1, 3:2
-#StoneAxe   = Stick, 2:2, 2:3 | Cobblestone, 2:1, 1:1, 1:2
-#StoneAxe   = Stick, 2:2, 2:3 | Cobblestone, 2:1, 3:1, 3:2
-#WoodenAxe  = Stick, 2:2, 2:3 | Planks^-1,   2:1, 1:1, 1:2
-#WoodenAxe  = Stick, 2:2, 2:3 | Planks^-1,   2:1, 3:1, 3:2
+DiamondAxe = Stick, 2:2, 2:3 | Diamond,     2:1, 1:1, 1:2
+DiamondAxe = Stick, 2:2, 2:3 | Diamond,     2:1, 3:1, 3:2
+GoldenAxe  = Stick, 2:2, 2:3 | GoldIngot,   2:1, 1:1, 1:2
+GoldenAxe  = Stick, 2:2, 2:3 | GoldIngot,   2:1, 3:1, 3:2
+IronAxe    = Stick, 2:2, 2:3 | IronIngot,   2:1, 1:1, 1:2
+IronAxe    = Stick, 2:2, 2:3 | IronIngot,   2:1, 3:1, 3:2
+StoneAxe   = Stick, 2:2, 2:3 | Cobblestone, 2:1, 1:1, 1:2
+StoneAxe   = Stick, 2:2, 2:3 | Cobblestone, 2:1, 3:1, 3:2
+WoodenAxe  = Stick, 2:2, 2:3 | WoodPlanks^-1,   2:1, 1:1, 1:2
+WoodenAxe  = Stick, 2:2, 2:3 | WoodPlanks^-1,   2:1, 3:1, 3:2
 #
 ## Pickaxes:
-#DiamondPickaxe = Stick, 2:2, 2:3 | Diamond,     1:1, 2:1, 3:1
-#GoldenPickaxe  = Stick, 2:2, 2:3 | GoldIngot,   1:1, 2:1, 3:1
-#IronPickaxe    = Stick, 2:2, 2:3 | IronIngot,   1:1, 2:1, 3:1
-#StonePickaxe   = Stick, 2:2, 2:3 | Cobblestone, 1:1, 2:1, 3:1
-#WoodenPickaxe  = Stick, 2:2, 2:3 | Planks^-1,   1:1, 2:1, 3:1
+DiamondPickaxe = Stick, 2:2, 2:3 | Diamond,     1:1, 2:1, 3:1
+GoldenPickaxe  = Stick, 2:2, 2:3 | GoldIngot,   1:1, 2:1, 3:1
+IronPickaxe    = Stick, 2:2, 2:3 | IronIngot,   1:1, 2:1, 3:1
+StonePickaxe   = Stick, 2:2, 2:3 | Cobblestone, 1:1, 2:1, 3:1
+WoodenPickaxe  = Stick, 2:2, 2:3 | WoodPlanks^-1,   1:1, 2:1, 3:1
 #
 ## Shovels:
-#DiamondShovel = Stick, 2:2, 2:3 | Diamond,     2:1
-#GoldenShovel  = Stick, 2:2, 2:3 | GoldIngot,   2:1
-#IronShovel    = Stick, 2:2, 2:3 | IronIngot,   2:1
-#StoneShovel   = Stick, 2:2, 2:3 | Cobblestone, 2:1
-#WoodenShovel  = Stick, 2:2, 2:3 | Planks^-1,   2:1
+DiamondShovel = Stick, 2:2, 2:3 | Diamond,     2:1
+GoldenShovel  = Stick, 2:2, 2:3 | GoldIngot,   2:1
+IronShovel    = Stick, 2:2, 2:3 | IronIngot,   2:1
+StoneShovel   = Stick, 2:2, 2:3 | Cobblestone, 2:1
+WoodenShovel  = Stick, 2:2, 2:3 | WoodPlanks^-1,   2:1
 #
 ## Hoes:
-#DiamondHoe = Stick, 2:2, 2:3 | Diamond,     2:1, *:1
-#GoldenHoe  = Stick, 2:2, 2:3 | GoldIngot,   2:1, *:1
-#IronHoe    = Stick, 2:2, 2:3 | IronIngot,   2:1, *:1
-#StoneHoe   = Stick, 2:2, 2:3 | Cobblestone, 2:1, *:1
-#WoodenHoe  = Stick, 2:2, 2:3 | Planks^-1,   2:1, *:1
+DiamondHoe = Stick, 2:2, 2:3 | Diamond,     2:1, *:1
+GoldenHoe  = Stick, 2:2, 2:3 | GoldIngot,   2:1, *:1
+IronHoe    = Stick, 2:2, 2:3 | IronIngot,   2:1, *:1
+StoneHoe   = Stick, 2:2, 2:3 | Cobblestone, 2:1, *:1
+WoodenHoe  = Stick, 2:2, 2:3 | WoodPlanks^-1,   2:1, *:1
 #
-#Bucket         = IronIngot, 1:1, 2:2, 3:1
+Bucket         = IronIngot, 1:1, 2:2, 3:1
 #Compass        = IronIngot, 2:1, 1:2, 3:2, 2:3 | RedstoneDust, 2:2
 #EmptyMap       = Paper,     1:1, 1:2, 1:3, 2:1, 2:3, 3:1, 3:2, 3:3 | Compass, 2:2
 #FireCharge, 3  = BlazePowder, *   | Coal, *    | Gunpowder, *

+ 10 - 1
src/MineCase.Core/CraftingRecipeLoader.cs

@@ -72,6 +72,7 @@ namespace MineCase
                     restSpan = restSpan.Slice(ingredientSplitter + 1);
             }
 
+            NormalizeIngredients(recipe);
             Recipes.Add(recipe);
         }
 
@@ -130,8 +131,16 @@ namespace MineCase
                     distributionSpan = distributionSpan.Slice(positionSplitter + 1);
             }
             while (true);
+
+            if (recipe.Inputs != null)
+            {
+                foreach (CraftingRecipeSlot each in recipe.Inputs)
+                {
+                    recipeSlots.Add(each);
+                }
+            }
+
             recipe.Inputs = recipeSlots.ToArray();
-            NormalizeIngredients(recipe);
         }
 
         private void NormalizeIngredients(CraftingRecipe recipe)

+ 22 - 1
tests/UnitTest/CraftingRecipeTest.cs

@@ -32,7 +32,7 @@ namespace MineCase.UnitTest
             }
 
             var recipes = loader.Recipes;
-            Assert.Equal(13, recipes.Count);
+            Assert.Equal(13 + 26, recipes.Count);
         }
 
         [Fact]
@@ -55,5 +55,26 @@ namespace MineCase.UnitTest
             Assert.Equal((short)BlockStates.WoodPlanks().Id, recipe.Result.BlockId);
             Assert.True(recipe.AfterTake.Cast<Slot>().All(o => o.IsEmpty));
         }
+
+        [Fact]
+        public async Task TestTools()
+        {
+            var loader = new CraftingRecipeLoader();
+            using (var sr = new StreamReader(File.OpenRead(Path.Combine(RootDir, "crafting.txt"))))
+            {
+                await loader.LoadRecipes(sr);
+            }
+
+            var matcher = new CraftingRecipeMatcher(loader.Recipes);
+            var recipe = matcher.FindRecipe(new Slot[,]
+            {
+                { new Slot { BlockId = (short)BlockStates.WoodPlanks().Id, ItemCount = 1 }, Slot.Empty, Slot.Empty },
+                { new Slot { BlockId = (short)BlockStates.WoodPlanks().Id, ItemCount = 1 }, new Slot { BlockId = (short)ItemId.Stick, ItemCount = 1 }, new Slot { BlockId = (short)ItemId.Stick, ItemCount = 1 }},
+                { new Slot { BlockId = (short)BlockStates.WoodPlanks().Id, ItemCount = 1 }, Slot.Empty, Slot.Empty }
+            });
+            Assert.NotNull(recipe);
+            Assert.Equal((short)ItemId.WoodenPickaxe, recipe.Result.BlockId);
+            Assert.True(recipe.AfterTake.Cast<Slot>().All(o => o.IsEmpty));
+        }
     }
 }