示例#1
0
 /// <summary> Determines whether this bounding box intersects 
 /// the given bounding box on any axes. </summary>
 public bool Intersects( AABB other )
 {
     if( Max.X >= other.Min.X && Min.X <= other.Max.X ) {
         if( Max.Y < other.Min.Y || Min.Y > other.Max.Y ) {
             return false;
         }
         return Max.Z >= other.Min.Z && Min.Z <= other.Max.Z;
     }
     return false;
 }
示例#2
0
        bool PushbackPlace( PickedPos selected, AABB blockBB )
        {
            Vector3 newP = game.LocalPlayer.Position;
            Vector3 oldP = game.LocalPlayer.Position;

            // Offset position by the closest face
            if( selected.BlockFace == CpeBlockFace.XMax )
                newP.X = blockBB.Max.X + 0.5f;
            else if( selected.BlockFace == CpeBlockFace.ZMax )
                newP.Z = blockBB.Max.Z + 0.5f;
            else if( selected.BlockFace == CpeBlockFace.XMin )
                newP.X = blockBB.Min.X - 0.5f;
            else if( selected.BlockFace == CpeBlockFace.ZMin )
                newP.Z = blockBB.Min.Z - 0.5f;
            else if( selected.BlockFace == CpeBlockFace.YMax )
                newP.Y = blockBB.Min.Y + 1 + Entity.Adjustment;
            else if( selected.BlockFace == CpeBlockFace.YMin )
                newP.Y = blockBB.Min.Y - game.LocalPlayer.CollisionSize.Y - Entity.Adjustment;

            Vector3I newLoc = Vector3I.Floor( newP );
            bool validPos = newLoc.X >= 0 && newLoc.Y >= 0 && newLoc.Z >= 0 &&
                newLoc.X < game.World.Width && newP.Z < game.World.Length;
            if( !validPos ) return false;

            game.LocalPlayer.Position = newP;
            if( !game.LocalPlayer.Hacks.Noclip
               && game.LocalPlayer.TouchesAny( CannotPassThrough ) ) {
                game.LocalPlayer.Position = oldP;
                return false;
            }

            game.LocalPlayer.Position = oldP;
            LocationUpdate update = LocationUpdate.MakePos( newP, false );
            game.LocalPlayer.SetLocation( update, false );
            return true;
        }
示例#3
0
        bool IntersectsOtherPlayers( Vector3 pos, byte newType )
        {
            AABB blockBB = new AABB( pos + game.BlockInfo.MinBB[newType],
                                                  pos + game.BlockInfo.MaxBB[newType] );

            for( int id = 0; id < 255; id++ ) {
                Player player = game.Players[id];
                if( player == null ) continue;
                AABB bounds = player.CollisionBounds;
                bounds.Min.Y += 1/32f; // when player is exactly standing on top of ground
                if( bounds.Intersects( blockBB ) ) return true;
            }
            return false;
        }
示例#4
0
        bool CheckIsFree( PickedPos selected, byte newBlock )
        {
            Vector3 pos = (Vector3)selected.TranslatedPos;
            if( !CannotPassThrough( newBlock ) ) return true;
            if( IntersectsOtherPlayers( pos, newBlock ) ) return false;

            AABB blockBB = new AABB( pos + game.BlockInfo.MinBB[newBlock],
                                                  pos + game.BlockInfo.MaxBB[newBlock] );
            AABB localBB = game.LocalPlayer.CollisionBounds;

            if( game.LocalPlayer.Hacks.Noclip || !localBB.Intersects( blockBB ) ) return true;
            HacksComponent hacks = game.LocalPlayer.Hacks;
            if( hacks.CanPushbackBlocks && hacks.PushbackPlacing && hacks.Enabled )
                return PushbackPlace( selected, blockBB );

            localBB.Min.Y += 0.25f + Entity.Adjustment;
            if( localBB.Intersects( blockBB ) ) return false;

            // Push player up if they are jumping and trying to place a block underneath them.
            Vector3 p = game.LocalPlayer.Position;
            p.Y = pos.Y + game.BlockInfo.MaxBB[newBlock].Y + Entity.Adjustment;
            LocationUpdate update = LocationUpdate.MakePos( p, false );
            game.LocalPlayer.SetLocation( update, false );
            return true;
        }
示例#5
0
 /// <summary> Determines whether this bounding box entirely contains 
 /// the given bounding box on all axes. </summary>
 public bool Contains( AABB other )
 {
     return other.Min.X >= Min.X && other.Min.Y >= Min.Y && other.Min.Z >= Min.Z &&
         other.Max.X <= Max.X && other.Max.Y <= Max.Y && other.Max.Z <= Max.Z;
 }
示例#6
0
 /// <summary> Determines whether this bounding box intersects 
 /// the given bounding box on the Z axis. </summary>
 public bool ZIntersects( AABB box )
 {
     return Max.Z >= box.Min.Z && Min.Z <= box.Max.Z;
 }
示例#7
0
 /// <summary> Determines whether this bounding box intersects 
 /// the given bounding box on the Y axis. </summary>
 public bool YIntersects( AABB box )
 {
     return Max.Y >= box.Min.Y && Min.Y <= box.Max.Y;
 }
示例#8
0
 /// <summary> Determines whether this bounding box intersects 
 /// the given bounding box on the X axis. </summary>
 public bool XIntersects( AABB box )
 {
     return Max.X >= box.Min.X && Min.X <= box.Max.X;
 }