Пример #1
0
        void FindHighestFree(ref Vector3 spawn)
        {
            AABB bb = AABB.Make(spawn, entity.Size);

            Vector3I P = Vector3I.Floor(spawn);

            // Spawn player at highest valid position.
            for (int y = P.Y; y <= game.World.Height; y++)
            {
                float spawnY = Respawn.HighestFreeY(game, ref bb);
                if (spawnY == float.NegativeInfinity)
                {
                    BlockID block  = game.World.GetPhysicsBlock(P.X, y, P.Z);
                    float   height = BlockInfo.Collide[block] == CollideType.Solid ? BlockInfo.MaxBB[block].Y : 0;
                    spawn.Y = y + height + Entity.Adjustment;
                    return;
                }
                bb.Min.Y += 1; bb.Max.Y += 1;
            }
        }
Пример #2
0
        void DoRespawn()
        {
            if (!game.World.HasBlocks)
            {
                return;
            }
            Vector3  spawn = Spawn;
            Vector3I P     = Vector3I.Floor(spawn);
            AABB     bb;

            // Spawn player at highest solid position to match vanilla Minecraft classic
            // Only when player can noclip, since this can let you 'clip' to above solid blocks
            if (Hacks.CanNoclip && game.World.IsValidPos(P))
            {
                bb = AABB.Make(spawn, Size);
                for (int y = P.Y; y <= game.World.Height; y++)
                {
                    float spawnY = Respawn.HighestFreeY(game, ref bb);
                    if (spawnY == float.NegativeInfinity)
                    {
                        BlockID block  = game.World.GetPhysicsBlock(P.X, y, P.Z);
                        float   height = BlockInfo.Collide[block] == CollideType.Solid ? BlockInfo.MaxBB[block].Y : 0;
                        spawn.Y = y + height + Entity.Adjustment;
                        break;
                    }
                    bb.Min.Y += 1; bb.Max.Y += 1;
                }
            }

            spawn.Y += 2 / 16f;
            LocationUpdate update = LocationUpdate.MakePosAndOri(spawn, SpawnRotY, SpawnHeadX, false);

            SetLocation(update, false);
            Velocity = Vector3.Zero;

            // Update onGround, otherwise if 'respawn' then 'space' is pressed, you still jump into the air if onGround was true before
            bb        = Bounds;
            bb.Min.Y -= 0.01f; bb.Max.Y = bb.Min.Y;
            onGround  = TouchesAny(bb, touchesAnySolid);
        }