public override void HandleMcpeCraftingData(McpeCraftingData message) { if (Client.IsEmulator) { return; } string fileName = Path.GetTempPath() + "Recipes_" + Guid.NewGuid() + ".txt"; Log.Info("Writing recipes to filename: " + fileName); FileStream file = File.OpenWrite(fileName); IndentedTextWriter writer = new IndentedTextWriter(new StreamWriter(file)); writer.WriteLine("static RecipeManager()"); writer.WriteLine("{"); writer.Indent++; writer.WriteLine("Recipes = new Recipes"); writer.WriteLine("{"); writer.Indent++; foreach (Recipe recipe in message.recipes) { ShapelessRecipe shapelessRecipe = recipe as ShapelessRecipe; if (shapelessRecipe != null) { writer.WriteLine($"new ShapelessRecipe(new Item({shapelessRecipe.Result.Id}, {shapelessRecipe.Result.Metadata}, {shapelessRecipe.Result.Count}),"); writer.Indent++; writer.WriteLine("new List<Item>"); writer.WriteLine("{"); writer.Indent++; foreach (var itemStack in shapelessRecipe.Input) { writer.WriteLine($"new Item({itemStack.Id}, {itemStack.Metadata}, {itemStack.Count}),"); } writer.Indent--; writer.WriteLine("}),"); writer.Indent--; continue; } ShapedRecipe shapedRecipe = recipe as ShapedRecipe; if (shapedRecipe != null && Client._recipeToSend == null) { if (shapedRecipe.Result.Id == 5 && shapedRecipe.Result.Count == 4 && shapedRecipe.Result.Metadata == 0) { Log.Error("Setting recipe! " + shapedRecipe.Id); Client._recipeToSend = shapedRecipe; } } if (shapedRecipe != null) { writer.WriteLine($"new ShapedRecipe({shapedRecipe.Width}, {shapedRecipe.Height}, new Item({shapedRecipe.Result.Id}, {shapedRecipe.Result.Metadata}, {shapedRecipe.Result.Count}),"); writer.Indent++; writer.WriteLine("new Item[]"); writer.WriteLine("{"); writer.Indent++; foreach (Item item in shapedRecipe.Input) { writer.WriteLine($"new Item({item.Id}, {item.Metadata}),"); } writer.Indent--; writer.WriteLine("}),"); writer.Indent--; continue; } SmeltingRecipe smeltingRecipe = recipe as SmeltingRecipe; if (smeltingRecipe != null) { writer.WriteLine($"new SmeltingRecipe(new Item({smeltingRecipe.Result.Id}, {smeltingRecipe.Result.Metadata}, {smeltingRecipe.Result.Count}), new Item({smeltingRecipe.Input.Id}, {smeltingRecipe.Input.Metadata})),"); continue; } MultiRecipe multiRecipe = recipe as MultiRecipe; if (multiRecipe != null) { writer.WriteLine($"new MultiRecipe() {{ Id = new UUID(\"{recipe.Id}\") }}, // {recipe.Id}"); continue; } } writer.WriteLine("};"); writer.Indent--; writer.WriteLine("}"); writer.Indent--; writer.Flush(); file.Close(); //Environment.Exit(0); }
private void ReadNewRecipes() { recipes = new Recipes(); var count = ReadUnsignedVarInt(); Log.Trace($"Reading {count} recipes"); for (int i = 0; i < count; i++) { int recipeType = ReadSignedVarInt(); Log.Trace($"Read recipe no={i} type={recipeType}"); if (recipeType < 0 /*|| len == 0*/) { Log.Error("Read void recipe"); break; } switch (recipeType) { case ShapelessChemistry: case Shapeless: case ShulkerBox: { var recipe = new ShapelessRecipe(); ReadString(); // some unique id int ingrediensCount = ReadVarInt(); // for (int j = 0; j < ingrediensCount; j++) { recipe.Input.Add(ReadRecipeIngredient()); } int resultCount = ReadVarInt(); // 1? for (int j = 0; j < resultCount; j++) { recipe.Result.Add(this.ReadItem2(false)); } recipe.Id = ReadUUID(); // Id recipe.Block = ReadString(); // block? ReadSignedVarInt(); // priority recipe.UniqueId = ReadVarInt(); // unique id recipes.Add(recipe); //Log.Error("Read shapeless recipe"); break; } case ShapedChemistry: case Shaped: { ReadString(); // some unique id int width = ReadVarInt(); // Width int height = ReadVarInt(); // Height var recipe = new ShapedRecipe(width, height); if (width > 3 || height > 3) { // throw new Exception("Wrong number of ingredience. Width=" + width + ", height=" + height); } for (int w = 0; w < width; w++) { for (int h = 0; h < height; h++) { recipe.Input[(h * width) + w] = ReadRecipeIngredient(); } } int resultCount = ReadVarInt(); // 1? for (int j = 0; j < resultCount; j++) { recipe.Result.Add(this.ReadItem2(false)); } recipe.Id = ReadUUID(); // Id recipe.Block = ReadString(); // block? ReadSignedVarInt(); // priority recipe.UniqueId = ReadVarInt(); // unique id recipes.Add(recipe); //Log.Error("Read shaped recipe"); break; } case FurnaceData: case Furnace: { var recipe = new SmeltingRecipe(); short id = (short)ReadSignedVarInt(); // input (with metadata) Item result = this.ReadItem2(false); // Result recipe.Block = ReadString(); // block? recipe.Input = ItemFactory.GetItem(id, 0); recipe.Result = result; recipes.Add(recipe); //Log.Error("Read furnace recipe"); //Log.Error($"Input={id}, meta={""} Item={result.Id}, Meta={result.Metadata}"); break; } /*case FurnaceData: * { * //const ENTRY_FURNACE_DATA = 3; * var recipe = new SmeltingRecipe(); * short id = (short) ReadSignedVarInt(); // input (with metadata) * short meta = (short) ReadSignedVarInt(); // input (with metadata) * Item result = ReadItem(); // Result * recipe.Block = ReadString(); // block? * recipe.Input = ItemFactory.GetItem(id, meta); * recipe.Result = result; * recipes.Add(recipe); * //Log.Error("Read smelting recipe"); * //Log.Error($"Input={id}, meta={meta} Item={result.Id}, Meta={result.Metadata}"); * break; * }*/ case Multi: { //Log.Error("Reading MULTI"); var recipe = new MultiRecipe(); recipe.Id = ReadUUID(); recipe.UniqueId = ReadVarInt(); // unique id recipes.Add(recipe); break; } /*case ShapelessChemistry: * { * var recipe = new ShapelessRecipe(); * ReadString(); // some unique id * int ingrediensCount = ReadVarInt(); // * for (int j = 0; j < ingrediensCount; j++) * { * recipe.Input.Add(ReadRecipeIngredient()); * } * int resultCount = ReadVarInt(); // 1? * for (int j = 0; j < resultCount; j++) * { * recipe.Result.Add(ReadItem()); * } * recipe.Id = ReadUUID(); // Id * recipe.Block = ReadString(); // block? * ReadSignedVarInt(); // priority * recipe.UniqueId = ReadVarInt(); // unique id * //recipes.Add(recipe); * //Log.Error("Read shapeless recipe"); * break; * }*/ /*case ShapedChemistry: * { * ReadString(); // some unique id * int width = ReadSignedVarInt(); // Width * int height = ReadSignedVarInt(); // Height * var recipe = new ShapedRecipe(width, height); * if (width > 3 || height > 3) throw new Exception("Wrong number of ingredience. Width=" + width + ", height=" + height); * for (int w = 0; w < width; w++) * { * for (int h = 0; h < height; h++) * { * recipe.Input[(h * width) + w] = ReadRecipeIngredient(); * } * } * * int resultCount = ReadVarInt(); // 1? * for (int j = 0; j < resultCount; j++) * { * recipe.Result.Add(ReadItem()); * } * recipe.Id = ReadUUID(); // Id * recipe.Block = ReadString(); // block? * ReadSignedVarInt(); // priority * recipe.UniqueId = ReadVarInt(); // unique id * //recipes.Add(recipe); * //Log.Error("Read shaped recipe"); * break; * } */ default: Log.Error($"Read unknown recipe type: {recipeType}"); //ReadBytes(len); break; } } Log.Trace($"Done reading {count} recipes"); }