コード例 #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);
        }
コード例 #3
0
        public override bool CanSmelt(IWorldAccessor world, ISlotProvider cookingSlotsProvider, ItemStack inputStack, ItemStack outputStack)
        {
            ItemStack[] stacks = GetIngredients(world, cookingSlotsProvider);

            // Got alloy?
            if (GetMatchingAlloy(world, stacks) != null)
            {
                return(true);
            }

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

            MatchedSmeltableStack match = GetSingleSmeltableStack(stacks);

            return(match != null);
        }