Fix Direct3D9 build clipping when standing next to a block, blocks should not be placed over players. (Thanks Empy)

This commit is contained in:
UnknownShadow200 2015-09-30 09:10:55 +10:00
parent 976db7a487
commit 9e9a739932
7 changed files with 42 additions and 12 deletions

View file

@ -168,14 +168,40 @@ namespace ClassicalSharp {
Vector3I pos = SelectedPos.TranslatedPos;
if( !Map.IsValidPos( pos ) ) return;
Block block = inv.HeldBlock;
if( !CanPick( Map.GetBlock( pos ) ) && inv.CanPlace[(int)block] ) {
UpdateBlock( pos.X, pos.Y, pos.Z, (byte)block );
Network.SendSetBlock( pos.X, pos.Y, pos.Z, true, (byte)block );
byte block = (byte)inv.HeldBlock;
if( !CanPick( Map.GetBlock( pos ) ) && inv.CanPlace[block]
&& CheckIsFree( pos, block ) ) {
UpdateBlock( pos.X, pos.Y, pos.Z, block );
Network.SendSetBlock( pos.X, pos.Y, pos.Z, true, block );
}
}
}
bool CheckIsFree( Vector3I pos, byte newBlock ) {
float height = BlockInfo.Height[newBlock];
BoundingBox blockBB = new BoundingBox( pos.X, pos.Y, pos.Z,
pos.X + 1, pos.Y + height, pos.Z + 1 );
for( int id = 0; id < 255; id++ ) {
Player player = Players[id];
if( player == null ) continue;
if( player.CollisionBounds.Intersects( blockBB ) ) return false;
}
BoundingBox localBB = LocalPlayer.CollisionBounds;
if( localBB.Intersects( 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 = LocalPlayer.Position;
p.Y = pos.Y + height + Entity.Adjustment;
LocationUpdate update = LocationUpdate.MakePos( p, false );
LocalPlayer.SetLocation( update, false );
}
return true;
}
void ButtonStateChanged( MouseButton button, bool pressed, byte targetId ) {
if( buttonsDown[(int)button] ) {
Network.SendPlayerClick( button, false, targetId, SelectedPos );

View file

@ -31,6 +31,7 @@ namespace ClassicalSharp.GraphicsAPI {
CreateFlags createFlags = CreateFlags.HardwareVertexProcessing;
public Direct3D9Api( Game game ) {
MinZNear = 0.05f;
IntPtr windowHandle = ((WinWindowInfo)game.WindowInfo).WindowHandle;
d3d = new Direct3D();
int adapter = d3d.Adapters[0].Adapter;

View file

@ -17,6 +17,8 @@ namespace ClassicalSharp.GraphicsAPI {
public abstract bool Texturing { set; }
internal float MinZNear = 0.1f;
public int CreateTexture( Bitmap bmp ) {
Rectangle rec = new Rectangle( 0, 0, bmp.Width, bmp.Height );
// Convert other pixel formats into 32bpp formats.

View file

@ -22,12 +22,12 @@ namespace ClassicalSharp {
return new BoundingBox( Min + amount, Max + amount );
}
public bool Intersects( BoundingBox box ) {
if( Max.X >= box.Min.X && Min.X <= box.Max.X ) {
if( Max.Y < box.Min.Y || Min.Y > box.Max.Y ) {
public bool Intersects( BoundingBox 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 >= box.Min.Z && Min.Z <= box.Max.Z;
return Max.Z >= other.Min.Z && Min.Z <= other.Max.Z;
}
return false;
}

View file

@ -25,7 +25,7 @@ namespace ClassicalSharp.Renderers {
index = 0;
Vector3 p1 = pickedPos.Min - new Vector3( offset, offset, offset );
Vector3 p2 = pickedPos.Max + new Vector3( offset, offset, offset );
col.A = 220;
col.A = 150;
graphics.AlphaBlending = true;
// bottom face

View file

@ -38,7 +38,8 @@ namespace ClassicalSharp {
public override Matrix4 GetProjection() {
float fovy = (float)Utils.DegreesToRadians( 70 );
float aspectRatio = (float)game.Width / game.Height;
return Matrix4.CreatePerspectiveFieldOfView( fovy, aspectRatio, 0.1f, game.ViewDistance );
float zNear = game.Graphics.MinZNear;
return Matrix4.CreatePerspectiveFieldOfView( fovy, aspectRatio, zNear, game.ViewDistance );
}
public override void GetPickedBlock( PickedPos pos ) {

View file

@ -20,10 +20,10 @@ It **does not** work with 'modern/premium' Minecraft servers.
Initially, you will need to run launcher.exe to download the required assets from minecraft.net.
Just click 'OK' to the dialog box that appears when you start the launcher.
##### Singleplayer
**Singleplayer**
Run classicalsharp.exe.
##### Multiplayer
**Multiplayer**
Run launcher.exe. You can connect to LAN/locally hosted servers, minecraft.net servers, and classicube.net servers through the launcher.
##### Mono specific notes