public EntityBlockFalling(Block block, BlockEntity blockEntity, BlockPos initialPos, AssetLocation fallSound, float impactDamageMul, bool canFallSideways, float dustIntensity)
        {
            this.impactDamageMul = impactDamageMul;
            this.fallSound       = fallSound;
            this.canFallSideways = canFallSideways;
            this.dustIntensity   = dustIntensity;

            WatchedAttributes.SetBool("canFallSideways", canFallSideways);
            WatchedAttributes.SetFloat("dustIntensity", dustIntensity);
            if (fallSound != null)
            {
                WatchedAttributes.SetString("fallSound", fallSound.ToShortString());
            }

            this.Code               = new AssetLocation("blockfalling");
            this.blockCode          = block.Code;
            this.removedBlockentity = blockEntity;
            this.initialPos         = initialPos.Copy(); // Must have a Copy() here!

            ServerPos.SetPos(initialPos);
            ServerPos.X += 0.5;
            ServerPos.Z += 0.5;

            Pos.SetFrom(ServerPos);
        }
        public override void OnGameTick(float dt)
        {
            if (World.Side == EnumAppSide.Server)
            {
                base.OnGameTick(dt);
                return;
            }

            if (!AnimManager.ActiveAnimationsByAnimCode.ContainsKey("feed"))
            {
                if (ServerPos.Y < Pos.Y - 0.25 && !Collided)
                {
                    SetAnimation("glide", 1);
                }
                else
                {
                    SetAnimation("fly", 2);
                }
            }


            base.OnGameTick(dt);

            if (ServerPos.SquareDistanceTo(Pos.XYZ) > 0.01)
            {
                float desiredYaw = (float)Math.Atan2(ServerPos.X - Pos.X, ServerPos.Z - Pos.Z);

                float yawDist = GameMath.AngleRadDistance(LocalPos.Yaw, desiredYaw);
                Pos.Yaw += GameMath.Clamp(yawDist, -35 * dt, 35 * dt);
                Pos.Yaw  = Pos.Yaw % GameMath.TWOPI;
            }
        }
Example #3
0
        public EntityStackedBlockFalling(Block block, BlockEntity blockEntity, BlockPos initialPos)
        {
            this.Code               = new AssetLocation("blockfalling");
            this.blockCode          = block.Code;
            this.removedBlockentity = blockEntity;
            this.initialPos         = initialPos;

            ServerPos.SetPos(initialPos);
            ServerPos.X += 0.5;
            ServerPos.Z += 0.5;

            Pos.SetFrom(ServerPos);
        }
