public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel == null || byEntity.Controls.Sneak)
            {
                base.OnHeldInteractStart(itemslot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
                return;
            }

            IPlayer byPlayer = (byEntity as EntityPlayer)?.Player;

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

            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 (byEntity.Controls.Sprint)
                    {
                        SpillContents(itemslot, byEntity, blockSel);
                    }
                }
            }

            // Prevent placing on normal use
            handHandling = EnumHandHandling.PreventDefaultAction;
        }
Esempio n. 2
0
        public override void OnInteract(EntityAgent byEntity, ItemSlot itemslot, Vec3d hitPosition, EnumInteractMode mode, ref EnumHandling handled)
        {
            if (itemslot.Itemstack == null)
            {
                return;
            }
            if (itemslot.Itemstack.Block is BlockBucket)
            {
                handled = EnumHandling.PreventDefault;
                ItemStack milkstack = new ItemStack(milk, RemainingLiters);

                BlockBucket bucket   = itemslot.Itemstack.Block as BlockBucket;
                ItemStack   contents = bucket.GetContent(byEntity.World, itemslot.Itemstack);
                if ((contents == null || contents.Item == milk) && RemainingLiters > 0)
                {
                    if (contents?.StackSize != null && contents.StackSize / milkProps.ItemsPerLitre >= bucket.CapacityLitres)
                    {
                        return;
                    }
                    DummySlot slot = new DummySlot(itemslot.TakeOut(1));

                    int taken = bucket.TryPutContent(byEntity.World, slot.Itemstack, milkstack, 1);
                    if (taken > 0)
                    {
                        RemainingLiters -= taken;
                        if (byEntity.World.Side == EnumAppSide.Client)
                        {
                            byEntity.World.SpawnCubeParticles(entity.Pos.XYZ + new Vec3d(0, 0.5, 0), milkstack, 0.3f, 4, 0.5f, (byEntity as EntityPlayer)?.Player);
                        }
                        if (id == 0 && RemainingLiters < defaultvalue)
                        {
                            if (NextTimeMilkable == 0)
                            {
                                NextTimeMilkable = GetNextTimeMilkable();
                            }
                            id = entity.World.RegisterGameTickListener(MilkListener, 1000);
                        }
                        byEntity.TryGiveItemStack(slot.Itemstack);
                        itemslot.MarkDirty();
                    }
                }
            }

            base.OnInteract(byEntity, itemslot, hitPosition, mode, ref handled);
        }
Esempio n. 3
0
        public override void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (blockSel == null || slot.Itemstack.Collectible.Variant["contents"] == "curds" || slot.Itemstack.Collectible.Variant["contents"] == "cheese")
            {
                return;
            }
            BlockPos pos      = blockSel.Position;
            Block    selBlock = api.World.BlockAccessor.GetBlock(pos);

            if (api.World.Side.IsServer())
            {
                if (selBlock is BlockBucket)
                {
                    BlockBucket bucket = selBlock as BlockBucket;
                    WaterTightContainableProps contentProps = bucket.GetContentProps(byEntity.World, pos);
                    if (bucket.GetContent(byEntity.World, pos) != null)
                    {
                        ItemStack contents = bucket.GetContent(byEntity.World, pos);
                        if (contents.Item.Code.Path == "curdsportion" && slot.Itemstack.Collectible.Variant["contents"] == "none")
                        {
                            ItemStack curdsandwhey = new ItemStack(CodeWithPart("curdsandwhey", 2).GetBlock(api), 1);

                            bucket.TryTakeContent(api.World, pos, 2);

                            TryGiveItem(curdsandwhey, slot, byEntity, contentProps, pos);
                            return;
                        }
                    }
                    if ((bucket.GetContent(byEntity.World, pos) == null || bucket.GetContent(byEntity.World, pos).Item.Code.Path == "wheyportion") && slot.Itemstack.Collectible.Variant["contents"] == "curdsandwhey")
                    {
                        ItemStack curds       = new ItemStack(CodeWithPart("curds", 2).GetBlock(api), 1);
                        ItemStack wheyportion = new ItemStack(new AssetLocation("wheyportion").GetItem(api), 1);
                        bucket.TryPutContent(api.World, pos, wheyportion, 1);

                        TryGiveItem(curds, slot, byEntity, contentProps, pos);
                        return;
                    }
                }
            }
            slot.MarkDirty();
        }