Beispiel #1
0
        public virtual void OnTick(Entity[] entities)
        {
            SeenEntities.Clear();
            UnseenEntities.Clear();
            Age++;

            HealthManager.OnTick();
        }
Beispiel #2
0
        public virtual void OnTick()
        {
            SeenEntities.Clear();
            UnseenEntities.Clear();

            Age++;

            HealthManager.OnTick();

            if (_isHit && Age > _hitAnimationEnd)
            {
                _isHit = false;
                ModelRenderer.EntityColor = Color.White.ToVector3();
            }

            if (DoRotationCalculations)
            {
                UpdateRotations();
            }
            else
            {
                KnownPosition.Yaw = KnownPosition.HeadYaw;
            }

            _previousPosition = KnownPosition;

            if (ServerEntity && DateTime.UtcNow >= NextUpdate)
            {
                var distanceMoved = DistanceMoved;
                DistanceMoved = 0;

                //PreviousUpdate
                _mvSpeed = (float)(distanceMoved * (TimeSpan.FromSeconds(1) / (DateTime.UtcNow - PreviousUpdate)));

                PreviousUpdate = DateTime.UtcNow;
                NextUpdate     = DateTime.UtcNow + TimeSpan.FromMilliseconds(500);
            }

            if (IsNoAi)
            {
                return;
            }
            //	IsMoving = Velocity.LengthSquared() > 0f;

            var knownPos  = new BlockCoordinates(new Vector3(KnownPosition.X, KnownPosition.Y, KnownPosition.Z));
            var knownDown = KnownPosition.GetCoordinates3D();

            if (!(Network is JavaNetworkProvider))
            {
                knownDown = knownDown.BlockDown();
            }

            var blockBelowFeet = Level?.GetBlockStates(knownDown.X, knownDown.Y, knownDown.Z);
            var feetBlock      = Level?.GetBlockStates(knownPos.X, knownPos.Y, knownPos.Z).ToArray();
            var headBlock      = Level?.GetBlock(KnownPosition.GetCoordinates3D() + new BlockCoordinates(0, 1, 0));

            if (headBlock != null)
            {
                if (headBlock.BlockMaterial == Material.Water || headBlock.IsWater)
                {
                    HeadInWater = true;
                }
                else
                {
                    HeadInWater = false;
                }
            }

            if (blockBelowFeet != null)
            {
                if (blockBelowFeet.Any(b => b.State.Block.BlockMaterial == Material.Water || b.State.Block.IsWater))
                {
                    AboveWater = true;
                }
                else
                {
                    AboveWater = false;
                }
            }
            else
            {
                AboveWater = false;
            }

            if (feetBlock != null)
            {
                if (feetBlock.Any(b => b.State.Block.BlockMaterial == Material.Water || b.State.Block.IsWater))
                {
                    FeetInWater = true;
                }
                else
                {
                    FeetInWater = false;
                }

                if (feetBlock.Any(b => b.State.Block.BlockMaterial == Material.Lava))
                {
                    IsInLava = true;
                }
                else
                {
                    IsInLava = false;
                }

                if (!feetBlock.Any(x => x.Storage == 0 && x.State.Block.Solid))
                {
                    KnownPosition.OnGround = false;
                }
            }

            IsInWater = FeetInWater || HeadInWater;

            /*
             * if (headBlock != null)
             * {
             *      if (headBlock.IsWater)
             *      {
             *              IsInWater = true;
             *      }
             *      else
             *      {
             *              IsInWater = false;
             *      }
             * }*/

            //HealthManager.OnTick();
        }