Example #4
0
        public override void TeleportToDouble(double x, double y, double z, Action onTeleported = null)
        {
            Teleporting = true;
            ICoreServerAPI sapi = this.World.Api as ICoreServerAPI;

            if (sapi != null)
            {
                sapi.WorldManager.LoadChunkColumnPriority((int)ServerPos.X / World.BlockAccessor.ChunkSize, (int)ServerPos.Z / World.BlockAccessor.ChunkSize, new ChunkLoadOptions()
                {
                    OnLoaded = () =>
                    {
                        Pos.SetPos(x, y, z);
                        ServerPos.SetPos(x, y, z);
                        PreviousServerPos.SetPos(-99, -99, -99);
                        PositionBeforeFalling.Set(x, y, z);
                        Pos.Motion.Set(0, 0, 0);
                        if (this is EntityPlayer)
                        {
                            sapi.Network.BroadcastEntityPacket(EntityId, 1, SerializerUtil.Serialize(ServerPos.XYZ));
                            IServerPlayer player          = this.Player as IServerPlayer;
                            int chunksize                 = World.BlockAccessor.ChunkSize;
                            player.CurrentChunkSentRadius = 0;

                            sapi.Event.RegisterCallback((bla) => {
                                if (player.ConnectionState == EnumClientState.Offline)
                                {
                                    return;
                                }

                                if (!sapi.WorldManager.HasChunk((int)x / chunksize, (int)y / chunksize, (int)z / chunksize, player))
                                {
                                    sapi.WorldManager.SendChunk((int)x / chunksize, (int)y / chunksize, (int)z / chunksize, player, false);
                                }

                                // Oherwise we get an endlessly looping exception spam and break the server
                                player.CurrentChunkSentRadius = 0;
                            }, 50);
                        }

                        WatchedAttributes.SetInt("positionVersionNumber", WatchedAttributes.GetInt("positionVersionNumber", 0) + 1);


                        onTeleported?.Invoke();

                        Teleporting = false;
                    },
                });
            }
        }
        public override void OnGameTick(float dt)
        {
            if (World.Side == EnumAppSide.Server)
            {
                base.OnGameTick(dt);
                return;
            }

            if (!AnimManager.ActiveAnimationsByAnimCode.ContainsKey("feed") && !AnimManager.ActiveAnimationsByAnimCode.ContainsKey("rest"))
            {
                if (ServerPos.Y < Pos.Y - 0.05 && !Collided)
                {
                    SetAnimation("glide", 1);
                }

                if ((ServerPos.Y > Pos.Y - 0.02 || Collided) && !FeetInLiquid)
                {
                    SetAnimation("fly", 2.5f);
                }

                if (FeetInLiquid)
                {
                    (Properties.Client.Renderer as EntityShapeRenderer).AddRenderFlags |= 1 << 12;
                }
                else
                {
                    (Properties.Client.Renderer as EntityShapeRenderer).AddRenderFlags &= ~(1 << 12);
                }

                if (FeetInLiquid && flapPauseDt <= 0 && Api.World.Rand.NextDouble() < 0.07)
                {
                    flapPauseDt = 2 + 6 * (float)Api.World.Rand.NextDouble();
                    StopAnimation("fly");
                }

                if (flapPauseDt > 0)
                {
                    flapPauseDt -= dt;

                    if (flapPauseDt <= 0)
                    {
                        SetAnimation("fly", 2.5f);
                    }
                }
                else
                {
                    if (FeetInLiquid)
                    {
                        EntityPos herepos = Pos;
                        double    width   = SelectionBox.XSize * 0.75f;

                        SplashParticleProps.BasePos.Set(herepos.X - width / 2, herepos.Y - 0.05, herepos.Z - width / 2);
                        SplashParticleProps.AddPos.Set(width, 0, width);

                        SplashParticleProps.AddVelocity.Set(0, 0, 0);
                        SplashParticleProps.QuantityMul = 0.01f;

                        World.SpawnParticles(SplashParticleProps);

                        SpawnWaterMovementParticles(1, 0, +0.05, 0);
                    }
                }
            }


            base.OnGameTick(dt);

            if (cnt++ > 30)
            {
                float affectedness = World.BlockAccessor.GetLightLevel(SidedPos.XYZ.AsBlockPos, EnumLightLevelType.OnlySunLight) < 14 ? 1 : 0;
                windMotion = Api.ModLoader.GetModSystem <WeatherSystemBase>().WeatherDataSlowAccess.GetWindSpeed(SidedPos.XYZ) * affectedness;
                cnt        = 0;
            }

            if (AnimManager.ActiveAnimationsByAnimCode.ContainsKey("fly"))
            {
                SidedPos.X += Math.Max(0, (windMotion - 0.2) / 20.0);
            }

            if (ServerPos.SquareDistanceTo(Pos.XYZ) > 0.01 && !FeetInLiquid)
            {
                float desiredYaw = (float)Math.Atan2(ServerPos.X - Pos.X, ServerPos.Z - Pos.Z);

                float yawDist = GameMath.AngleRadDistance(SidedPos.Yaw, desiredYaw);
                Pos.Yaw += GameMath.Clamp(yawDist, -35 * dt, 35 * dt);
                Pos.Yaw  = Pos.Yaw % GameMath.TWOPI;
            }
        }