Ejemplo n.º 1
0
        public override void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent 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.TryPutContent(world, blockSel.Position, new ItemStack(world.GetItem(new AssetLocation("honeyportion"))), 1) == 0)
                {
                    return;
                }
            }
            else
            {
                AssetLocation loc = new AssetLocation(block.Attributes["contentItem2BlockCodes"]["honeyportion"].AsString());
                world.BlockAccessor.SetBlock(world.GetBlock(loc).BlockId, blockSel.Position);
            }

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

            IPlayer byPlayer = null;

            if (byEntity is EntityPlayer)
            {
                byPlayer = world.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
            }
            byPlayer?.InventoryManager.TryGiveItemstack(new ItemStack(world.GetItem(new AssetLocation("beeswax"))));
        }
Ejemplo n.º 2
0
        public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel == null || byEntity.Controls.Sneak)
            {
                return;
            }
            IPlayer byPlayer = (byEntity as EntityPlayer)?.Player;

            ItemStack contentStack = GetContent(byEntity.World, itemslot.Itemstack);
            bool      isEmpty      = contentStack == null || contentStack.StackSize == 0;

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

            if (!byEntity.World.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak))
            {
                byEntity.World.BlockAccessor.MarkBlockDirty(blockSel.Position.AddCopy(blockSel.Face));
                byPlayer?.InventoryManager.ActiveHotbarSlot?.MarkDirty();
                return;
            }

            if (!TryFillFromBlock(itemslot, byEntity, blockSel.Position))
            {
                BlockBucket targetBucket = targetedBlock as BlockBucket;
                if (targetBucket != null)
                {
                    WaterTightContainableProps props = GetContentProps(byEntity.World, itemslot.Itemstack);

                    if (targetBucket.TryPutContent(byEntity.World, blockSel.Position, contentStack, 1) > 0)
                    {
                        TryTakeContent(byEntity.World, itemslot.Itemstack, 1);
                        byEntity.World.PlaySoundAt(props.FillSpillSound, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer);
                    }
                }
                else
                {
                    if (byPlayer.WorldData.EntityControls.Sprint)
                    {
                        SpillContents(itemslot, byEntity, blockSel);
                    }
                }
            }

            // Prevent placing on normal use
            handHandling = EnumHandHandling.PreventDefaultAction;
        }
Ejemplo n.º 3
0
        public override string GetPlacedBlockInfo(IWorldAccessor world, BlockPos pos, IPlayer forPlayer)
        {
            string text = base.GetPlacedBlockInfo(world, pos, forPlayer);

            float litres = GetCurrentLitres(world, 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 += BlockBucket.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);
        }
Ejemplo 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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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.TryPutContent(world, sourceSlot.Itemstack, Itemstack, 1));
                    MarkDirty();
                }
                else
                {
                    if (itemstack.Equals(world, bucketContents, GlobalConstants.IgnoredStackAttributes))
                    {
                        TakeOut(bucketblock.TryPutContent(world, sourceSlot.Itemstack, bucketblock.GetContent(world, sourceSlot.Itemstack), 1));
                        MarkDirty();
                        return;
                    }
                }

                return;
            }


            if (itemstack != null && sourceSlot.Itemstack?.ItemAttributes?["contentItem2BlockCodes"].Exists == true)
            {
                string outBlockCode = sourceSlot.Itemstack.ItemAttributes["contentItem2BlockCodes"][itemstack.Collectible.Code.ToShortString()].AsString();

                if (outBlockCode != null)
                {
                    ItemStack outBlockStack = new ItemStack(world.GetBlock(AssetLocation.Create(outBlockCode, sourceSlot.Itemstack.Collectible.Code.Domain)));

                    if (sourceSlot.StackSize == 1)
                    {
                        sourceSlot.Itemstack = outBlockStack;
                    }
                    else
                    {
                        sourceSlot.Itemstack.StackSize--;
                        if (!op.ActingPlayer.InventoryManager.TryGiveItemstack(outBlockStack))
                        {
                            world.SpawnItemEntity(outBlockStack, op.ActingPlayer.Entity.Pos.XYZ);
                        }
                    }

                    sourceSlot.MarkDirty();
                    TakeOut(1);
                }

                return;
            }

            if (sourceSlot.Itemstack?.ItemAttributes?["contentItem2BlockCodes"].Exists == true || sourceSlot.Itemstack?.ItemAttributes?["contentItemCode"].AsString() != null)
            {
                return;
            }

            base.ActivateSlotRightClick(sourceSlot, ref op);
        }
