예제 #1
0
        //Adds 'use' recipe if it doesn't already exist
        protected ConvertRecipe AddRecipe(ConvertRecipe r)
        {
            if (convertRecipes.Contains(r))
            {
                return(r);
            }

            if (r.owner == null)
            {
                typeof(ConvertRecipe).GetProperty("owner").SetValue(r, this, null);
            }

            convertRecipes.Add(r);
            Console.WriteLine(r.ToString());
            return(r);
        }
예제 #2
0
        //Registers the recipe into the game
        protected bool RegisterRecipe(ConvertRecipe r)
        {
            FieldInfo itemConnections = typeof(CookingSlot).GetField("itemConnections", BindingFlags.NonPublic | BindingFlags.Instance);

            if (itemConnections == null)
            {
                return(false);
            }

            int count = 0;

            //The recipe/item has to be registered into the converters
            foreach (Item c in converter[r.type])
            {
                Block buildable = c.baseItem.settings_buildable.GetBlockPrefab(DPS.Default);

                if (buildable == null || !(buildable is CookingStand))
                {
                    continue;
                }

                CookingStand stand = (CookingStand)buildable;

                CookingSlot[] slots = stand.GetComponentsInChildren <CookingSlot>();

                foreach (CookingSlot slot in slots)
                {
                    if (slot == null)
                    {
                        continue;
                    }

                    object connectionso = itemConnections.GetValue(slot);

                    if (connectionso == null)
                    {
                        continue;
                    }

                    List <CookItemConnection> connections = (List <CookItemConnection>)connectionso;

                    if (connections == null)
                    {
                        continue;
                    }

                    CookItemConnection recipe = new CookItemConnection();
                    recipe.cookableItem = r.input.baseItem;
                    recipe.rawItem      = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                    recipe.cookedItem   = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
                    connections.Add(recipe);

                    GameObject.DontDestroyOnLoad(recipe.rawItem);
                    GameObject.DontDestroyOnLoad(recipe.cookedItem);

                    itemConnections.SetValue(slot, connections);
                    ++count;
                }
            }

            return(count != 0);
        }
예제 #3
0
        /// <summary>
        /// Converting a conversion recipe from legacy to mod, as well as registering it.
        /// This requires lookup into 'CookingStand', which means that this should be used sparingly
        /// </summary>
        /// <param name="it">The item this recipe belongs to</param>
        /// <param name="recipe">The legacy way of declaring a recipe</param>
        /// <returns>mod recipe</returns>
        private ConvertRecipe ConvertRecipe(Item it, ItemInstance_Cookable recipe)
        {
            string type = "";

            foreach (string t in GetConverterTypes())
            {
                foreach (Item i in GetConverters(t))
                {
                    Block block;

                    if (i.baseItem == null || (block = i.baseItem.settings_buildable.GetBlockPrefab(DPS.Default)) == null || !(block is CookingStand))
                    {
                        continue;
                    }

                    CookingStand stand = (CookingStand)block;

                    CookingSlot[] slots = block.GetComponentsInChildren <CookingSlot>();

                    if (slots.Length < 1)
                    {
                        continue;
                    }

                    CookingSlot slot = slots[0];

                    FieldInfo itemConnections = typeof(CookingSlot).GetField("itemConnections", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (slot == null || itemConnections == null)
                    {
                        continue;
                    }

                    object connectionso = itemConnections.GetValue(slot);

                    if (connectionso == null)
                    {
                        continue;
                    }

                    List <CookItemConnection> connections = (List <CookItemConnection>)connectionso;

                    if (connections == null)
                    {
                        continue;
                    }

                    foreach (CookItemConnection connection in connections)
                    {
                        if (connection.rawItem == null)
                        {
                            continue;
                        }

                        if (connection.cookableItem == it.baseItem)
                        {
                            type = t;
                            goto end;
                        }
                    }
                }
            }

end:

            if (type == "")
            {
                return(null);
            }

            ConvertRecipe r = new ConvertRecipe(it, 1, Item.ByHandle(recipe.CookingResult.item), recipe.CookingResult.amount, type, recipe.CookingTime, recipe.CookingSlotsRequired);

            typeof(ConvertRecipe).GetProperty("owner").SetValue(r, this, null);
            return(AddRecipe(r));
        }