Exemple #1
0
        /// <summary>
        /// Ticks the physics entity.
        /// </summary>
        public override void Tick()
        {
            if (!TheRegion.IsVisible(GetPosition()))
            {
                if (Body.ActivityInformation.IsActive)
                {
                    wasActive = true;
                    // TODO: Is this needed?
                    if (Body.ActivityInformation.SimulationIsland != null)
                    {
                        Body.ActivityInformation.SimulationIsland.IsActive = false;
                    }
                }
            }
            else if (wasActive)
            {
                wasActive = false;
                Body.ActivityInformation.Activate();
            }
            Vector3i cpos = TheRegion.ChunkLocFor(GetPosition());

            if (CanSave && !TheRegion.TryFindChunk(cpos, out Chunk _)) // TODO: is this really needed every tick?
            {
                TheRegion.LoadChunk(cpos);
            }
            if (!GenBlockShadow)// TODO: and world config allows trackables
            {
                if (TheRegion.GetEntitiesInRadius(GetPosition(), 1.5f, EntityType.SMASHER_PRIMTIVE).Count == 0)
                {
                    // TODO: 5 * 60 -> world config
                    TheRegion.SpawnEntity(new SmasherPrimitiveEntity(TheRegion, Math.Min((float)GetScaleEstimate(), 2f), TheRegion.TheWorld.GlobalTickTime + (5 * 60))
                    {
                        Position = GetPosition()
                    });
                }
            }
            // TODO: More genericish
            if (TheRegion.Generator is SphereGeneratorCore)
            {
                Location pos   = new Location(Body.Position);
                double   scale = TheRegion.TheWorld.GeneratorScale;
                Location gravDir;
                if (pos.LengthSquared() > scale * scale)
                {
                    gravDir = new Location(scale / pos.X, scale / pos.Y, scale / pos.Z);
                }
                else
                {
                    gravDir = pos / scale;
                }
                SetGravity(gravDir * (-TheRegion.GravityStrength));
            }
        }