Exemplo n.º 1
0
        public override void OnHeldInteractStart(IItemSlot itemslot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling)
        {
            if (blockSel == null || byEntity.Controls.Sneak)
            {
                return;
            }
            IPlayer byPlayer = (byEntity as EntityPlayer)?.Player;

            Block targetedBlock = byEntity.World.BlockAccessor.GetBlock(blockSel.Position);

            if (targetedBlock.HasBehavior(typeof(BlockBehaviorLiquidContainer), true))
            {
                if (!byEntity.World.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.Use))
                {
                    return;
                }

                BlockBehaviorLiquidContainer bh = targetedBlock.GetBehavior(typeof(BlockBehaviorLiquidContainer), true) as BlockBehaviorLiquidContainer;

                if (bh.OnInteractWithBucket(itemslot, byEntity, blockSel))
                {
                    handHandling = EnumHandHandling.PreventDefaultAction;
                    return;
                }
            }


            if (!byEntity.World.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak))
            {
                return;
            }

            ItemStack contentStack = GetContent(byEntity.World, itemslot.Itemstack);

            bool isEmpty = contentStack == null;


            if (!TryFillBucketFromBlock(itemslot, byEntity, blockSel.Position))
            {
                BlockBucket targetBucket = targetedBlock as BlockBucket;
                if (targetBucket != null)
                {
                    if (targetBucket.TryAddContent(byEntity.World, blockSel.Position, contentStack, 1) > 0)
                    {
                        TryTakeContent(byEntity.World, itemslot.Itemstack, 1);
                        WaterTightContainableProps props = GetContentProps(byEntity.World, itemslot.Itemstack);

                        byEntity.World.PlaySoundAt(props.FillSpillSound, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer);
                    }
                }
                else
                {
                    SpillContents(itemslot, byEntity, blockSel);
                }
            }

            // Prevent placing on normal use
            handHandling = EnumHandHandling.PreventDefaultAction;
        }
Exemplo n.º 2
0
        protected override void ActivateSlotRightClick(ItemSlot sourceSlot, ref ItemStackMoveOperation op)
        {
            IWorldAccessor world       = inventory.Api.World;
            BlockBucket    bucketblock = sourceSlot.Itemstack?.Block as BlockBucket;

            if (bucketblock != null)
            {
                if (Empty)
                {
                    return;
                }

                ItemStack bucketContents = bucketblock.GetContent(world, sourceSlot.Itemstack);

                if (bucketContents == null)
                {
                    TakeOut(bucketblock.TryAddContent(world, sourceSlot.Itemstack, Itemstack, 1));
                    MarkDirty();
                }
                else
                {
                    if (itemstack.Equals(world, bucketContents, GlobalConstants.IgnoredStackAttributes))
                    {
                        TakeOut(bucketblock.TryAddContent(world, sourceSlot.Itemstack, bucketblock.GetContent(world, sourceSlot.Itemstack), 1));
                        MarkDirty();
                        return;
                    }
                }


                return;
            }


            base.ActivateSlotRightClick(sourceSlot, ref op);
        }
Exemplo n.º 3
0
        public override void OnHeldInteractStop(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (blockSel == null)
            {
                return;
            }
            if (secondsUsed < 1.9f)
            {
                return;
            }

            IWorldAccessor world = byEntity.World;

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

            if (!CanSqueezeInto(block))
            {
                return;
            }

            BlockBucket blockbucket = block as BlockBucket;

            if (blockbucket != null)
            {
                if (blockbucket.TryAddContent(world, blockSel.Position, new ItemStack(world.GetItem(new AssetLocation("honeyportion"))), 1) == 0)
                {
                    return;
                }
            }
            else
            {
                world.BlockAccessor.SetBlock(world.GetBlock(new AssetLocation("bowl-honey")).BlockId, blockSel.Position);
            }

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

            IPlayer byPlayer = null;

            if (byEntity is IEntityPlayer)
            {
                byPlayer = world.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID);
            }
            byPlayer?.InventoryManager.TryGiveItemstack(new ItemStack(world.GetItem(new AssetLocation("beeswax"))));
        }
Exemplo n.º 4
0
        public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling)
        {
            if (blockSel == null)
            {
                base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, ref handHandling);
                return;
            }

            BlockBucket blockbucket = byEntity.World.BlockAccessor.GetBlock(blockSel.Position) as BlockBucket;
            string      contents    = BowlContents();

            if (blockbucket != null)
            {
                if (contents == null)
                {
                    ItemStack stack = blockbucket.GetContent(byEntity.World, blockSel.Position);
                    if (stack?.Collectible.Code.Path == "honeyportion")
                    {
                        InsertHoney(slot, byEntity);
                        blockbucket.TryTakeContent(byEntity.World, blockSel.Position, 1);
                    }
                }
                else
                {
                    ItemStack stack = blockbucket.GetContent(byEntity.World, blockSel.Position);
                    if (stack == null || stack.Collectible.Code.Path == "honeyportion")
                    {
                        Item honeyitem = byEntity.World.GetItem(new AssetLocation("honeyportion"));
                        if (blockbucket.TryAddContent(byEntity.World, blockSel.Position, new ItemStack(honeyitem), 1) > 0)
                        {
                            TakeoutHoney(slot, byEntity);
                        }
                    }
                }

                handHandling = EnumHandHandling.PreventDefaultAction;
                return;
            }

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