diff --git a/ClassicalSharp/2D/Screens/ChatScreen.cs b/ClassicalSharp/2D/Screens/ChatScreen.cs index 6df6fad75..12d56174b 100644 --- a/ClassicalSharp/2D/Screens/ChatScreen.cs +++ b/ClassicalSharp/2D/Screens/ChatScreen.cs @@ -147,13 +147,14 @@ namespace ClassicalSharp.Gui { void SetFetchStatus( int progress ) { lastDownload.Clear(); int index = 0; - if( progress == -2 ) + if( progress == -2 ) { lastDownload.Append( ref index, "&eRetrieving texture pack.." ); - else if( progress == -1 ) + } else if( progress == -1 ) { lastDownload.Append( ref index, "&eDownloading texture pack" ); - else if( progress >= 0 && progress <= 100 ) + } else if( progress >= 0 && progress <= 100 ) { lastDownload.Append( ref index, "&eDownloading texture pack (&7" ) .AppendNum( ref index, progress ).Append( ref index, "&e%)" ); + } status.SetText( 1, lastDownload.ToString() ); } diff --git a/ClassicalSharp/2D/Screens/Inventory/InventoryScreen.Input.cs b/ClassicalSharp/2D/Screens/Inventory/InventoryScreen.Input.cs index 0b8cd5b02..b6aceef4a 100644 --- a/ClassicalSharp/2D/Screens/Inventory/InventoryScreen.Input.cs +++ b/ClassicalSharp/2D/Screens/Inventory/InventoryScreen.Input.cs @@ -41,10 +41,11 @@ namespace ClassicalSharp.Gui { if( button == MouseButton.Left && mouseX >= TableX - scrollbarWidth && mouseX < TableX ) { ScrollbarClick( mouseY ); } else if( button == MouseButton.Left ) { - if( selIndex != -1 ) + if( selIndex != -1 ) { game.Inventory.HeldBlock = blocksTable[selIndex]; - else if( Contains( TableX, TableY, TableWidth, TableHeight, mouseX, mouseY ) ) + } else if( Contains( TableX, TableY, TableWidth, TableHeight, mouseX, mouseY ) ) { return true; + } bool hotbar = game.IsKeyDown( Key.AltLeft ) || game.IsKeyDown( Key.AltRight ); if( !hotbar ) diff --git a/ClassicalSharp/2D/Widgets/Chat/TextGroupWidget.Formatter.cs b/ClassicalSharp/2D/Widgets/Chat/TextGroupWidget.Formatter.cs index de0880c57..2fc373a80 100644 --- a/ClassicalSharp/2D/Widgets/Chat/TextGroupWidget.Formatter.cs +++ b/ClassicalSharp/2D/Widgets/Chat/TextGroupWidget.Formatter.cs @@ -162,8 +162,7 @@ namespace ClassicalSharp.Gui { count += 2; } - if( lastEnd < line.Length ) - count++; + if( lastEnd < line.Length ) count++; return count; } diff --git a/ClassicalSharp/Audio/AudioPlayer.Sounds.cs b/ClassicalSharp/Audio/AudioPlayer.Sounds.cs index 8fe66cb9f..11424da6a 100644 --- a/ClassicalSharp/Audio/AudioPlayer.Sounds.cs +++ b/ClassicalSharp/Audio/AudioPlayer.Sounds.cs @@ -57,10 +57,11 @@ namespace ClassicalSharp.Audio { chunk.BytesUsed = snd.Data.Length; chunk.Data = snd.Data; - if( snd.Channels == 1 ) + if( snd.Channels == 1 ) { PlayCurrentSound( monoOutputs ); - else if( snd.Channels == 2 ) + } else if( snd.Channels == 2 ) { PlayCurrentSound( stereoOutputs ); + } } IAudioOutput firstSoundOut; diff --git a/ClassicalSharp/Blocks/Block.cs b/ClassicalSharp/Blocks/Block.cs index f29065dbf..6de52ad2d 100644 --- a/ClassicalSharp/Blocks/Block.cs +++ b/ClassicalSharp/Blocks/Block.cs @@ -76,7 +76,7 @@ namespace ClassicalSharp { public const string Names = "Air Stone Grass Dirt Cobblestone Wood Sapling Bedrock Water StillWater Lava" + " StillLava Sand Gravel GoldOre IronOre CoalOre Log Leaves Sponge Glass Red Orange Yellow Lime Green" + - " Teal Aqua Cyan Blue Indigo Violet Magenta Pink Black Gray White Dandelion Rose BrownMushroom RedMushroom" + + " Teal Aqua Cyan Blue Indigo Violet Magenta Pink Black Gray White Dandelion Rose BrownMushroom RedMushroom" + " Gold Iron DoubleSlab Slab Brick TNT Bookshelf MossyRocks Obsidian CobblestoneSlab Rope Sandstone" + " Snow Fire LightPink ForestGreen Brown DeepBlue Turquoise Ice CeramicTile Magma Pillar Crate StoneBrick"; } diff --git a/ClassicalSharp/Entities/Components/CollisionsComponent.cs b/ClassicalSharp/Entities/Components/CollisionsComponent.cs index 364195387..6e8acae86 100644 --- a/ClassicalSharp/Entities/Components/CollisionsComponent.cs +++ b/ClassicalSharp/Entities/Components/CollisionsComponent.cs @@ -118,34 +118,36 @@ namespace ClassicalSharp.Entities { // if we have hit the bottom of a block, we need to change the axis we test first. if( !hitYMin ) { - if( finalBB.Min.Y + Adjustment >= blockBB.Max.Y ) + if( finalBB.Min.Y + Adjustment >= blockBB.Max.Y ) { ClipYMax( ref blockBB, ref entityBB, ref entityExtentBB, ref size ); - else if( finalBB.Max.Y - Adjustment <= blockBB.Min.Y ) + } else if( finalBB.Max.Y - Adjustment <= blockBB.Min.Y ) { ClipYMin( ref blockBB, ref entityBB, ref entityExtentBB, ref size ); - else if( finalBB.Min.X + Adjustment >= blockBB.Max.X ) + } else if( finalBB.Min.X + Adjustment >= blockBB.Max.X ) { ClipXMax( ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size ); - else if( finalBB.Max.X - Adjustment <= blockBB.Min.X ) + } else if( finalBB.Max.X - Adjustment <= blockBB.Min.X ) { ClipXMin( ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size ); - else if( finalBB.Min.Z + Adjustment >= blockBB.Max.Z ) + } else if( finalBB.Min.Z + Adjustment >= blockBB.Max.Z ) { ClipZMax( ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size ); - else if( finalBB.Max.Z - Adjustment <= blockBB.Min.Z ) + } else if( finalBB.Max.Z - Adjustment <= blockBB.Min.Z ) { ClipZMin( ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size ); + } continue; } // if flying or falling, test the horizontal axes first. - if( finalBB.Min.X + Adjustment >= blockBB.Max.X ) + if( finalBB.Min.X + Adjustment >= blockBB.Max.X ) { ClipXMax( ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size ); - else if( finalBB.Max.X - Adjustment <= blockBB.Min.X ) + } else if( finalBB.Max.X - Adjustment <= blockBB.Min.X ) { ClipXMin( ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size ); - else if( finalBB.Min.Z + Adjustment >= blockBB.Max.Z ) + } else if( finalBB.Min.Z + Adjustment >= blockBB.Max.Z ) { ClipZMax( ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size ); - else if( finalBB.Max.Z - Adjustment <= blockBB.Min.Z ) + } else if( finalBB.Max.Z - Adjustment <= blockBB.Min.Z ) { ClipZMin( ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size ); - else if( finalBB.Min.Y + Adjustment >= blockBB.Max.Y ) + } else if( finalBB.Min.Y + Adjustment >= blockBB.Max.Y ) { ClipYMax( ref blockBB, ref entityBB, ref entityExtentBB, ref size ); - else if( finalBB.Max.Y - Adjustment <= blockBB.Min.Y ) + } else if( finalBB.Max.Y - Adjustment <= blockBB.Min.Y ) { ClipYMin( ref blockBB, ref entityBB, ref entityExtentBB, ref size ); + } } } diff --git a/ClassicalSharp/Entities/Components/HacksComponent.cs b/ClassicalSharp/Entities/Components/HacksComponent.cs index 018cb14fb..208ef3eb0 100644 --- a/ClassicalSharp/Entities/Components/HacksComponent.cs +++ b/ClassicalSharp/Entities/Components/HacksComponent.cs @@ -111,10 +111,11 @@ namespace ClassicalSharp.Entities { } static void ParseFlag( Action action, string joined, string flag ) { - if( joined.Contains( "+" + flag ) ) + if( joined.Contains( "+" + flag ) ) { action( true ); - else if( joined.Contains( "-" + flag ) ) + } else if( joined.Contains( "-" + flag ) ) { action( false ); + } } /// Sets the user type of this user. This is used to control permissions for grass, diff --git a/ClassicalSharp/Entities/LocalPlayer.cs b/ClassicalSharp/Entities/LocalPlayer.cs index 23c454018..b159abee8 100644 --- a/ClassicalSharp/Entities/LocalPlayer.cs +++ b/ClassicalSharp/Entities/LocalPlayer.cs @@ -106,8 +106,9 @@ namespace ClassicalSharp.Entities { /// Disables any hacks if their respective CanHackX value is set to false. public void CheckHacksConsistency() { Hacks.CheckHacksConsistency(); - if( !Hacks.CanJumpHigher ) + if( !Hacks.CanJumpHigher ) { physics.jumpVel = physics.serverJumpVel; + } } internal Vector3 lastPos, nextPos; diff --git a/ClassicalSharp/Events/EntityEvents.cs b/ClassicalSharp/Events/EntityEvents.cs index c2ed9131c..16a0be2e9 100644 --- a/ClassicalSharp/Events/EntityEvents.cs +++ b/ClassicalSharp/Events/EntityEvents.cs @@ -5,7 +5,7 @@ namespace ClassicalSharp.Events { /// Contains events related to the spawning/despawning of entities, /// and the creation/removal of tab list entries. - public sealed class EntityEvents : OtherEvents { + public sealed class EntityEvents : EventsBase { IdEventArgs idArgs = new IdEventArgs(); diff --git a/ClassicalSharp/Events/Events.cs b/ClassicalSharp/Events/Events.cs index 223940547..5b325419b 100644 --- a/ClassicalSharp/Events/Events.cs +++ b/ClassicalSharp/Events/Events.cs @@ -3,7 +3,20 @@ using System; namespace ClassicalSharp.Events { - public class OtherEvents { + public abstract class EventsBase { + + protected void Raise( EventHandler handler ) { + if( handler == null ) return; + handler( this, EventArgs.Empty ); + } + + protected void Raise( EventHandler handler, T args ) where T : EventArgs { + if( handler == null ) return; + handler( this, args ); + } + } + + public class OtherEvents : EventsBase { /// Raised when the terrain atlas ("terrain.png") is changed. public event EventHandler TerrainAtlasChanged; @@ -61,15 +74,6 @@ namespace ClassicalSharp.Events { ChatEventArgs chatArgs = new ChatEventArgs(); TextureEventArgs texArgs = new TextureEventArgs(); ColourCodeEventArgs colArgs = new ColourCodeEventArgs(); - protected void Raise( EventHandler handler ) { - if( handler != null ) - handler( this, EventArgs.Empty ); - } - - protected void Raise( EventHandler handler, T args ) where T : EventArgs { - if( handler != null ) - handler( this, args ); - } } public sealed class ChatEventArgs : EventArgs { diff --git a/ClassicalSharp/Events/UserEvents.cs b/ClassicalSharp/Events/UserEvents.cs index e5236d5a9..7d719fb3a 100644 --- a/ClassicalSharp/Events/UserEvents.cs +++ b/ClassicalSharp/Events/UserEvents.cs @@ -3,7 +3,7 @@ using System; namespace ClassicalSharp.Events { - public class UserEvents { + public class UserEvents : EventsBase { /// Raised when the user changes a block in the world. public event EventHandler BlockChanged; @@ -13,15 +13,6 @@ namespace ClassicalSharp.Events { } BlockChangedEventArgs blockArgs = new BlockChangedEventArgs(); - protected void Raise( EventHandler handler ) { - if( handler != null ) - handler( this, EventArgs.Empty ); - } - - protected void Raise( EventHandler handler, T args ) where T : EventArgs { - if( handler != null ) - handler( this, args ); - } } public sealed class BlockChangedEventArgs : EventArgs { diff --git a/ClassicalSharp/Events/WorldEvents.cs b/ClassicalSharp/Events/WorldEvents.cs index aef560067..3549e1885 100644 --- a/ClassicalSharp/Events/WorldEvents.cs +++ b/ClassicalSharp/Events/WorldEvents.cs @@ -3,7 +3,7 @@ using System; namespace ClassicalSharp.Events { - public class WorldEvents : OtherEvents { + public class WorldEvents : EventsBase { /// Raised when the player joins and begins loading a new world. public event EventHandler OnNewMap; diff --git a/ClassicalSharp/Game/GuiInterface.cs b/ClassicalSharp/Game/GuiInterface.cs index 06740386a..331f924e5 100644 --- a/ClassicalSharp/Game/GuiInterface.cs +++ b/ClassicalSharp/Game/GuiInterface.cs @@ -61,12 +61,13 @@ namespace ClassicalSharp { } void TextureChanged( object sender, TextureEventArgs e ) { - if( e.Name == "gui.png" ) + if( e.Name == "gui.png" ) { game.UpdateTexture( ref GuiTex, e.Name, e.Data, false ); - else if( e.Name == "gui_classic.png" ) + } else if( e.Name == "gui_classic.png" ) { game.UpdateTexture( ref GuiClassicTex, e.Name, e.Data, false ); - else if( e.Name == "icons.png" ) + } else if( e.Name == "icons.png" ) { game.UpdateTexture( ref IconsTex, e.Name, e.Data, false ); + } } diff --git a/ClassicalSharp/Game/InputHandler.cs b/ClassicalSharp/Game/InputHandler.cs index 6865121d1..568f40323 100644 --- a/ClassicalSharp/Game/InputHandler.cs +++ b/ClassicalSharp/Game/InputHandler.cs @@ -183,10 +183,11 @@ namespace ClassicalSharp { bool more; if( !Hotkeys.IsHotkey( key, game.Keyboard, out text, out more ) ) return; - if( !more ) + if( !more ) { game.Network.SendChat( text, false ); - else if( game.Gui.activeScreen == null ) + } else if( game.Gui.activeScreen == null ) { game.Gui.hudScreen.OpenTextInputBar( text ); + } } MouseButtonEventArgs simArgs = new MouseButtonEventArgs(); diff --git a/ClassicalSharp/Game/PickingHandler.cs b/ClassicalSharp/Game/PickingHandler.cs index d8bc48fe9..cae7f7258 100644 --- a/ClassicalSharp/Game/PickingHandler.cs +++ b/ClassicalSharp/Game/PickingHandler.cs @@ -109,18 +109,19 @@ namespace ClassicalSharp { Vector3 oldP = game.LocalPlayer.Position; // Offset position by the closest face - if( selected.BlockFace == CpeBlockFace.XMax ) + if( selected.BlockFace == CpeBlockFace.XMax ) { newP.X = blockBB.Max.X + 0.5f; - else if( selected.BlockFace == CpeBlockFace.ZMax ) + } else if( selected.BlockFace == CpeBlockFace.ZMax ) { newP.Z = blockBB.Max.Z + 0.5f; - else if( selected.BlockFace == CpeBlockFace.XMin ) + } else if( selected.BlockFace == CpeBlockFace.XMin ) { newP.X = blockBB.Min.X - 0.5f; - else if( selected.BlockFace == CpeBlockFace.ZMin ) + } else if( selected.BlockFace == CpeBlockFace.ZMin ) { newP.Z = blockBB.Min.Z - 0.5f; - else if( selected.BlockFace == CpeBlockFace.YMax ) + } else if( selected.BlockFace == CpeBlockFace.YMax ) { newP.Y = blockBB.Min.Y + 1 + Entity.Adjustment; - else if( selected.BlockFace == CpeBlockFace.YMin ) + } else if( selected.BlockFace == CpeBlockFace.YMin ) { newP.Y = blockBB.Min.Y - game.LocalPlayer.Size.Y - Entity.Adjustment; + } Vector3I newLoc = Vector3I.Floor( newP ); bool validPos = newLoc.X >= 0 && newLoc.Y >= 0 && newLoc.Z >= 0 && diff --git a/ClassicalSharp/Generator/NotchyGenerator.Utils.cs b/ClassicalSharp/Generator/NotchyGenerator.Utils.cs index 24af2c980..aacf323d0 100644 --- a/ClassicalSharp/Generator/NotchyGenerator.Utils.cs +++ b/ClassicalSharp/Generator/NotchyGenerator.Utils.cs @@ -37,18 +37,17 @@ namespace ClassicalSharp.Generator { stack.Push( startIndex ); while( stack.Size > 0 ) { int index = stack.Pop(); - if( blocks[index] == 0 ) { - blocks[index] = block; - - int x = index % width; - int y = index / oneY; - int z = (index / width) % length; - if( x > 0 ) stack.Push( index - 1 ); - if( x < width - 1 ) stack.Push( index + 1 ); - if( z > 0 ) stack.Push( index - width ); - if( z < length - 1 ) stack.Push( index + width ); - if( y > 0 ) stack.Push( index - oneY ); - } + if( blocks[index] != 0 ) continue; + blocks[index] = block; + + int x = index % width; + int y = index / oneY; + int z = (index / width) % length; + if( x > 0 ) stack.Push( index - 1 ); + if( x < width - 1 ) stack.Push( index + 1 ); + if( z > 0 ) stack.Push( index - width ); + if( z < length - 1 ) stack.Push( index + width ); + if( y > 0 ) stack.Push( index - oneY ); } } diff --git a/ClassicalSharp/Map/Formats/MapLvl.Importer.cs b/ClassicalSharp/Map/Formats/MapLvl.Importer.cs index d90702c2e..b3626fd3e 100644 --- a/ClassicalSharp/Map/Formats/MapLvl.Importer.cs +++ b/ClassicalSharp/Map/Formats/MapLvl.Importer.cs @@ -61,8 +61,8 @@ namespace ClassicalSharp.Map { int bx = i & 0xF, by = (i >> 8) & 0xF, bz = (i >> 4) & 0xF; int index = baseIndex + (by * length + bz) * width + bx; - if( blocks[index] == customTile ) - blocks[index] = chunk[i]; + if( blocks[index] != customTile ) continue; + blocks[index] = chunk[i]; } } } diff --git a/ClassicalSharp/Network/NetworkProcessor.Original.cs b/ClassicalSharp/Network/NetworkProcessor.Original.cs index 2388aed8e..4e79740cc 100644 --- a/ClassicalSharp/Network/NetworkProcessor.Original.cs +++ b/ClassicalSharp/Network/NetworkProcessor.Original.cs @@ -122,8 +122,7 @@ namespace ClassicalSharp.Network { internal void HandleLevelDataChunk() { // Workaround for some servers that send LevelDataChunk before LevelInit // due to their async packet sending behaviour. - if( gzipStream == null ) - HandleLevelInit(); + if( gzipStream == null ) HandleLevelInit(); int usedLength = reader.ReadInt16(); gzippedMap.Position = 0; gzippedMap.Offset = reader.index; @@ -152,8 +151,9 @@ namespace ClassicalSharp.Network { task.Interval = 1.0 / 20; game.Gui.SetNewScreen( null ); game.Gui.activeScreen = prevScreen; - if( prevScreen != null && prevCursorVisible != game.CursorVisible ) + if( prevScreen != null && prevCursorVisible != game.CursorVisible ) { game.CursorVisible = prevCursorVisible; + } prevScreen = null; int mapWidth = reader.ReadInt16(); diff --git a/ClassicalSharp/Network/NetworkProcessor.cs b/ClassicalSharp/Network/NetworkProcessor.cs index 8dcc3a0d0..1862b9170 100644 --- a/ClassicalSharp/Network/NetworkProcessor.cs +++ b/ClassicalSharp/Network/NetworkProcessor.cs @@ -67,8 +67,9 @@ namespace ClassicalSharp.Network { public override void Tick( ScheduledTask task ) { if( Disconnected ) return; - if( (DateTime.UtcNow - lastPacket).TotalSeconds >= 30 ) + if( (DateTime.UtcNow - lastPacket).TotalSeconds >= 30 ) { CheckDisconnection( task.Interval ); + } if( Disconnected ) return; LocalPlayer player = game.LocalPlayer; @@ -209,10 +210,12 @@ namespace ClassicalSharp.Network { void BlockChanged( object sender, BlockChangedEventArgs e ) { Vector3I p = e.Coords; byte block = game.Inventory.HeldBlock; - if( e.Block == 0 ) + + if( e.Block == 0 ) { SendSetBlock( p.X, p.Y, p.Z, false, block ); - else + } else { SendSetBlock( p.X, p.Y, p.Z, true, e.Block ); + } } void OnNewMap( object sender, EventArgs e ) { diff --git a/ClassicalSharp/Rendering/ChunkUpdater.cs b/ClassicalSharp/Rendering/ChunkUpdater.cs index 79f05dbb0..710c154ed 100644 --- a/ClassicalSharp/Rendering/ChunkUpdater.cs +++ b/ClassicalSharp/Rendering/ChunkUpdater.cs @@ -57,7 +57,7 @@ namespace ClassicalSharp.Renderers { game.WorldEvents.OnNewMap -= OnNewMap; game.WorldEvents.OnNewMapLoaded -= OnNewMapLoaded; game.WorldEvents.EnvVariableChanged -= EnvVariableChanged; - game.WorldEvents.BlockDefinitionChanged -= BlockDefinitionChanged; + game.Events.BlockDefinitionChanged -= BlockDefinitionChanged; game.Events.ViewDistanceChanged -= ViewDistanceChanged; game.Events.ProjectionChanged -= ProjectionChanged; builder.Dispose(); @@ -388,7 +388,7 @@ namespace ClassicalSharp.Renderers { } else { if( info.NormalParts != null ) IncrementUsed( info.NormalParts ); - if (info.TranslucentParts != null ) + if ( info.TranslucentParts != null ) IncrementUsed( info.TranslucentParts ); } chunkUpdates++;