mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 09:35:23 -04:00
Keep track of picked block face in PickedPos class, rearrange MouseButton enum order to match CPE PlayerClick specification.
This commit is contained in:
parent
b11a27d14e
commit
07471e54d7
@ -51,4 +51,13 @@ namespace ClassicalSharp {
|
||||
BottomRight3 = 13,
|
||||
Announcement = 100,
|
||||
}
|
||||
|
||||
public enum CpeBlockFace {
|
||||
XMax,
|
||||
XMin,
|
||||
YMax,
|
||||
YMin,
|
||||
ZMax,
|
||||
ZMin,
|
||||
}
|
||||
}
|
||||
|
@ -174,18 +174,18 @@ namespace ClassicalSharp {
|
||||
WriteUInt8( version );
|
||||
}
|
||||
|
||||
private static void MakePlayerClick( byte button, byte action, short yaw, short pitch, byte targetEntity,
|
||||
Vector3I targetPos, byte targetFace ) {
|
||||
private static void MakePlayerClick( byte button, bool buttonDown, float yaw, float pitch, byte targetEntity,
|
||||
Vector3I targetPos, CpeBlockFace targetFace ) {
|
||||
WriteUInt8( (byte)PacketId.CpePlayerClick );
|
||||
WriteUInt8( button );
|
||||
WriteUInt8( action );
|
||||
WriteInt16( yaw );
|
||||
WriteInt16( pitch );
|
||||
WriteUInt8( buttonDown ? (byte)0 : (byte)1 );
|
||||
WriteInt16( (short)Utils.DegreesToPacked( yaw, 65536 ) );
|
||||
WriteInt16( (short)Utils.DegreesToPacked( pitch, 65536 ) );
|
||||
WriteUInt8( targetEntity );
|
||||
WriteInt16( (short)targetPos.X );
|
||||
WriteInt16( (short)targetPos.Y );
|
||||
WriteInt16( (short)targetPos.Z );
|
||||
WriteUInt8( targetFace );
|
||||
WriteUInt8( (byte)targetFace );
|
||||
}
|
||||
|
||||
static void WriteString( string value ) {
|
||||
|
@ -41,14 +41,14 @@ namespace OpenTK.Input
|
||||
/// </summary>
|
||||
Left = 0,
|
||||
/// <summary>
|
||||
/// The middle mouse button.
|
||||
/// </summary>
|
||||
Middle,
|
||||
/// <summary>
|
||||
/// The right mouse button.
|
||||
/// </summary>
|
||||
Right,
|
||||
/// <summary>
|
||||
/// The middle mouse button.
|
||||
/// </summary>
|
||||
Middle,
|
||||
/// <summary>
|
||||
/// The first extra mouse button.
|
||||
/// </summary>
|
||||
Button1,
|
||||
|
@ -120,6 +120,7 @@ namespace ClassicalSharp {
|
||||
public Vector3I BlockPos;
|
||||
public Vector3I TranslatedPos;
|
||||
public bool Valid = true;
|
||||
public CpeBlockFace BlockFace;
|
||||
|
||||
public void UpdateBlockPos( Vector3 p1, Vector3 p2, Vector3 origin, Vector3 dir, float t0, float t1 ) {
|
||||
Min = Vector3.Min( p1, p2 );
|
||||
@ -130,20 +131,22 @@ namespace ClassicalSharp {
|
||||
Vector3I normal = Vector3I.Zero;
|
||||
Vector3 intersect = origin + dir * t0;
|
||||
float dist = float.PositiveInfinity;
|
||||
TestAxis( intersect.X - Min.X, ref dist, -Vector3I.UnitX, ref normal );
|
||||
TestAxis( intersect.X - Max.X, ref dist, Vector3I.UnitX, ref normal );
|
||||
TestAxis( intersect.Y - Min.Y, ref dist, -Vector3I.UnitY, ref normal );
|
||||
TestAxis( intersect.Y - Max.Y, ref dist, Vector3I.UnitY, ref normal );
|
||||
TestAxis( intersect.Z - Min.Z, ref dist, -Vector3I.UnitZ, ref normal );
|
||||
TestAxis( intersect.Z - Max.Z, ref dist, Vector3I.UnitZ, ref normal );
|
||||
TestAxis( intersect.X - Min.X, ref dist, -Vector3I.UnitX, ref normal, CpeBlockFace.XMin );
|
||||
TestAxis( intersect.X - Max.X, ref dist, Vector3I.UnitX, ref normal, CpeBlockFace.XMax );
|
||||
TestAxis( intersect.Y - Min.Y, ref dist, -Vector3I.UnitY, ref normal, CpeBlockFace.YMin );
|
||||
TestAxis( intersect.Y - Max.Y, ref dist, Vector3I.UnitY, ref normal, CpeBlockFace.YMax );
|
||||
TestAxis( intersect.Z - Min.Z, ref dist, -Vector3I.UnitZ, ref normal, CpeBlockFace.ZMin );
|
||||
TestAxis( intersect.Z - Max.Z, ref dist, Vector3I.UnitZ, ref normal, CpeBlockFace.ZMax );
|
||||
TranslatedPos = BlockPos + normal;
|
||||
}
|
||||
|
||||
static void TestAxis( float dAxis, ref float dist, Vector3I nAxis, ref Vector3I normal ) {
|
||||
void TestAxis( float dAxis, ref float dist, Vector3I nAxis, ref Vector3I normal,
|
||||
CpeBlockFace fAxis) {
|
||||
dAxis = Math.Abs( dAxis );
|
||||
if( dAxis < dist ) {
|
||||
dist = dAxis;
|
||||
normal = nAxis;
|
||||
BlockFace = fAxis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user