예제 #1
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            BlockEntityBarrel bebarrel = null;

            if (blockSel.Position != null)
            {
                bebarrel = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityBarrel;
            }
            if (bebarrel != null && bebarrel.Sealed)
            {
                return(true);
            }

            bool handled = base.OnBlockInteractStart(world, byPlayer, blockSel);

            if (!handled && !byPlayer.WorldData.EntityControls.Sneak && blockSel.Position != null)
            {
                if (bebarrel != null)
                {
                    bebarrel.OnBlockInteract(byPlayer);
                }

                return(true);
            }

            return(handled);
        }
예제 #2
0
        private bool onSealClick()
        {
            BlockEntityBarrel bebarrel = capi.World.BlockAccessor.GetBlockEntity(BlockEntityPosition) as BlockEntityBarrel;

            if (bebarrel == null || bebarrel.Sealed)
            {
                return(true);
            }

            if (!bebarrel.CanSeal)
            {
                return(true);
            }

            bebarrel.SealBarrel();

            capi.Network.SendBlockEntityPacket(BlockEntityPosition.X, BlockEntityPosition.Y, BlockEntityPosition.Z, 1337);
            Vec3d pos = BlockEntityPosition.ToVec3d().Add(0.5, 0.5, 0.5);

            capi.World.PlaySoundAt(new AssetLocation("sounds/player/seal"), pos.X, pos.Y, pos.Z, null);

            TryClose();

            return(true);
        }
예제 #3
0
        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.GetContainableProps(stack);

                    if (props != null)
                    {
                        string incontainername = Lang.Get("incontainer-" + stack.Class.ToString().ToLowerInvariant() + "-" + stack.Collectible.Code.Path);
                        contents += "\n" + Lang.Get(props.MaxStackSize > 0 ? "{0}x of {1}" : "{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.GetContainableProps(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 {1} after {2} of sealing.", bebarrel.CurrentOutSize, outStack.GetName(), timeText);
                    }
                }
            }

            return(contents);
        }
예제 #4
0
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref string failureCode)
        {
            BlockEntityBarrel beba = api.World.BlockAccessor.GetBlockEntity(blockSel.Position.AddCopy(blockSel.Face.Opposite)) as BlockEntityBarrel;

            if (beba != null)
            {
                return(false);
            }


            return(base.TryPlaceBlock(world, byPlayer, itemstack, blockSel, ref failureCode));
        }
예제 #5
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel != null)
            {
                BlockEntityBarrel beba = api.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityBarrel;

                var liqslot = beba?.Inventory[1];

                if (beba != null && !liqslot.Empty)
                {
                    if (liqslot.Itemstack.Item?.Code?.Path == "cottagecheeseportion")
                    {
                        var   props     = BlockLiquidContainerBase.GetContainableProps(liqslot.Itemstack);
                        float curLitres = liqslot.Itemstack.StackSize / props.ItemsPerLitre;

                        if (curLitres < 25)
                        {
                            (api as ICoreClientAPI)?.TriggerIngameError(this, "notenough", Lang.Get("Need at least 25 litres to create a roll of cheese"));
                            handHandling = EnumHandHandling.PreventDefault;
                            return;
                        }

                        if (api.World.Side == EnumAppSide.Server)
                        {
                            ItemStack ccStack = beba.Inventory[1].TakeOut((int)(25 * props.ItemsPerLitre));

                            BlockCheeseCurdsBundle block = api.World.GetBlock(new AssetLocation("curdbundle")) as BlockCheeseCurdsBundle;
                            ItemStack bundleStack        = new ItemStack(block);
                            block.SetContents(bundleStack, ccStack);

                            slot.TakeOut(1);
                            slot.MarkDirty();

                            beba.MarkDirty(true);

                            if (!byEntity.TryGiveItemStack(bundleStack))
                            {
                                api.World.SpawnItemEntity(bundleStack, byEntity.Pos.XYZ.AddCopy(0, 0.5, 0));
                            }
                        }

                        handHandling = EnumHandHandling.PreventDefault;
                        return;
                    }
                }
            }

            base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
        }
