Fully support PlayerClick extension, and declare that we support it.

This commit is contained in:
UnknownShadow200 2015-07-07 07:58:20 +10:00
parent 36560403ff
commit 87230dca45
4 changed files with 24 additions and 25 deletions

View File

@ -33,7 +33,7 @@ namespace ClassicalSharp {
}
public byte GetClosetPlayer( Game game ) {
Player localP = game.LocalPlayer;
LocalPlayer localP = game.LocalPlayer;
Vector3 eyePos = localP.EyePosition;
Vector3 dir = Utils.GetDirVector( localP.YawRadians, localP.PitchRadians );
float closestDist = float.PositiveInfinity;
@ -44,7 +44,7 @@ namespace ClassicalSharp {
if( p == null ) continue;
float t0, t1;
if( Intersection.RayIntersectsRotatedBox( eyePos, dir, p, out t0, out t1 ) ) {
if( t0 < closestDist ) {
if( t0 < closestDist && closestDist < localP.ReachDistance ) {
closestDist = t0;
targetId = (byte)i;
}

View File

@ -33,10 +33,9 @@ namespace ClassicalSharp {
bool[] buttonsDown = new bool[3];
void MouseButtonUp( object sender, MouseButtonEventArgs e ) {
if( activeScreen == null || !activeScreen.HandlesMouseUp( e.X, e.Y, e.Button ) ) {
if( SendPlayerClick( e.Button ) && buttonsDown[(int)e.Button] ) {
if( SendPlayerClick( e.Button ) ) {
byte targetId = Players.GetClosetPlayer( this );
Network.SendPlayerClick( e.Button, false, targetId, SelectedPos );
buttonsDown[(int)e.Button] = false;
ButtonStateChanged( e.Button, false, targetId );
}
}
}
@ -135,7 +134,12 @@ namespace ClassicalSharp {
double delta = ( now - lastClick ).TotalMilliseconds;
if( cooldown && delta < 250 ) return; // 4 times per second
lastClick = now;
ButtonStateChanged( !cooldown, left, right, middle );
if( Network.UsingPlayerClick && !ScreenLockedInput ) {
byte targetId = Players.GetClosetPlayer( this );
ButtonStateChanged( MouseButton.Left, left, targetId );
ButtonStateChanged( MouseButton.Right, right, targetId );
ButtonStateChanged( MouseButton.Middle, middle, targetId );
}
int buttonsDown = ( left ? 1 : 0 ) + ( right ? 1 : 0 ) + ( middle ? 1 : 0 );
if( !SelectedPos.Valid || buttonsDown > 1 || ScreenLockedInput || HeldBlock == Block.Air ) return;
@ -166,16 +170,14 @@ namespace ClassicalSharp {
}
}
void ButtonStateChanged( bool fromClick, bool left, bool right, bool middle ) {
if( !Network.UsingPlayerClick ) return;
byte targetId = Players.GetClosetPlayer( this );
for( int i = 0; i < buttonsDown.Length; i++ ) {
if( !buttonsDown[i] ) continue;
if( !fromClick )
Network.SendPlayerClick( (MouseButton)i, false, targetId, SelectedPos );
Network.SendPlayerClick( (MouseButton)i, true, targetId, SelectedPos );
void ButtonStateChanged( MouseButton button, bool pressed, byte targetId ) {
if( buttonsDown[(int)button] ) {
Network.SendPlayerClick( button, false, targetId, SelectedPos );
buttonsDown[(int)button] = false;
}
if( pressed ) {
Network.SendPlayerClick( button, true, targetId, SelectedPos );
buttonsDown[(int)button] = true;
}
}

View File

@ -327,11 +327,9 @@ namespace ClassicalSharp {
}
if( Network.UsingPlayerClick ) {
byte targetId = Players.GetClosetPlayer( this );
for( int i = 0; i < buttonsDown.Length; i++ ) {
if( !buttonsDown[i] ) continue;
Network.SendPlayerClick( (MouseButton)i, false, targetId, SelectedPos );
buttonsDown[i] = false;
}
ButtonStateChanged( MouseButton.Left, false, targetId );
ButtonStateChanged( MouseButton.Right, false, targetId );
ButtonStateChanged( MouseButton.Middle, false, targetId );
}
}

View File

@ -70,7 +70,6 @@ namespace ClassicalSharp {
public void SendPlayerClick( MouseButton button, bool buttonDown, byte targetId, PickedPos pos ) {
Player p = Window.LocalPlayer;
Console.WriteLine( "CLICK: " + button + "," + buttonDown );
MakePlayerClick( (byte)button, buttonDown, p.YawDegrees, p.PitchDegrees, targetId,
pos.BlockPos, pos.BlockFace );
}
@ -114,17 +113,17 @@ namespace ClassicalSharp {
CheckForWomEnvironment();
}
readonly int[] packetSizes = new int[] {
readonly int[] packetSizes = {
131, 1, 1, 1028, 7, 9, 8, 74, 10, 7, 5, 4, 2,
66, 65, 2, 67, 69, 3, 2, 3, 134, 196, 130, 3,
8, 86, 2, 4, 66, 69, 2, 8, 138,
};
static string[] clientExtensions = new string[] {
static string[] clientExtensions = {
"EmoteFix", "ClickDistance", "HeldBlock", "BlockPermissions",
"SelectionCuboid", "MessageTypes", "CustomBlocks", "EnvColors",
"HackControl", "EnvMapAppearance", "ExtPlayerList", "ChangeModel",
"EnvWeatherType",
"EnvWeatherType", "PlayerClick", // NOTE: There are no plans to support TextHotKey.
};