Ejemplo n.º 7
0
        protected override void ActivateSlotLeftClick(ItemSlot sourceSlot, ref ItemStackMoveOperation op)
        {
            IWorldAccessor world       = inventory.Api.World;
            BlockBucket    bucketblock = sourceSlot.Itemstack?.Block as BlockBucket;

            if (bucketblock != null)
            {
                ItemStack bucketContents = bucketblock.GetContent(world, sourceSlot.Itemstack);
                bool      stackable      = !Empty && itemstack.Equals(world, bucketContents, GlobalConstants.IgnoredStackAttributes);

                if ((Empty || stackable) && bucketContents != null)
                {
                    ItemStack bucketStack  = sourceSlot.Itemstack;
                    ItemStack takenContent = bucketblock.TryTakeContent(world, bucketStack, op.ActingPlayer?.Entity?.Controls.Sneak == true ? 10 : 1);
                    sourceSlot.Itemstack    = bucketStack;
                    takenContent.StackSize += StackSize;
                    this.itemstack          = takenContent;
                    MarkDirty();
                    return;
                }

                return;
            }

            string contentItemCode = sourceSlot.Itemstack?.ItemAttributes?["contentItemCode"].AsString();

            if (contentItemCode != null)
            {
                ItemStack contentStack = new ItemStack(world.GetItem(AssetLocation.Create(contentItemCode, sourceSlot.Itemstack.Collectible.Code.Domain)));
                bool      stackable    = !Empty && itemstack.Equals(world, contentStack, GlobalConstants.IgnoredStackAttributes);

                if ((Empty || stackable) && contentStack != null)
                {
                    if (stackable)
                    {
                        this.itemstack.StackSize++;
                    }
                    else
                    {
                        this.itemstack = contentStack;
                    }

                    MarkDirty();
                    ItemStack bowlStack = new ItemStack(world.GetBlock(AssetLocation.Create(sourceSlot.Itemstack.ItemAttributes["emptiedBlockCode"].AsString(), sourceSlot.Itemstack.Collectible.Code.Domain)));
                    if (sourceSlot.StackSize == 1)
                    {
                        sourceSlot.Itemstack = bowlStack;
                    }
                    else
                    {
                        sourceSlot.Itemstack.StackSize--;
                        if (!op.ActingPlayer.InventoryManager.TryGiveItemstack(bowlStack))
                        {
                            world.SpawnItemEntity(bowlStack, op.ActingPlayer.Entity.Pos.XYZ);
                        }
                    }
                    sourceSlot.MarkDirty();
                }

                return;
            }

            if (sourceSlot.Itemstack?.ItemAttributes?["contentItem2BlockCodes"].Exists == true)
            {
                return;
            }

            base.ActivateSlotLeftClick(sourceSlot, ref op);
        }
Ejemplo n.º 8
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel == null)
            {
                return;
            }
            if (byEntity.Controls.Sneak)
            {
                return;
            }

            slot.Itemstack.TempAttributes.SetFloat("secondsUsed", 0);

            IPlayer byPlayer = null;

            if (byEntity is EntityPlayer)
            {
                byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
            }

            if (byEntity.World.BlockAccessor.GetBlock(blockSel.Position).LiquidCode == "water")
            {
                BlockPos pos = blockSel.Position;
                SetRemainingWateringSeconds(slot.Itemstack, CapacitySeconds);
                slot.Itemstack.TempAttributes.SetInt("refilled", 1);
                slot.MarkDirty();

                byEntity.World.PlaySoundAt(new AssetLocation("sounds/block/water"), pos.X, pos.Y, pos.Z, byPlayer);
                handHandling = EnumHandHandling.PreventDefault;
                return;
            }

            BlockBucket bucket = byEntity.World.BlockAccessor.GetBlock(blockSel.Position) as BlockBucket;

            if (bucket != null && bucket.GetContent(byEntity.World, blockSel.Position)?.Block?.LiquidCode == "water")
            {
                BlockPos  pos        = blockSel.Position;
                ItemStack takenWater = bucket.TryTakeContent(byEntity.World, blockSel.Position, 5);
                SetRemainingWateringSeconds(slot.Itemstack, CapacitySeconds * takenWater.StackSize / 5f);
                slot.Itemstack.TempAttributes.SetInt("refilled", 1);
                slot.MarkDirty();

                byEntity.World.PlaySoundAt(new AssetLocation("sounds/block/water"), pos.X, pos.Y, pos.Z, byPlayer);
                handHandling = EnumHandHandling.PreventDefault;
            }


            slot.Itemstack.TempAttributes.SetInt("refilled", 0);
            float remainingwater = GetRemainingWateringSeconds(slot.Itemstack);

            if (remainingwater <= 0)
            {
                return;
            }

            if (byEntity.World.Side == EnumAppSide.Client)
            {
                byEntity.World.RegisterCallback(After350ms, 350);
            }

            handHandling = EnumHandHandling.PreventDefault;
        }