예제 #6
0
        private void fullnessMeterDraw(Context ctx, ImageSurface surface, ElementBounds currentBounds)
        {
            ItemSlot liquidSlot = Inventory[1];

            if (liquidSlot.Empty)
            {
                return;
            }

            int ravg = 0, gavg = 0, bavg = 0, aavg = 0;

            for (int i = 0; i < 10; i++)
            {
                int col = liquidSlot.Itemstack.Collectible.GetRandomColor(capi, liquidSlot.Itemstack);
                int r   = (col >> 16) & 0xff;
                int g   = (col >> 8) & 0xff;
                int b   = col & 0xff;
                int a   = (col >> 24) & 0xff;

                ravg += r;
                gavg += g;
                bavg += b;
                aavg += a;
            }

            ravg /= 10;
            gavg /= 10;
            bavg /= 10;
            aavg /= 10;


            int itemsPerLitre = 1;

            if (liquidSlot.Itemstack.ItemAttributes?["waterTightContainerProps"].Exists == true)
            {
                itemsPerLitre = liquidSlot.Itemstack.ItemAttributes["waterTightContainerProps"].AsInt(1);
            }

            BlockEntityBarrel bebarrel         = capi.World.BlockAccessor.GetBlockEntity(BlockEntityPosition) as BlockEntityBarrel;
            float             fullnessRelative = ((float)liquidSlot.StackSize / itemsPerLitre) / bebarrel.CapacityLitres;

            double offY = (1 - fullnessRelative) * currentBounds.InnerHeight;

            ctx.Rectangle(0, offY, currentBounds.InnerWidth, currentBounds.InnerHeight - offY);
            ctx.SetSourceRGBA(ravg / 255.0, gavg / 255.0, bavg / 255.0, aavg / 255.0);
            ctx.Fill();
        }
예제 #7
0
        public override string GetPlacedBlockInfo(IWorldAccessor world, BlockPos pos, IPlayer forPlayer)
        {
            string text = base.GetPlacedBlockInfo(world, pos, forPlayer);

            float litres = GetCurrentLitres(pos);

            if (litres <= 0)
            {
                text = "";
            }

            BlockEntityBarrel bebarrel = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityBarrel;

            if (bebarrel != null)
            {
                ItemSlot slot = bebarrel.Inventory[0];
                if (!slot.Empty)
                {
                    if (text.Length > 0)
                    {
                        text += "\n";
                    }
                    else
                    {
                        text += Lang.Get("Contents:") + "\n";
                    }

                    text += Lang.Get("{0}x {1}", slot.Itemstack.StackSize, slot.Itemstack.GetName());

                    text += PerishableInfoCompact(api, slot, 0, false);
                }

                if (bebarrel.Sealed && bebarrel.CurrentRecipe != null)
                {
                    double hoursPassed    = world.Calendar.TotalHours - bebarrel.SealedSinceTotalHours;
                    string timePassedText = hoursPassed > 24 ? Lang.Get("{0} days", Math.Round(hoursPassed / api.World.Calendar.HoursPerDay, 1)) : Lang.Get("{0} hours", Math.Round(hoursPassed));
                    string timeTotalText  = bebarrel.CurrentRecipe.SealHours > 24 ? Lang.Get("{0} days", Math.Round(bebarrel.CurrentRecipe.SealHours / api.World.Calendar.HoursPerDay, 1)) : Lang.Get("{0} hours", Math.Round(bebarrel.CurrentRecipe.SealHours));
                    text += "\n" + Lang.Get("Sealed for {0} / {1}", timePassedText, timeTotalText);
                }
            }


            return(text);
        }
