Vintagestory.GameContent.BEBehaviorFruiting.OnPlayerInteract C# (CSharp) Method

OnPlayerInteract() public method

public OnPlayerInteract ( float secondsUsed, IPlayer player, Vec3d hit ) : bool
secondsUsed float
player IPlayer
hit Vec3d
return bool
        public virtual bool OnPlayerInteract(float secondsUsed, IPlayer player, Vec3d hit)
        {
            if (player?.InventoryManager?.ActiveTool != EnumTool.Knife) return false;

            if (Api.Side == EnumAppSide.Server) return true;

            bool hasPickableFruit = false;
            for (int i = 0; i < fruitPoints.Length; i++)
            {
                FruitData val = fruitPoints[i];
                if (val.variant >= 0 && val.currentStage >= this.ripeStage)
                {
                    Item item = Api.World.GetItem(new AssetLocation(fruitCodeBases[val.variant] + val.currentStage));
                    if (item == null) continue;
                    if (item.Attributes != null && item.Attributes["onGround"].AsBool(false)) continue;  // ignore fruits already on the ground

                    hasPickableFruit = true;
                    break;
                }
           }

            return hasPickableFruit && secondsUsed < 0.3f;
        }

Usage Example

Ejemplo n.º 1
0
        public override bool OnBlockInteractStep(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            BEBehaviorFruiting bef = world.BlockAccessor.GetBlockEntity(blockSel.Position)?.GetBehavior<BEBehaviorFruiting>();
            if (bef != null) return bef.OnPlayerInteract(secondsUsed, byPlayer, blockSel.HitPosition);

            return base.OnBlockInteractStep(secondsUsed, world, byPlayer, blockSel);
        }