private SmeltingRecipe GetSmeltingRecipe(ItemStack item) { SmeltingRecipe recipe = null; if (item != null && !item.IsVoid()) { recipe = SmeltingRecipe.GetRecipe(Server.GetSmeltingRecipes(), item); } return(recipe); }
private SmeltingRecipe GetSmeltingRecipe(ItemInventory item) { SmeltingRecipe recipe = null; if (item != null && !ItemHelper.IsVoid(item)) { recipe = SmeltingRecipe.GetRecipe(Server.GetSmeltingRecipes(), item); } return(recipe); }
private bool HasIngredient() { if (InputSlot.IsVoid()) { return(false); } SmeltingRecipe recipe = GetSmeltingRecipe(InputSlot); return(recipe != null); }
private SmeltingRecipe ConvertLineToSmeltingRecipe(CsvReader csvReader) { var resultMinecraftId = csvReader.GetField("ItemId"); var ingredientMinecraftId = csvReader.GetField("IngredientId"); var primaryMethod = csvReader.GetField("PrimaryMethod"); var recipe = new SmeltingRecipe { ResultId = GetItemId(resultMinecraftId), IngredientId = GetItemId(ingredientMinecraftId) }; return(recipe); }
public Recipes ReadRecipes() { Recipes recipes = new Recipes(); int count = (int)ReadUnsignedVarInt(); Log.Error($"Reading {count} recipes"); for (int i = 0; i < count; i++) { int recipeType = (int)ReadSignedVarInt(); //Log.Error($"Read recipe no={i} type={recipeType}"); if (recipeType < 0 /*|| len == 0*/) { Log.Error("Read void recipe"); break; } if (recipeType == 0) { //const ENTRY_SHAPELESS = 0; ShapelessRecipe recipe = new ShapelessRecipe(); int ingrediensCount = ReadVarInt(); // for (int j = 0; j < ingrediensCount; j++) { recipe.Input.Add(ReadItem()); } ReadVarInt(); // 1? recipe.Result = ReadItem(); recipe.Id = ReadUUID(); // Id recipes.Add(recipe); //Log.Error("Read shapeless recipe"); } else if (recipeType == 1) { //const ENTRY_SHAPED = 1; int width = ReadSignedVarInt(); // Width int height = ReadSignedVarInt(); // Height ShapedRecipe 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] = ReadItem(); } } int resultCount = ReadVarInt(); // 1? for (int j = 0; j < resultCount; j++) { recipe.Result = ReadItem(); } recipe.Id = ReadUUID(); // Id recipes.Add(recipe); //Log.Error("Read shaped recipe"); } else if (recipeType == 2) { //const ENTRY_FURNACE = 2; SmeltingRecipe recipe = new SmeltingRecipe(); //short meta = (short) ReadVarInt(); // input (with metadata) short id = (short)ReadSignedVarInt(); // input (with metadata) Item result = ReadItem(); // Result 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}"); } else if (recipeType == 3) { //const ENTRY_FURNACE_DATA = 3; SmeltingRecipe recipe = new SmeltingRecipe(); short id = (short)ReadSignedVarInt(); // input (with metadata) short meta = (short)ReadSignedVarInt(); // input (with metadata) Item result = ReadItem(); // Result 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}"); } else if (recipeType == 4) { //const ENTRY_ENCHANT_LIST = 4; Log.Error("Reading ENCHANT_LIST"); ReadUUID(); } else { Log.Error($"Read unknown recipe type: {recipeType}"); //ReadBytes(len); } } ReadByte(); // Clean (1) or update (0) return(recipes); }
public void Write(Recipes recipes) { WriteUnsignedVarInt((uint)recipes.Count); foreach (Recipe recipe in recipes) { if (recipe is ShapelessRecipe) { WriteSignedVarInt(0); // Type ShapelessRecipe rec = (ShapelessRecipe)recipe; WriteVarInt(rec.Input.Count); foreach (Item stack in rec.Input) { Write(stack); } WriteVarInt(1); Write(rec.Result); Write(new UUID(Guid.NewGuid())); } else if (recipe is ShapedRecipe) { WriteSignedVarInt(1); // Type ShapedRecipe rec = (ShapedRecipe)recipe; WriteSignedVarInt(rec.Width); WriteSignedVarInt(rec.Height); for (int w = 0; w < rec.Width; w++) { for (int h = 0; h < rec.Height; h++) { Write(rec.Input[(h * rec.Width) + w]); } } WriteVarInt(1); Write(rec.Result); Write(new UUID(Guid.NewGuid())); } else if (recipe is SmeltingRecipe) { SmeltingRecipe rec = (SmeltingRecipe)recipe; WriteSignedVarInt(rec.Input.Metadata == 0 ? 2 : 3); // Type WriteSignedVarInt(rec.Input.Id); if (rec.Input.Metadata != 0) { WriteSignedVarInt(rec.Input.Metadata); } Write(rec.Result); } else if (recipe is EnchantingRecipe) { //var memoryStream = MiNetServer.MemoryStreamManager.GetStream(); //McpeWriter writer = new McpeWriter(memoryStream); //writer.Write((byte) 3); // Count //{ // writer.Write((int) 1); // Cost // writer.Write((byte) 1); // Count // writer.Write((int) 9); // Id // writer.Write((int) 1); // Level // writer.Write("Test1"); // Level //} //Write(4); // Type //var bytes = memoryStream.ToArray(); //Write(bytes.Length); //Write(bytes); } } Write((byte)1); }
public void Write(Recipes recipes) { Write(recipes.Count); foreach (Recipe recipe in recipes) { if (recipe is ShapelessRecipe) { var memoryStream = MiNetServer.MemoryStreamManager.GetStream(); McpeWriter writer = new McpeWriter(memoryStream); ShapelessRecipe rec = (ShapelessRecipe)recipe; writer.Write(rec.Input.Count); foreach (Item stack in rec.Input) { writer.Write(stack); } writer.Write(1); writer.Write(rec.Result); writer.Write(new UUID(Guid.NewGuid())); Write(0); // Type var bytes = memoryStream.ToArray(); Write(bytes.Length); Write(bytes); } else if (recipe is ShapedRecipe) { var memoryStream = MiNetServer.MemoryStreamManager.GetStream(); McpeWriter writer = new McpeWriter(memoryStream); ShapedRecipe rec = (ShapedRecipe)recipe; writer.Write(rec.Width); writer.Write(rec.Height); for (int w = 0; w < rec.Width; w++) { for (int h = 0; h < rec.Height; h++) { writer.Write(rec.Input[(h * rec.Width) + w]); } } writer.Write(1); writer.Write(rec.Result); writer.Write(new UUID(Guid.NewGuid())); Write(1); // Type var bytes = memoryStream.ToArray(); Write(bytes.Length); Write(bytes); } else if (recipe is SmeltingRecipe) { ////const ENTRY_FURNACE = 2; //SmeltingRecipe recipe = new SmeltingRecipe(); //short meta = ReadShort(); // input (with metadata) //short id = ReadShort(); // input (with metadata) //Item result = ReadItem(); // Result //recipe.Input = ItemFactory.GetItem(id, meta); //recipe.Result = result; //recipes.Add(recipe); var memoryStream = MiNetServer.MemoryStreamManager.GetStream(); McpeWriter writer = new McpeWriter(memoryStream); SmeltingRecipe rec = (SmeltingRecipe)recipe; writer.Write(rec.Input.Metadata); writer.Write(rec.Input.Id); writer.Write(rec.Result); Write(rec.Input.Metadata == 0 ? 2 : 3); // Type var bytes = memoryStream.ToArray(); Write(bytes.Length); Write(bytes); } else if (recipe is EnchantingRecipe) { var memoryStream = MiNetServer.MemoryStreamManager.GetStream(); McpeWriter writer = new McpeWriter(memoryStream); writer.Write((byte)3); // Count { writer.Write((int)1); // Cost writer.Write((byte)1); // Count writer.Write((int)9); // Id writer.Write((int)1); // Level writer.Write("Test1"); // Level } { writer.Write((int)2); // Cost writer.Write((byte)1); // Count writer.Write((int)10); // Id writer.Write((int)2); // Level writer.Write("Test2"); // Level } { writer.Write((int)3); // Cost writer.Write((byte)1); // Count writer.Write((int)12); // Id writer.Write((int)3); // Level writer.Write("Test3"); // Level } Write(4); // Type var bytes = memoryStream.ToArray(); Write(bytes.Length); Write(bytes); } } Write((byte)1); }
public Recipes ReadRecipes() { Recipes recipes = new Recipes(); int count = ReadInt(); for (int i = 0; i < count; i++) { int recipeType = ReadInt(); int len = ReadInt(); if (recipeType < 0 || len == 0) { Log.Error("Read void recipe"); continue; } if (recipeType == 0) { //const ENTRY_SHAPELESS = 0; ShapelessRecipe recipe = new ShapelessRecipe(); int ingrediensCount = ReadInt(); // for (int j = 0; j < ingrediensCount; j++) { recipe.Input.Add(ReadItem()); } ReadInt(); // 1? recipe.Result = ReadItem(); recipe.Id = ReadUUID(); // Id recipes.Add(recipe); } else if (recipeType == 1) { //const ENTRY_SHAPED = 1; int width = ReadInt(); // Width int height = ReadInt(); // Height ShapedRecipe 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] = ReadItem(); } } int resultCount = ReadInt(); // 1? for (int j = 0; j < resultCount; j++) { recipe.Result = ReadItem(); } recipe.Id = ReadUUID(); // Id recipes.Add(recipe); } else if (recipeType == 2) { //const ENTRY_FURNACE = 2; SmeltingRecipe recipe = new SmeltingRecipe(); short meta = ReadShort(); // input (with metadata) short id = ReadShort(); // input (with metadata) Item result = ReadItem(); // Result recipe.Input = ItemFactory.GetItem(id, meta); recipe.Result = result; recipes.Add(recipe); } else if (recipeType == 3) { //const ENTRY_FURNACE_DATA = 3; SmeltingRecipe recipe = new SmeltingRecipe(); short id = ReadShort(); // input (with metadata) short meta = ReadShort(); // input (with metadata) Item result = ReadItem(); // Result recipe.Input = ItemFactory.GetItem(id, meta); recipe.Result = result; recipes.Add(recipe); } else if (recipeType == 4) { Log.Error("Reading ENCHANT_LIST"); //const ENTRY_ENCHANT_LIST = 4; int enchantmentListCount = ReadByte(); // count for (int j = 0; j < enchantmentListCount; j++) { ReadInt(); // Cost byte enchantmentCount = ReadByte(); // EnchantCount for (int k = 0; k < enchantmentCount; k++) { ReadInt(); // Id ReadInt(); // Level(strenght) } string name = ReadString(); // Name Log.Error("Enchant: " + name); } } else { Log.Error($"Read unknown recipe type: {recipeType}, lenght: {len}"); ReadBytes(len); } } ReadByte(); // Clean (1) or update (0) return(recipes); }
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 static CraftingTreeCompoundItem CreateSmeltingItem(MinecraftItem mcItem, SmeltingRecipe smeltingRecipe, int requiredAmount, int currentAmount, ICraftingTreeCompoundItem parent = null, int recipeAmount = 1) { List <ICraftingTreeItem> ingredients = new List <ICraftingTreeItem>(); var smeltingIngredientMCItem = _minecraftItemRepository.GetMinecraftItemById(smeltingRecipe.IngredientId); var smeltingIngredientItem = CreateSmeltingIngredient(smeltingIngredientMCItem, currentAmount); ingredients.Add(smeltingIngredientItem); var smeltingItem = new CraftingTreeCompoundItem(item: mcItem, requiredAmount: requiredAmount, ingredients: ingredients, recipeResultCount: 1, recipeAmount: recipeAmount, currentAmount: currentAmount, parent: parent); smeltingIngredientItem.Parent = smeltingItem; return(smeltingItem); }
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"); }
public void ForceInject(SmeltingRecipe recipe) { Config.SmeltingRecipes.Add(recipe); }