示例#1
0
        public override void DoSmelt(IWorldAccessor world, ISlotProvider cookingSlotsProvider, ItemSlot inputSlot, ItemSlot outputSlot)
        {
            ItemStack[] stacks = GetIngredients(world, cookingSlotsProvider);

            AlloyRecipe alloy = GetMatchingAlloy(world, stacks);

            Block     block       = world.GetBlock(CodeWithPath(FirstCodePart() + "-smelted"));
            ItemStack outputStack = new ItemStack(block);

            if (alloy != null)
            {
                ItemStack smeltedStack = alloy.Output.ResolvedItemstack.Clone();
                int       units        = (int)Math.Round(alloy.GetTotalOutputQuantity(stacks) * 100, 4);

                ((BlockSmeltedContainer)block).SetContents(outputStack, smeltedStack, units);
                outputStack.Collectible.SetTemperature(world, outputStack, GetIngredientsTemperature(world, stacks));
                outputSlot.Itemstack = outputStack;
                inputSlot.Itemstack  = null;

                for (int i = 0; i < cookingSlotsProvider.Slots.Length; i++)
                {
                    cookingSlotsProvider.Slots[i].Itemstack = null;
                }


                return;
            }


            MatchedSmeltableStack match = GetSingleSmeltableStack(stacks);

            if (match != null)
            {
                ((BlockSmeltedContainer)block).SetContents(outputStack, match.output, (int)(match.stackSize * 100));
                outputStack.Collectible.SetTemperature(world, outputStack, GetIngredientsTemperature(world, stacks));
                outputSlot.Itemstack = outputStack;
                inputSlot.Itemstack  = null;

                for (int i = 0; i < cookingSlotsProvider.Slots.Length; i++)
                {
                    cookingSlotsProvider.Slots[i].Itemstack = null;
                }
            }
        }
示例#2
0
        public string GetOutputText(IWorldAccessor world, ISlotProvider cookingSlotsProvider, ItemSlot inputSlot)
        {
            if (inputSlot.Itemstack == null)
            {
                return(null);
            }

            if (inputSlot.Itemstack.Collectible is BlockSmeltingContainer)
            {
                BlockSmeltingContainer bsc = (BlockSmeltingContainer)inputSlot.Itemstack.Collectible;

                ItemStack[] stacks = bsc.GetIngredients(world, cookingSlotsProvider);

                for (int i = 0; i < stacks.Length; i++)
                {
                    CombustibleProperties props = stacks[i]?.Collectible.CombustibleProps;
                    if (props != null && !props.RequiresContainer)
                    {
                        return(null);
                    }
                }

                AlloyRecipe alloy = bsc.GetMatchingAlloy(world, stacks);

                if (alloy != null)
                {
                    double quantity = alloy.GetTotalOutputQuantity(stacks);
                    return(string.Format("Will create {0} units of {1}", (int)Math.Round(quantity * 100, 4), CheapMetalNameHax(alloy.Output.ResolvedItemstack)));
                }

                MatchedSmeltableStack match = GetSingleSmeltableStack(stacks);
                if (match != null)
                {
                    return(string.Format("Will create {0} units of {1}", (int)Math.Round(match.stackSize * 100, 4), CheapMetalNameHax(match.output)));
                }

                return(null);
            }

            return(null);
        }
 public static void RegisterMetalAlloy(this ICoreServerAPI api, AlloyRecipe r)
 {
     api.ModLoader.GetModSystem <RecipeRegistrySystem>().RegisterMetalAlloy(r);
 }
 /// <summary>
 /// Registers a new metal alloy. These are sent to the client during connect, so only need to register them on the server side.
 /// </summary>
 /// <param name="alloy"></param>
 public void RegisterMetalAlloy(AlloyRecipe alloy)
 {
     MetalAlloys.Add(alloy);
 }