diff --git a/MinecraftClient/Mapping/World.cs b/MinecraftClient/Mapping/World.cs index 6c31c8de..66290a40 100644 --- a/MinecraftClient/Mapping/World.cs +++ b/MinecraftClient/Mapping/World.cs @@ -317,7 +317,7 @@ namespace MinecraftClient.Mapping public static void SetDimension(string name) { // Try to get the dimension using the name as is - if (dimensionList.TryGetValue(name, out Dimension dimension)) + if (dimensionList.TryGetValue(name, out Dimension? dimension)) { curDimension = dimension; return; // Dimension found diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs index 96762e74..a9fccdba 100644 --- a/MinecraftClient/McClient.cs +++ b/MinecraftClient/McClient.cs @@ -61,14 +61,12 @@ namespace MinecraftClient private readonly Lock locationLock = new(); private bool locationReceived = false; private readonly World world = new(); - private Queue? steps; private Queue? path; private Location location; private float? _yaw; // Used for calculation ONLY!!! Doesn't reflect the client yaw private float? _pitch; // Used for calculation ONLY!!! Doesn't reflect the client pitch private float playerYaw; private float playerPitch; - private double motionY; private readonly PlayerPhysics playerPhysics = new(); private readonly MovementInput physicsInput = new(); private bool physicsInitialized = false; @@ -156,8 +154,8 @@ namespace MinecraftClient public void SetCookie(string key, byte[] data) => Cookies[key] = data; public void DeleteCookie(string key) => Cookies.Remove(key, out var data); - TcpClient client; - IMinecraftCom handler; + TcpClient client = null!; + IMinecraftCom handler = null!; SessionToken _sessionToken; CancellationTokenSource? cmdprompt = null; Tuple? timeoutdetector = null; @@ -213,7 +211,7 @@ namespace MinecraftClient scope.SetTag("MCC Build", Program.BuildInfo is null ? "Debug" : Program.BuildInfo); if (forgeInfo is not null) - scope.SetTag("Forge Version", forgeInfo?.Version.ToString()); + scope.SetTag("Forge Version", forgeInfo.Version.ToString()); scope.Contexts["Server Information"] = new { @@ -2782,7 +2780,7 @@ namespace MinecraftClient /// true if a movement is currently handled public bool ClientIsMoving() { - return terrainAndMovementsEnabled && locationReceived && ((steps is not null && steps.Count > 0) || (path is not null && path.Count > 0)); + return terrainAndMovementsEnabled && locationReceived && path is not null && path.Count > 0; } /// diff --git a/MinecraftClient/Protocol/Handlers/DataTypes.cs b/MinecraftClient/Protocol/Handlers/DataTypes.cs index 94b1f3ff..82e17ae1 100644 --- a/MinecraftClient/Protocol/Handlers/DataTypes.cs +++ b/MinecraftClient/Protocol/Handlers/DataTypes.cs @@ -973,7 +973,7 @@ namespace MinecraftClient.Protocol.Handlers return data; } - catch(Exception ex) + catch (Exception) { return new Dictionary(); } diff --git a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/BundleContentsComponent.cs b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/BundleContentsComponent.cs index 4ff4c4ff..753a621b 100644 --- a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/BundleContentsComponent.cs +++ b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/BundleContentsComponent.cs @@ -16,7 +16,7 @@ public class BundleContentsComponent(DataTypes dataTypes, ItemPalette itemPalett for (var i = 0; i < count; i++) { - var item = DataTypes.ReadNextItemSlot(data, itemPalette); + var item = DataTypes.ReadNextItemSlot(data, ItemPalette); if (item is not null) Items.Add(item); } @@ -28,7 +28,7 @@ public class BundleContentsComponent(DataTypes dataTypes, ItemPalette itemPalett data.AddRange(DataTypes.GetVarInt(Items.Count)); foreach (var item in Items) - data.AddRange(DataTypes.GetItemSlot(item, itemPalette)); + data.AddRange(DataTypes.GetItemSlot(item, ItemPalette)); return new Queue(data); } diff --git a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/ChargedProjectilesComponent.cs b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/ChargedProjectilesComponent.cs index 06b5904e..55e597a3 100644 --- a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/ChargedProjectilesComponent.cs +++ b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/ChargedProjectilesComponent.cs @@ -16,7 +16,7 @@ public class ChargedProjectilesComponent(DataTypes dataTypes, ItemPalette itemPa for (var i = 0; i < count; i++) { - var item = DataTypes.ReadNextItemSlot(data, itemPalette); + var item = DataTypes.ReadNextItemSlot(data, ItemPalette); if (item is not null) Items.Add(item); } @@ -28,7 +28,7 @@ public class ChargedProjectilesComponent(DataTypes dataTypes, ItemPalette itemPa data.AddRange(DataTypes.GetVarInt(Items.Count)); foreach (var item in Items) - data.AddRange(DataTypes.GetItemSlot(item, itemPalette)); + data.AddRange(DataTypes.GetItemSlot(item, ItemPalette)); return new Queue(data); } diff --git a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/ContainerComponent.cs b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/ContainerComponent.cs index 61428b36..f198952a 100644 --- a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/ContainerComponent.cs +++ b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/ContainerComponent.cs @@ -22,7 +22,7 @@ public class ContainerComponent(DataTypes dataTypes, ItemPalette itemPalette, Su var data = new List(); data.AddRange(DataTypes.GetVarInt(Items.Count)); foreach (var item in Items) - data.AddRange(DataTypes.GetItemSlot(item, itemPalette)); + data.AddRange(DataTypes.GetItemSlot(item, ItemPalette)); return new Queue(data); } diff --git a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/Subcomponents/1_20_6/EffectSubComponent.cs b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/Subcomponents/1_20_6/EffectSubComponent.cs index 8b6795ec..250cbd6f 100644 --- a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/Subcomponents/1_20_6/EffectSubComponent.cs +++ b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/Subcomponents/1_20_6/EffectSubComponent.cs @@ -6,7 +6,7 @@ namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subc public class EffectSubComponent(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : SubComponent(dataTypes, subComponentRegistry) { - public PotionEffectSubComponent TypeId { get; set; } + public PotionEffectSubComponent TypeId { get; set; } = null!; public float Probability { get; set; } protected override void Parse(Queue data) diff --git a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/Subcomponents/1_20_6/PotionEffectSubComponent.cs b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/Subcomponents/1_20_6/PotionEffectSubComponent.cs index c627f726..d667c5b3 100644 --- a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/Subcomponents/1_20_6/PotionEffectSubComponent.cs +++ b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/Subcomponents/1_20_6/PotionEffectSubComponent.cs @@ -7,7 +7,7 @@ namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subc public class PotionEffectSubComponent(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : SubComponent(dataTypes, subComponentRegistry) { public int TypeId { get; set; } - public DetailsSubComponent Details { get; set; } + public DetailsSubComponent Details { get; set; } = null!; protected override void Parse(Queue data) { diff --git a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/Subcomponents/1_20_6/RuleSubComponent.cs b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/Subcomponents/1_20_6/RuleSubComponent.cs index 6cf163fd..1356ceef 100644 --- a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/Subcomponents/1_20_6/RuleSubComponent.cs +++ b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/Subcomponents/1_20_6/RuleSubComponent.cs @@ -6,7 +6,7 @@ namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subc public class RuleSubComponent(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : SubComponent(dataTypes, subComponentRegistry) { - public BlockSetSubcomponent Blocks { get; set; } + public BlockSetSubcomponent Blocks { get; set; } = null!; public bool HasSpeed { get; set; } public float Speed { get; set; } public bool HasCorrectDropForBlocks { get; set; } diff --git a/MinecraftClient/Protocol/Message/ChatParser.cs b/MinecraftClient/Protocol/Message/ChatParser.cs index 610a2d7e..28311400 100644 --- a/MinecraftClient/Protocol/Message/ChatParser.cs +++ b/MinecraftClient/Protocol/Message/ChatParser.cs @@ -545,11 +545,11 @@ namespace MinecraftClient.Protocol.Message break; case "translate": { - if (nbt.TryGetValue("translate", out object translate)) + if (nbt.TryGetValue("translate", out object? translate)) { var translateKey = (string)translate; List translateString = new(); - if (nbt.TryGetValue("with", out object withComponent)) + if (nbt.TryGetValue("with", out object? withComponent)) { var withs = (object[])withComponent; for (var i = 0; i < withs.Length; i++) @@ -574,7 +574,7 @@ namespace MinecraftClient.Protocol.Message break; case "color": { - if (nbt.TryGetValue("color", out object color)) + if (nbt.TryGetValue("color", out object? color)) { colorCode = Color2tag((string)color); } diff --git a/MinecraftClient/Scripting/DynamicRun/Builder/Compiler.cs b/MinecraftClient/Scripting/DynamicRun/Builder/Compiler.cs index c941aa19..9cc1df13 100644 --- a/MinecraftClient/Scripting/DynamicRun/Builder/Compiler.cs +++ b/MinecraftClient/Scripting/DynamicRun/Builder/Compiler.cs @@ -82,6 +82,8 @@ namespace MinecraftClient.Scripting.DynamicRun.Builder { // Create a temporary file to copy the executable to. var executablePath = Environment.ProcessPath; + if (executablePath is null) + throw new InvalidOperationException("Cannot determine the process path for self-contained scripting extraction."); var tempPath = Path.Combine(Path.GetTempPath(), "mcc-scripting"); Directory.CreateDirectory(tempPath);