예제 #8
0
        private void fullnessMeterDraw(Context ctx, ImageSurface surface, ElementBounds currentBounds)
        {
            ItemSlot liquidSlot = Inventory[1];

            if (liquidSlot.Empty)
            {
                return;
            }

            BlockEntityBarrel bebarrel      = capi.World.BlockAccessor.GetBlockEntity(BlockEntityPosition) as BlockEntityBarrel;
            float             itemsPerLitre = 1f;
            int capacity = bebarrel.CapacityLitres;

            WaterTightContainableProps props = BlockLiquidContainerBase.GetInContainerProps(liquidSlot.Itemstack);

            if (props != null)
            {
                itemsPerLitre = props.ItemsPerLitre;
                capacity      = Math.Max(capacity, props.MaxStackSize);
            }

            float fullnessRelative = liquidSlot.StackSize / itemsPerLitre / capacity;

            double offY = (1 - fullnessRelative) * currentBounds.InnerHeight;

            ctx.Rectangle(0, offY, currentBounds.InnerWidth, currentBounds.InnerHeight - offY);
            //ctx.SetSourceRGBA(ravg/255.0, gavg / 255.0, bavg / 255.0, aavg / 255.0);
            //ctx.Fill();

            CompositeTexture tex = liquidSlot.Itemstack.Collectible.Attributes?["waterTightContainerProps"]?["texture"]?.AsObject <CompositeTexture>(null, liquidSlot.Itemstack.Collectible.Code.Domain);

            if (tex != null)
            {
                ctx.Save();
                Matrix m = ctx.Matrix;
                m.Scale(GuiElement.scaled(3), GuiElement.scaled(3));
                ctx.Matrix = m;

                AssetLocation loc = tex.Base.Clone().WithPathAppendixOnce(".png");
                GuiElement.fillWithPattern(capi, ctx, loc.Path, true, false);

                ctx.Restore();
            }
        }
예제 #9
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel?.Position == null)
            {
                base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
                return;
            }

            Block block = api.World.BlockAccessor.GetBlock(blockSel.Position);

            if (block?.Attributes?.IsTrue("mealContainer") == true)
            {
                ServeIntoBowl(block, blockSel.Position, slot, byEntity.World);
                handHandling = EnumHandHandling.PreventDefault;
                return;
            }

            if (block is BlockCookingContainer && slot.Itemstack.Attributes.HasAttribute("recipeCode"))
            {
                handHandling = EnumHandHandling.PreventDefault;
                ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);

                string recipeCode       = slot.Itemstack.Attributes.GetString("recipeCode");
                float  quantityServings = (float)slot.Itemstack.Attributes.GetDecimal("quantityServings");

                float movedServings = (block as BlockCookingContainer).PutMeal(blockSel.Position, GetNonEmptyContents(api.World, slot.Itemstack), recipeCode, quantityServings);

                quantityServings -= movedServings;

                if (quantityServings > 0)
                {
                    slot.Itemstack.Attributes.SetFloat("quantityServings", quantityServings);
                }
                else
                {
                    slot.Itemstack.Attributes.RemoveAttribute("recipeCode");
                    slot.Itemstack.Attributes.RemoveAttribute("quantityServings");
                    slot.Itemstack.Attributes.RemoveAttribute("contents");
                }

                return;
            }

            if (block is BlockBarrel)
            {
                BlockEntityBarrel bebarrel = api.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityBarrel;
                if (bebarrel != null)
                {
                    ItemStack stack = bebarrel.inventory[0].Itemstack;

                    ItemStack[] ownContentStacks = GetNonEmptyContents(api.World, slot.Itemstack);
                    if (ownContentStacks == null || ownContentStacks.Length == 0)
                    {
                        if (stack != null && stack.Collectible.Attributes?.IsTrue("crockable") == true)
                        {
                            SetContents(null, slot.Itemstack, new ItemStack[] { bebarrel.inventory[0].TakeOut(4) }, 1);
                            bebarrel.MarkDirty(true);
                            slot.MarkDirty();
                        }
                    }
                    // non-meal items (eg. pickled vegetables) can be placed from a crock INTO a barrel - this is useful eg. for cheese-making
                    else if (ownContentStacks.Length == 1 && slot.Itemstack.Attributes.GetString("recipeCode") == null)
                    {
                        new DummySlot(ownContentStacks[0]).TryPutInto(api.World, bebarrel.inventory[0], ownContentStacks[0].StackSize);
                        if (ownContentStacks[0].StackSize <= 0)
                        {
                            SetContents(slot.Itemstack, new ItemStack[0]);
                        }
                        bebarrel.MarkDirty(true);
                        slot.MarkDirty();
                    }
                }

                handHandling = EnumHandHandling.PreventDefault;
                ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);
                return;
            }


            base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
        }
