mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-26 19:12:07 -05:00
Fix respawn not working properly with larger models. (Thanks goodlyay)
This commit is contained in:
parent
2a67f8f698
commit
abf965b346
2 changed files with 37 additions and 15 deletions
|
@ -4,7 +4,7 @@
|
|||
<ProjectGuid>{BEB1C785-5CAD-48FF-A886-876BF0A318D4}</ProjectGuid>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>ClassicalSharp</RootNamespace>
|
||||
<AssemblyName>ClassicalSharp</AssemblyName>
|
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||
|
|
|
@ -238,20 +238,9 @@ namespace ClassicalSharp.Entities {
|
|||
internal bool HandleKeyDown( Key key ) {
|
||||
KeyMap keys = game.InputHandler.Keys;
|
||||
if( key == keys[KeyBinding.Respawn] && Hacks.CanRespawn ) {
|
||||
Vector3I p = Vector3I.Floor( SpawnPoint );
|
||||
if( game.World.IsValidPos( p ) ) {
|
||||
// Spawn player at highest valid position.
|
||||
for( int y = p.Y; y <= game.World.Height; y++ ) {
|
||||
byte block1 = physics.GetPhysicsBlockId( p.X, y, p.Z );
|
||||
byte block2 = physics.GetPhysicsBlockId( p.X, y + 1, p.Z );
|
||||
if( info.Collide[block1] != CollideType.Solid &&
|
||||
info.Collide[block2] != CollideType.Solid ) {
|
||||
p.Y = y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Vector3 spawn = (Vector3)p + new Vector3( 0.5f, 0.01f, 0.5f );
|
||||
Vector3 spawn = SpawnPoint;
|
||||
if( game.World.IsValidPos( Vector3I.Floor( spawn ) ) )
|
||||
FindHighestFree( ref spawn );
|
||||
LocationUpdate update = LocationUpdate.MakePosAndOri( spawn, SpawnYaw, SpawnPitch, false );
|
||||
SetLocation( update, false );
|
||||
} else if( key == keys[KeyBinding.SetSpawn] && Hacks.CanRespawn ) {
|
||||
|
@ -276,5 +265,38 @@ namespace ClassicalSharp.Entities {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void FindHighestFree( ref Vector3 spawn ) {
|
||||
Vector3 size = Model.CollisionSize;
|
||||
BoundingBox bb = CollisionBounds;
|
||||
Vector3I P = Vector3I.Floor( spawn );
|
||||
int bbMax = Utils.Floor( size.Y );
|
||||
|
||||
int minX = Utils.Floor( -size.X / 2 ), maxX = Utils.Floor( size.X / 2 );
|
||||
int minZ = Utils.Floor( -size.Z / 2 ), maxZ = Utils.Floor( size.Z / 2 );
|
||||
|
||||
// Spawn player at highest valid position.
|
||||
for( int y = P.Y; y <= game.World.Height; y++ ) {
|
||||
bool anyHit = false;
|
||||
Console.WriteLine( "~~~~~" );
|
||||
for( int yy = 0; yy <= bbMax; yy++ )
|
||||
for( int zz = minZ; zz <= maxZ; zz++ )
|
||||
for ( int xx = minX; xx <= maxX; xx++ )
|
||||
{
|
||||
Vector3I coords = new Vector3I( P.X + xx, y + yy, P.Z + zz );
|
||||
byte block = physics.GetPhysicsBlockId( coords.X, coords.Y, coords.Z );
|
||||
Vector3 min = info.MinBB[block] + (Vector3)coords;
|
||||
Vector3 max = info.MaxBB[block] + (Vector3)coords;
|
||||
Console.WriteLine( min + "_" + max );
|
||||
if( !bb.Intersects( new BoundingBox( min, max ) ) ) continue;
|
||||
anyHit |= info.Collide[block] == CollideType.Solid;
|
||||
}
|
||||
|
||||
if( !anyHit ) {
|
||||
spawn.Y = y + Entity.Adjustment;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue