diff --git a/ClassicalSharp/2D/Widgets/Chat/TextInputWidget.cs b/ClassicalSharp/2D/Widgets/Chat/TextInputWidget.cs index 7cd779a6b..4c2eddc21 100644 --- a/ClassicalSharp/2D/Widgets/Chat/TextInputWidget.cs +++ b/ClassicalSharp/2D/Widgets/Chat/TextInputWidget.cs @@ -60,7 +60,7 @@ namespace ClassicalSharp { caretPos = -1; realIndex = 500000; } - int sum = 0, indexX = -1, indexY = 0; + int sum = 0, indexX = -1, indexY = 0; for( int i = 0; i < lines; i++ ) { if( partLens[i] == 0 ) break; @@ -70,7 +70,7 @@ namespace ClassicalSharp { break; } sum += partLens[i]; - } + } if( indexX == -1 ) indexX = partLens[indexY]; if( indexX == 64 ) { @@ -148,9 +148,17 @@ namespace ClassicalSharp { static char[] trimChars = { ' ' }; public void SendTextInBufferAndReset() { + int packetsCount = 0; for( int i = 0; i < parts.Length; i++ ) { if( parts[i] == null ) break; - game.Chat.Send( parts[i].TrimEnd( trimChars ) ); + packetsCount++; + } + // split up into both partial and final packet. + if( packetsCount > 0 ) { + for( int i = 0; i < packetsCount - 1; i++ ) { + game.Chat.Send( parts[i].TrimEnd( trimChars ), true ); + } + game.Chat.Send( parts[packetsCount - 1].TrimEnd( trimChars ), false ); } typingLogPos = game.Chat.InputLog.Count; // Index of newest entry + 1. diff --git a/ClassicalSharp/Game/ChatLog.cs b/ClassicalSharp/Game/ChatLog.cs index 399a059ac..c3b677fb6 100644 --- a/ClassicalSharp/Game/ChatLog.cs +++ b/ClassicalSharp/Game/ChatLog.cs @@ -24,15 +24,15 @@ namespace ClassicalSharp { public int FontSize = 12; - public void Send( string text ) { + public void Send( string text, bool partial ) { if( String.IsNullOrEmpty( text ) ) return; - InputLog.Add( text ); + if( CommandManager.IsCommandPrefix( text ) ) { game.CommandManager.Execute( text ); return; } - game.Network.SendChat( text ); + game.Network.SendChat( text, partial ); } public void Add( string text ) { diff --git a/ClassicalSharp/Game/Game.cs b/ClassicalSharp/Game/Game.cs index 66e584bac..963426b5b 100644 --- a/ClassicalSharp/Game/Game.cs +++ b/ClassicalSharp/Game/Game.cs @@ -116,7 +116,7 @@ namespace ClassicalSharp { Animations = new Animations( this ); TexturePackExtractor extractor = new TexturePackExtractor(); extractor.Extract( defaultTexPack, this ); - Inventory = new Inventory( this ); + Inventory = new Inventory( this ); BlockInfo.SetDefaultBlockPermissions( Inventory.CanPlace, Inventory.CanDelete ); Map = new Map( this ); @@ -217,7 +217,11 @@ namespace ClassicalSharp { MapRenderer.Render( e.Time ); SelectionManager.Render( e.Time ); WeatherRenderer.Render( e.Time ); - InputHandler.PickBlocks( true ); + + bool left = IsMousePressed( MouseButton.Left ); + bool middle = IsMousePressed( MouseButton.Middle ); + bool right = IsMousePressed( MouseButton.Right ); + InputHandler.PickBlocks( true, left, middle, right ); } else { SelectedPos.SetAsInvalid(); } diff --git a/ClassicalSharp/Game/InputHandler.cs b/ClassicalSharp/Game/InputHandler.cs index ece0b03ca..361051ea5 100644 --- a/ClassicalSharp/Game/InputHandler.cs +++ b/ClassicalSharp/Game/InputHandler.cs @@ -59,10 +59,7 @@ namespace ClassicalSharp { bool[] buttonsDown = new bool[3]; DateTime lastClick = DateTime.MinValue; - public void PickBlocks( bool cooldown ) { - bool left = game.IsMousePressed( MouseButton.Left ); - bool right = game.IsMousePressed( MouseButton.Right ); - bool middle = game.IsMousePressed( MouseButton.Middle ); + public void PickBlocks( bool cooldown, bool left, bool middle, bool right ) { DateTime now = DateTime.UtcNow; double delta = (now - lastClick).TotalMilliseconds; if( cooldown && delta < 250 ) return; // 4 times per second @@ -225,7 +222,10 @@ namespace ClassicalSharp { void MouseButtonDown( object sender, MouseButtonEventArgs e ) { if( game.activeScreen == null || !game.activeScreen.HandlesMouseClick( e.X, e.Y, e.Button ) ) { - PickBlocks( false ); + bool left = e.Button == MouseButton.Left; + bool middle = e.Button == MouseButton.Middle; + bool right = e.Button == MouseButton.Right; + PickBlocks( false, left, middle, right ); } else { lastClick = DateTime.UtcNow; } @@ -286,7 +286,7 @@ namespace ClassicalSharp { if( Hotkeys.IsHotkey( key, game.Keyboard, out text, out more ) ) { if( !more ) - game.Network.SendChat( text ); + game.Network.SendChat( text, false ); else if( game.activeScreen is NormalScreen ) ((NormalScreen)game.activeScreen).OpenTextInputBar( text ); } diff --git a/ClassicalSharp/Model/ChickenModel.cs b/ClassicalSharp/Model/ChickenModel.cs index a1ad99540..1ee507824 100644 --- a/ClassicalSharp/Model/ChickenModel.cs +++ b/ClassicalSharp/Model/ChickenModel.cs @@ -39,7 +39,7 @@ namespace ClassicalSharp.Model { } ModelPart MakeLeg( float x1, float x2, float legX1, float legX2 ) { - const float y1 = 0f, y2 = 5/16f, z2 = 1/16f, z1 = -2/16f; + const float y1 = 1/64f, y2 = 5/16f, z2 = 1/16f, z1 = -2/16f; YQuad( 32, 0, 3, 3, x2, x1, z1, z2, y1, false ); // bottom feet ZQuad( 36, 3, 1, 5, legX1, legX2, y1, y2, z2, false ); // vertical part of leg return new ModelPart( index - 2 * 4, 2 * 4 ); diff --git a/ClassicalSharp/Network/INetworkProcessor.cs b/ClassicalSharp/Network/INetworkProcessor.cs index ffc6b6485..27bb08bb8 100644 --- a/ClassicalSharp/Network/INetworkProcessor.cs +++ b/ClassicalSharp/Network/INetworkProcessor.cs @@ -12,7 +12,7 @@ namespace ClassicalSharp { public abstract void Connect( IPAddress address, int port ); - public abstract void SendChat( string text ); + public abstract void SendChat( string text, bool partial ); public abstract void SendPosition( Vector3 pos, float yaw, float pitch ); diff --git a/ClassicalSharp/Network/NetworkProcessor.CPE.cs b/ClassicalSharp/Network/NetworkProcessor.CPE.cs index 5622d9fb8..5c862254a 100644 --- a/ClassicalSharp/Network/NetworkProcessor.CPE.cs +++ b/ClassicalSharp/Network/NetworkProcessor.CPE.cs @@ -54,12 +54,15 @@ namespace ClassicalSharp { int cpeServerExtensionsCount; bool sendHeldBlock, useMessageTypes, usingTexturePack; + bool usePartialMessages; static string[] clientExtensions = { "ClickDistance", "CustomBlocks", "HeldBlock", "EmoteFix", "TextHotKey", "ExtPlayerList", "EnvColors", "SelectionCuboid", "BlockPermissions", "ChangeModel", "EnvMapAppearance", "EnvWeatherType", "HackControl", "MessageTypes", "PlayerClick", + // proposals + "FullCP437", "LongerMessages", }; void HandleCpeExtInfo() { @@ -84,6 +87,8 @@ namespace ClassicalSharp { } else if( extName == "EnvMapAppearance" && extVersion == 2 ) { usingTexturePack = true; packetSizes[(int)PacketId.CpeEnvSetMapApperance] += 4; + } else if( extName == "LongerMessages" ) { + usePartialMessages = true; } cpeServerExtensionsCount--; @@ -92,7 +97,7 @@ namespace ClassicalSharp { SendPacket(); for( int i = 0; i < clientExtensions.Length; i++ ) { string name = clientExtensions[i]; - int version = (name == "ExtPlayerList" || name == "EnvMapApperance") ? 2 : 1; + int version = (name == "ExtPlayerList") ? 2 : 1; MakeExtEntry( name, version ); SendPacket(); } @@ -268,6 +273,7 @@ namespace ClassicalSharp { game.Map.SetEdgeBlock( (Block)reader.ReadUInt8() ); game.Map.SetEdgeLevel( reader.ReadInt16() ); if( usingTexturePack ) { + // TODO: proper envmapappearance version 2 support game.Map.SetCloudsLevel( reader.ReadInt16() ); short maxViewDist = reader.ReadInt16(); // TODO: what to do with this? } diff --git a/ClassicalSharp/Network/NetworkProcessor.cs b/ClassicalSharp/Network/NetworkProcessor.cs index 4342446d2..d0d04c028 100644 --- a/ClassicalSharp/Network/NetworkProcessor.cs +++ b/ClassicalSharp/Network/NetworkProcessor.cs @@ -48,11 +48,13 @@ namespace ClassicalSharp { SendPacket(); } - public override void SendChat( string text ) { - if( !String.IsNullOrEmpty( text ) ) { - MakeMessagePacket( text ); - SendPacket(); - } + public override void SendChat( string text, bool partial ) { + if( String.IsNullOrEmpty( text ) ) return; + + byte payload = !usePartialMessages ? (byte)0xFF: + partial ? (byte)1 : (byte)0; + MakeMessagePacket( text, payload ); + SendPacket(); } public override void SendPosition( Vector3 pos, float yaw, float pitch ) { @@ -162,9 +164,9 @@ namespace ClassicalSharp { WriteUInt8( (byte)Utils.DegreesToPacked( pitch, 256 ) ); } - private static void MakeMessagePacket( string text ) { + private static void MakeMessagePacket( string text, byte payload ) { WriteUInt8( (byte)PacketId.Message ); - WriteUInt8( 0xFF ); // unused + WriteUInt8( payload ); WriteString( text ); } @@ -310,7 +312,7 @@ namespace ClassicalSharp { map = null; gzipStream.Dispose(); if( sendWomId && !sentWomId ) { - SendChat( "/womid WoMClient-2.0.7" ); + SendChat( "/womid WoMClient-2.0.7", false ); sentWomId = true; } gzipStream = null; diff --git a/ClassicalSharp/Singleplayer/Server.cs b/ClassicalSharp/Singleplayer/Server.cs index 1d4ad8886..7de2868cf 100644 --- a/ClassicalSharp/Singleplayer/Server.cs +++ b/ClassicalSharp/Singleplayer/Server.cs @@ -29,7 +29,7 @@ namespace ClassicalSharp.Singleplayer { game.CommandManager.RegisterCommand( new GenerateCommand() ); } - public override void SendChat( string text ) { + public override void SendChat( string text, bool partial ) { if( !String.IsNullOrEmpty( text ) ) { game.Chat.Add( text, CpeMessage.Normal ); } diff --git a/Launcher2/LauncherWindow.cs b/Launcher2/LauncherWindow.cs index 99284b523..99a5dd88c 100644 --- a/Launcher2/LauncherWindow.cs +++ b/Launcher2/LauncherWindow.cs @@ -125,7 +125,7 @@ namespace Launcher2 { platformDrawer.Draw( Window.WindowInfo, Framebuffer ); } - internal FastColour clearColour = new FastColour( 101, 79, 119 ); + internal FastColour clearColour = new FastColour( 30, 30, 30 ); public void MakeBackground() { if( Framebuffer != null ) Framebuffer.Dispose();