예제 #10
0
        public override void OnLoaded(ICoreAPI api)
        {
            base.OnLoaded(api);

            if (Attributes?["capacityLitres"].Exists == true)
            {
                capacityLitresFromAttributes = Attributes["capacityLitres"].AsInt(50);
            }


            if (api.Side != EnumAppSide.Client)
            {
                return;
            }
            ICoreClientAPI capi = api as ICoreClientAPI;

            interactions = ObjectCacheUtil.GetOrCreate(api, "liquidContainerBase", () =>
            {
                List <ItemStack> liquidContainerStacks = new List <ItemStack>();

                foreach (CollectibleObject obj in api.World.Collectibles)
                {
                    if (obj is ILiquidSource || obj is ILiquidSink || obj is BlockWateringCan)
                    {
                        List <ItemStack> stacks = obj.GetHandBookStacks(capi);
                        if (stacks != null)
                        {
                            liquidContainerStacks.AddRange(stacks);
                        }
                    }
                }

                ItemStack[] lstacks    = liquidContainerStacks.ToArray();
                ItemStack[] linenStack = new ItemStack[] { new ItemStack(api.World.GetBlock(new AssetLocation("linen-normal-down"))) };

                return(new WorldInteraction[] {
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-bucket-rightclick",
                        MouseButton = EnumMouseButton.Right,
                        Itemstacks = lstacks,
                        GetMatchingStacks = (wi, bs, ws) =>
                        {
                            BlockEntityBarrel bebarrel = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityBarrel;
                            return bebarrel?.Sealed == false ? lstacks : null;
                        }
                    },
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-barrel-takecottagecheese",
                        MouseButton = EnumMouseButton.Right,
                        HotKeyCode = "sneak",
                        Itemstacks = linenStack,
                        GetMatchingStacks = (wi, bs, ws) =>
                        {
                            BlockEntityBarrel bebarrel = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityBarrel;
                            if (bebarrel?.Inventory[1].Itemstack?.Item?.Code?.Path == "cottagecheeseportion")
                            {
                                return linenStack;
                            }
                            return null;
                        }
                    }
                });
            });
        }
예제 #11
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel?.Position == null)
            {
                base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
                return;
            }

            Block block            = api.World.BlockAccessor.GetBlock(blockSel.Position);
            float quantityServings = (float)slot.Itemstack.Attributes.GetDecimal("quantityServings");

            if (block?.Attributes?.IsTrue("mealContainer") == true)
            {
                if (!byEntity.Controls.Sneak)
                {
                    return;
                }
                if (quantityServings > 0)
                {
                    ServeIntoBowl(block, blockSel.Position, slot, byEntity.World);
                }
                handHandling = EnumHandHandling.PreventDefault;
                return;
            }


            if (block is BlockGroundStorage)
            {
                if (!byEntity.Controls.Sneak)
                {
                    return;
                }
                var      begs   = api.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityGroundStorage;
                ItemSlot gsslot = begs.GetSlotAt(blockSel);
                if (gsslot == null || gsslot.Empty)
                {
                    return;
                }

                if (gsslot.Itemstack.ItemAttributes?.IsTrue("mealContainer") == true)
                {
                    if (quantityServings > 0)
                    {
                        ServeIntoStack(gsslot, slot, byEntity.World);
                        gsslot.MarkDirty();
                        begs.updateMeshes();
                        begs.MarkDirty(true);
                    }

                    handHandling = EnumHandHandling.PreventDefault;
                    return;
                }
            }

            if (block is BlockCookingContainer && slot.Itemstack.Attributes.HasAttribute("recipeCode"))
            {
                handHandling = EnumHandHandling.PreventDefault;
                ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);

                string recipeCode = slot.Itemstack.Attributes.GetString("recipeCode");


                float movedServings = (block as BlockCookingContainer).PutMeal(blockSel.Position, GetNonEmptyContents(api.World, slot.Itemstack), recipeCode, quantityServings);

                quantityServings -= movedServings;

                if (quantityServings > 0)
                {
                    slot.Itemstack.Attributes.SetFloat("quantityServings", quantityServings);
                }
                else
                {
                    slot.Itemstack.Attributes.RemoveAttribute("recipeCode");
                    slot.Itemstack.Attributes.RemoveAttribute("quantityServings");
                    slot.Itemstack.Attributes.RemoveAttribute("contents");
                }

                return;
            }

            if (block is BlockBarrel)
            {
                BlockEntityBarrel bebarrel = api.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityBarrel;
                if (bebarrel != null)
                {
                    ItemStack stack = bebarrel.Inventory[0].Itemstack;

                    ItemStack[] ownContentStacks = GetNonEmptyContents(api.World, slot.Itemstack);
                    if (ownContentStacks == null || ownContentStacks.Length == 0)
                    {
                        if (stack != null && stack.Collectible.Attributes?.IsTrue("crockable") == true)
                        {
                            float servingCapacity = slot.Itemstack.Block.Attributes["servingCapacity"].AsFloat(1);

                            var   foodstack   = bebarrel.Inventory[0].TakeOut((int)servingCapacity * 4);
                            float servingSize = foodstack.StackSize / 4f;

                            foodstack.StackSize = Math.Max(0, foodstack.StackSize / 4);

                            SetContents(null, slot.Itemstack, new ItemStack[] { foodstack }, servingSize);
                            bebarrel.MarkDirty(true);
                            slot.MarkDirty();
                        }
                    }

                    // non-meal items (eg. pickled vegetables) can be placed from a crock INTO a barrel - this is useful eg. for cheese-making
                    else if (ownContentStacks.Length == 1 && slot.Itemstack.Attributes.GetString("recipeCode") == null)
                    {
                        var foodstack = ownContentStacks[0].Clone();
                        foodstack.StackSize = (int)(foodstack.StackSize * quantityServings);
                        new DummySlot(foodstack).TryPutInto(api.World, bebarrel.Inventory[0], foodstack.StackSize);
                        foodstack.StackSize = (int)(foodstack.StackSize / quantityServings);

                        if (foodstack.StackSize <= 0)
                        {
                            SetContents(slot.Itemstack, new ItemStack[0]);
                        }
                        else
                        {
                            SetContents(slot.Itemstack, new ItemStack[] { foodstack });
                        }

                        bebarrel.MarkDirty(true);
                        slot.MarkDirty();
                    }
                }

                handHandling = EnumHandHandling.PreventDefault;
                ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);
                return;
            }


            base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
        }
