Add proper respawning.

This commit is contained in:
UnknownShadow200 2015-10-22 09:12:49 +11:00
parent a91dd49963
commit 0dc008b11e

View File

@ -252,7 +252,21 @@ namespace ClassicalSharp {
internal void HandleKeyDown( Key key ) {
if( key == game.Keys[KeyMapping.Respawn] && canRespawn ) {
LocationUpdate update = LocationUpdate.MakePos( SpawnPoint, false );
Vector3I p = Vector3I.Floor( SpawnPoint );
if( game.Map.IsValidPos( p ) ) {
// Spawn player at highest valid position.
for( int y = p.Y; y <= game.Map.Height; y++ ) {
byte block1 = GetPhysicsBlockId( p.X, y, p.Z );
byte block2 = GetPhysicsBlockId( p.X, y + 1, p.Z );
if( info.CollideType[block1] != BlockCollideType.Solid &&
info.CollideType[block2] != BlockCollideType.Solid ) {
p.Y = y;
break;
}
}
}
Vector3 spawn = (Vector3)p + new Vector3( 0.5f, 0.01f, 0.5f );
LocationUpdate update = LocationUpdate.MakePos( spawn, false );
SetLocation( update, false );
} else if( key == game.Keys[KeyMapping.SetSpawn] && canRespawn ) {
SpawnPoint = Position;