private void FindMatchingRecipe()
        {
            ItemStack[] inputstacks = new ItemStack[] { inventory[0].Itemstack, inventory[1].Itemstack };
            CurrentRecipe = null;

            foreach (var recipe in api.World.BarrelRecipes)
            {
                int outsize;


                if (recipe.Matches(api.World, inputstacks, out outsize))
                {
                    ignoreChange = true;

                    if (recipe.SealHours > 0)
                    {
                        CurrentRecipe  = recipe;
                        CurrentOutSize = outsize;
                    }
                    else
                    {
                        ItemStack mixedStack = recipe.Output.ResolvedItemstack.Clone();
                        mixedStack.StackSize = outsize;

                        if (BlockLiquidContainerBase.GetStackProps(mixedStack) != null)
                        {
                            inventory[0].Itemstack = null;
                            inventory[1].Itemstack = mixedStack;
                        }
                        else
                        {
                            inventory[1].Itemstack = null;
                            inventory[0].Itemstack = mixedStack;
                        }


                        inventory[0].MarkDirty();
                        inventory[1].MarkDirty();
                        MarkDirty(true);
                        api.World.BlockAccessor.MarkBlockEntityDirty(pos);
                    }


                    invDialog?.UpdateContents();
                    if (api?.Side == EnumAppSide.Client)
                    {
                        currentMesh = GenMesh();
                        MarkDirty(true);
                    }

                    ignoreChange = false;
                    return;
                }
            }
        }
        string getContentsText()
        {
            string contents = "Contents:";

            if (Inventory[0].Empty && Inventory[1].Empty)
            {
                contents += "\nNone.";
            }
            else
            {
                if (!Inventory[1].Empty)
                {
                    ItemStack stack = Inventory[1].Itemstack;
                    WaterTightContainableProps props = BlockLiquidContainerBase.GetStackProps(stack);

                    if (props != null)
                    {
                        string incontainername = Lang.Get("incontainer-" + stack.Class.ToString().ToLowerInvariant() + "-" + stack.Collectible.Code.Path);
                        contents += "\n" + Lang.Get("{0} litres of {1}", (float)stack.StackSize / props.ItemsPerLitre, incontainername);
                    }
                    else
                    {
                        contents += "\n" + Lang.Get("{0}x of {1}", stack.StackSize, stack.GetName());
                    }
                }

                if (!Inventory[0].Empty)
                {
                    ItemStack stack = Inventory[0].Itemstack;
                    contents += "\n" + Lang.Get("{0}x of {1}", stack.StackSize, stack.GetName());
                }

                BlockEntityBarrel bebarrel = capi.World.BlockAccessor.GetBlockEntity(BlockEntityPosition) as BlockEntityBarrel;
                if (bebarrel.CurrentRecipe != null)
                {
                    ItemStack outStack = bebarrel.CurrentRecipe.Output.ResolvedItemstack;
                    WaterTightContainableProps props = BlockLiquidContainerBase.GetStackProps(outStack);

                    string timeText = bebarrel.CurrentRecipe.SealHours > 24 ? Lang.Get("{0} days", Math.Round(bebarrel.CurrentRecipe.SealHours / capi.World.Calendar.HoursPerDay, 1)) : Lang.Get("{0} hours", bebarrel.CurrentRecipe.SealHours);

                    if (props != null)
                    {
                        string incontainername = Lang.Get("incontainer-" + outStack.Class.ToString().ToLowerInvariant() + "-" + outStack.Collectible.Code.Path);
                        float  litres          = (float)bebarrel.CurrentOutSize / props.ItemsPerLitre;
                        contents += "\n\n" + Lang.Get("Will turn into {0} litres of {1} after {2} of sealing.", litres, incontainername, timeText);
                    }
                    else
                    {
                        contents += "\n\n" + Lang.Get("Will turn into {0}x of {1} after {2} of sealing.", bebarrel.CurrentOutSize, outStack.GetName(), timeText);
                    }
                }
            }

            return(contents);
        }
        private void OnEvery3Second(float dt)
        {
            if (!inventory[0].Empty && CurrentRecipe == null)
            {
                FindMatchingRecipe();
            }

            if (CurrentRecipe != null && Sealed && CurrentRecipe.SealHours > 0)
            {
                if (api.World.Calendar.TotalHours - SealedSinceTotalHours > CurrentRecipe.SealHours)
                {
                    ItemStack mixedStack = CurrentRecipe.Output.ResolvedItemstack.Clone();
                    mixedStack.StackSize = CurrentOutSize;

                    // Carry over freshness
                    TransitionableProperties perishProps = mixedStack.Collectible.GetTransitionableProperties(api.World, mixedStack, null)?[0];

                    if (perishProps != null)
                    {
                        ItemSlot[] slots = new ItemSlot[inventory.Count];
                        for (int i = 0; i < inventory.Count; i++)
                        {
                            slots[i] = inventory[i];
                        }
                        BlockCookingContainer.CarryOverFreshness(api, slots, new ItemStack[] { mixedStack }, perishProps);
                    }

                    if (BlockLiquidContainerBase.GetStackProps(mixedStack) != null)
                    {
                        inventory[0].Itemstack = null;
                        inventory[1].Itemstack = mixedStack;
                    }
                    else
                    {
                        inventory[1].Itemstack = null;
                        inventory[0].Itemstack = mixedStack;
                    }



                    inventory[0].MarkDirty();
                    inventory[1].MarkDirty();

                    MarkDirty(true);
                    api.World.BlockAccessor.MarkBlockEntityDirty(pos);
                    Sealed = false;
                }
            }
            else
            {
                Sealed = false;
                MarkDirty(true);
            }
        }
        public override bool CanTakeFrom(ItemSlot sourceSlot)
        {
            if (inventory?.PutLocked == true)
            {
                return(false);
            }

            ItemStack sourceStack = sourceSlot.Itemstack;

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

            WaterTightContainableProps props = BlockLiquidContainerBase.GetStackProps(sourceStack);

            return(props != null && (itemstack == null || itemstack.Collectible.GetMergableQuantity(itemstack, sourceStack) > 0) && RemainingSlotSpace > 0);
        }
        public override bool CanHold(ItemSlot itemstackFromSourceSlot)
        {
            WaterTightContainableProps props = BlockLiquidContainerBase.GetStackProps(itemstackFromSourceSlot.Itemstack);

            return(props != null);
        }