예제 #12
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel.Position == null)
            {
                base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
                return;
            }

            Block block = api.World.BlockAccessor.GetBlock(blockSel.Position);

            if (block?.Attributes?["mealcontainer"]?.AsBool() == true)
            {
                ServeIntoBowl(block, blockSel.Position, slot, byEntity.World);
                handHandling = EnumHandHandling.PreventDefault;
                return;
            }

            if (block is BlockCookingContainer && slot.Itemstack.Attributes.HasAttribute("recipeCode"))
            {
                handHandling = EnumHandHandling.PreventDefault;
                ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);

                string recipeCode       = slot.Itemstack.Attributes.GetString("recipeCode");
                int    quantityServings = slot.Itemstack.Attributes.GetInt("quantityServings");

                int movedServings = (block as BlockCookingContainer).PutMeal(blockSel.Position, GetContents(api.World, slot.Itemstack), recipeCode, quantityServings);

                quantityServings -= movedServings;

                if (quantityServings > 0)
                {
                    slot.Itemstack.Attributes.SetInt("quantityServings", quantityServings);
                }
                else
                {
                    slot.Itemstack.Attributes.RemoveAttribute("recipeCode");
                    slot.Itemstack.Attributes.RemoveAttribute("quantityServings");
                    slot.Itemstack.Attributes.RemoveAttribute("contents");
                }

                return;
            }

            if (block is BlockBarrel)
            {
                BlockEntityBarrel bebarrel = api.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityBarrel;
                ItemStack         stack    = bebarrel.inventory[0].Itemstack;

                ItemStack[] ownContentStacks = GetNonEmptyContents(api.World, slot.Itemstack);
                if (ownContentStacks == null || ownContentStacks.Length == 0)
                {
                    if (stack != null && stack.Collectible.Attributes["crockable"].AsBool() == true)
                    {
                        SetContents(slot.Itemstack, new ItemStack[] { bebarrel.inventory[0].TakeOut(4) });
                        bebarrel.MarkDirty(true);
                    }
                }
                else
                {
                    if (stack != null)
                    {
                        new DummySlot(ownContentStacks[0]).TryPutInto(api.World, bebarrel.inventory[0], ownContentStacks[0].StackSize);
                        if (ownContentStacks[0].StackSize <= 0)
                        {
                            SetContents(slot.Itemstack, new ItemStack[0]);
                        }
                        bebarrel.MarkDirty(true);
                        slot.MarkDirty();
                    }
                }


                handHandling = EnumHandHandling.PreventDefault;
                ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);
                return;
            }


            base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
        }