From 83f29d4bdec738cbaedc77028bd7c105e7932ee7 Mon Sep 17 00:00:00 2001 From: Aaron B <24834067+Aaron2550@users.noreply.github.com> Date: Thu, 16 Nov 2023 15:54:02 +0100 Subject: [PATCH] .NET 8 and Cleanup (#392) * Update Projects to .NET 8 * Use collection initializers (IDE0028) * Simplify collection initializers (IDE0300) * Update docfx.yml to .NET 8 * Update dotnet.yml to .NET 8 * Simplify collection initializers (IDE0301) * Simplify collection initializers (IDE0302) * Simplify collection initializers (IDE0305) * Invalid version format, change X to x * Revert "Use collection initializers (IDE0028)" This reverts commit ff24a25f48538b30da3f3de2dbdb32c20efe5a45. * Use collection initializers (IDE0028) - but carefully * Update Artifact Paths * Revert "Simplify collection initializers (IDE0305)" This reverts commit b7c0923d3e4fc81466fb3b4adb23e0221c58fb88. * Edit editorconfig so IDE0305 will not be suggested --- .editorconfig | 5 +++- .github/workflows/docfx.yml | 2 +- .github/workflows/dotnet.yml | 6 ++--- Obsidian.API/AI/AStarPath.cs | 14 +++++------ .../Crafting/Builders/ShapedRecipeBuilder.cs | 6 ++--- .../Builders/ShapelessRecipeBuilder.cs | 4 ++-- .../SmithingTransformRecipeBuilder.cs | 8 +++---- Obsidian.API/Crafting/Ingredient.cs | 2 +- Obsidian.API/Obsidian.API.csproj | 2 +- Obsidian.API/Plugins/PluginBase.cs | 4 ++-- Obsidian.API/_Types/BitSet.cs | 2 +- Obsidian.API/_Types/BoundingBox.cs | 6 ++--- Obsidian.API/_Types/ChatMessage.cs | 6 ++--- .../_Types/Inventory/ItemMetaBuilder.cs | 8 +++---- Obsidian.API/_Types/MinecraftArgumentTypes.cs | 4 ++-- Obsidian.API/_Types/Traversal.cs | 2 +- Obsidian.API/_Types/Vector.cs | 2 +- .../Obsidian.ConsoleApp.csproj | 2 +- Obsidian.Nbt/NbtCompound.cs | 2 +- Obsidian.Nbt/NbtList.cs | 2 +- Obsidian.Nbt/Obsidian.Nbt.csproj | 2 +- .../Attributes/AttributeBehaviorBase.cs | 2 +- .../Packets/Attributes/AttributeFactory.cs | 2 +- .../Packets/MethodsRegistry.cs | 4 ++-- .../Packets/SerializationMethodsGenerator.cs | 6 ++--- .../Registry/Models/Assets.cs | 10 ++++---- .../Registry/Models/BlockProperty.cs | 2 +- .../Registry/Models/Codec.cs | 2 +- .../Registry/Models/Customizations.cs | 2 +- .../Registry/Models/Tag.cs | 2 +- Obsidian.Tests/Boolean.cs | 2 +- Obsidian.Tests/Encryption.cs | 2 +- Obsidian.Tests/Obsidian.Tests.csproj | 2 +- Obsidian.Tests/String.cs | 2 +- Obsidian/BossBar.cs | 2 +- Obsidian/Client.cs | 6 ++--- Obsidian/Commands/CommandNode.cs | 2 +- Obsidian/Commands/Framework/CommandHandler.cs | 4 ++-- Obsidian/Entities/Player.cs | 6 ++--- Obsidian/Events/AsyncEvent.T.cs | 2 +- Obsidian/Net/MinecraftStream.Writing.cs | 2 +- Obsidian/Net/Rcon/RconPacket.cs | 6 ++--- Obsidian/Obsidian.csproj | 2 +- Obsidian/Plugins/DirectoryWatcher.cs | 4 ++-- .../PluginProviders/CompiledPluginProvider.cs | 2 +- .../Registries/BlocksRegistry.Properties.cs | 2 +- Obsidian/Server.cs | 4 ++-- Obsidian/Utilities/Collections/DataArray.cs | 4 ++-- Obsidian/Utilities/Config.cs | 2 +- Obsidian/Utilities/Extensions.cs | 4 ++-- Obsidian/Utilities/GuidHelper.cs | 7 +++--- Obsidian/Utilities/ServerStatus.cs | 2 +- .../WorldData/Decorators/DecoratorFactory.cs | 2 +- .../Decorators/OverworldDecorator.cs | 2 +- .../WorldData/Generators/IslandGenerator.cs | 10 ++++---- .../Generators/Overworld/ChunkBuilder.cs | 24 +++++++++---------- Obsidian/WorldData/Region.cs | 10 ++++---- Obsidian/WorldData/RegionFile.cs | 2 +- SamplePlugin/SamplePlugin.csproj | 2 +- 59 files changed, 126 insertions(+), 120 deletions(-) diff --git a/.editorconfig b/.editorconfig index 8fa7bbf27..a0f1f5f7e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -151,4 +151,7 @@ insert_final_newline=true dotnet_style_prefer_simplified_boolean_expressions=true:warning dotnet_style_prefer_conditional_expression_over_assignment=true:suggestion dotnet_style_prefer_conditional_expression_over_return=true:suggestion -dotnet_code_quality_unused_parameters=all:warning \ No newline at end of file +dotnet_code_quality_unused_parameters=all:warning + +# IDE0305: Simplify collection initializers (IDE0305) - See https://github.com/dotnet/roslyn/issues/70656 +dotnet_diagnostic.IDE0305.severity = none diff --git a/.github/workflows/docfx.yml b/.github/workflows/docfx.yml index 50338f749..0c4a91d93 100644 --- a/.github/workflows/docfx.yml +++ b/.github/workflows/docfx.yml @@ -22,7 +22,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.0.103 + dotnet-version: 8.0.0 - name: Install DocFX run: dotnet tool update -g docfx continue-on-error: true diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 06a2f9120..9d381075f 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -17,14 +17,14 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 7.0.x + dotnet-version: 8.0.x include-prerelease: true - name: Restore dependencies run: dotnet restore - name: Build run: dotnet build --no-restore --configuration Release /p:DebugType=None - name: Rename executables - working-directory: /home/runner/work/Obsidian/Obsidian/Obsidian.ConsoleApp/bin/Release/net7.0/ + working-directory: /home/runner/work/Obsidian/Obsidian/Obsidian.ConsoleApp/bin/Release/net8.0/ run: | mv Obsidian.ConsoleApp.dll ObsidianApp.dll mv Obsidian.ConsoleApp.deps.json ObsidianApp.deps.json @@ -33,7 +33,7 @@ jobs: uses: actions/upload-artifact@v2.2.4 with: name: Obsidian-Nightly-Build - path: /home/runner/work/Obsidian/Obsidian/Obsidian.ConsoleApp/bin/Release/net7.0/ + path: /home/runner/work/Obsidian/Obsidian/Obsidian.ConsoleApp/bin/Release/net8.0/ if: ${{ github.event_name == 'push' }} # Only upload artifacts on push, don't upload them for PRs - name: Discord Webhook Action uses: tsickert/discord-webhook@v4.0.0 diff --git a/Obsidian.API/AI/AStarPath.cs b/Obsidian.API/AI/AStarPath.cs index 23de147f9..1589de12e 100644 --- a/Obsidian.API/AI/AStarPath.cs +++ b/Obsidian.API/AI/AStarPath.cs @@ -20,8 +20,8 @@ internal class AStarPath private readonly IWorld world; - private readonly List validMoves = new() - { + private readonly List validMoves = + [ Vector.Left, Vector.Right, Vector.Forwards, @@ -43,7 +43,7 @@ internal class AStarPath Vector.Backwards + Vector.Down, Vector.Left + Vector.Down, Vector.Right + Vector.Down, - }; + ]; public AStarPath(IWorld world) { @@ -58,11 +58,11 @@ public List GetPath(Vector startPos, Vector targetPos) // Out of range? float distanceSquared = (targetPos - startPos).MagnitudeSquared(); if (distanceSquared > MaxRange * MaxRange) - return new List(); + return []; - List openList = new(); - List closedList = new(); + List openList = []; + List closedList = []; openList.Add(startNode); @@ -130,7 +130,7 @@ public List GetPath(Vector startPos, Vector targetPos) } } - return new List(); + return []; } private bool IsValidMove(Vector curPos, Vector nextPos) diff --git a/Obsidian.API/Crafting/Builders/ShapedRecipeBuilder.cs b/Obsidian.API/Crafting/Builders/ShapedRecipeBuilder.cs index 0c6596a03..90af1cd7f 100644 --- a/Obsidian.API/Crafting/Builders/ShapedRecipeBuilder.cs +++ b/Obsidian.API/Crafting/Builders/ShapedRecipeBuilder.cs @@ -7,9 +7,9 @@ public sealed class ShapedRecipeBuilder : BaseRecipeBuilder, IPatt { private readonly CraftingBookCategory category; - private readonly List pattern = new(); + private readonly List pattern = []; - private readonly Dictionary key = new(); + private readonly Dictionary key = []; private bool showNotification; @@ -61,7 +61,7 @@ public override ShapedRecipe Build() Identifier = this.Identifier ?? throw new NullReferenceException("Recipe must have a name"), Type = CraftingType.CraftingShaped, Group = this.Group, - Result = this.Result != null ? new Ingredient { this.Result } : throw new NullReferenceException("Result is not set."), + Result = this.Result != null ? [this.Result] : throw new NullReferenceException("Result is not set."), Pattern = new ReadOnlyCollection(new List(this.pattern)), Key = new ReadOnlyDictionary(new Dictionary(this.key)), Category = this.category, diff --git a/Obsidian.API/Crafting/Builders/ShapelessRecipeBuilder.cs b/Obsidian.API/Crafting/Builders/ShapelessRecipeBuilder.cs index 5172a442b..91ddc05e6 100644 --- a/Obsidian.API/Crafting/Builders/ShapelessRecipeBuilder.cs +++ b/Obsidian.API/Crafting/Builders/ShapelessRecipeBuilder.cs @@ -7,7 +7,7 @@ public sealed class ShapelessRecipeBuilder : BaseRecipeBuilder, { private readonly CraftingBookCategory category; - private readonly List ingredients = new(); + private readonly List ingredients = []; private ShapelessRecipeBuilder(CraftingBookCategory category) => this.category = category; @@ -31,7 +31,7 @@ public override ShapelessRecipe Build() Identifier = this.Identifier ?? throw new NullReferenceException("Recipe must have a name"), Type = CraftingType.CraftingShapeless, Group = this.Group, - Result = this.Result != null ? new Ingredient { this.Result } : throw new NullReferenceException("Result is not set."), + Result = this.Result != null ? [this.Result] : throw new NullReferenceException("Result is not set."), Ingredients = new ReadOnlyCollection(new List(this.ingredients)), Category = this.category }; diff --git a/Obsidian.API/Crafting/Builders/SmithingTransformRecipeBuilder.cs b/Obsidian.API/Crafting/Builders/SmithingTransformRecipeBuilder.cs index 0ec7de9c8..7fa138a53 100644 --- a/Obsidian.API/Crafting/Builders/SmithingTransformRecipeBuilder.cs +++ b/Obsidian.API/Crafting/Builders/SmithingTransformRecipeBuilder.cs @@ -7,9 +7,9 @@ public sealed class SmithingTransformRecipeBuilder : BaseRecipeBuilder, ITemplateIngredientRecipe { - private Ingredient @base = new(); - private Ingredient addition = new(); - private Ingredient template = new(); + private Ingredient @base = []; + private Ingredient addition = []; + private Ingredient template = []; private SmithingTransformRecipeBuilder() { } @@ -55,7 +55,7 @@ public override SmithingTransformRecipe Build() Base = this.@base, Addition = this.addition, Template = template, - Result = this.Result != null ? new Ingredient { this.Result } : throw new NullReferenceException("Result is not set.") + Result = this.Result != null ? [this.Result] : throw new NullReferenceException("Result is not set.") }; } } diff --git a/Obsidian.API/Crafting/Ingredient.cs b/Obsidian.API/Crafting/Ingredient.cs index 3cba2c881..cd74f407c 100644 --- a/Obsidian.API/Crafting/Ingredient.cs +++ b/Obsidian.API/Crafting/Ingredient.cs @@ -10,7 +10,7 @@ public class Ingredient : IEnumerable public Ingredient() { - this.items = new List(); + this.items = []; } public void Add(ItemStack item) => this.items.Add(item); diff --git a/Obsidian.API/Obsidian.API.csproj b/Obsidian.API/Obsidian.API.csproj index b0e9f43e7..cd701fc76 100644 --- a/Obsidian.API/Obsidian.API.csproj +++ b/Obsidian.API/Obsidian.API.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 True enable Obsidian.API diff --git a/Obsidian.API/Plugins/PluginBase.cs b/Obsidian.API/Plugins/PluginBase.cs index d1977fcab..87f170fad 100644 --- a/Obsidian.API/Plugins/PluginBase.cs +++ b/Obsidian.API/Plugins/PluginBase.cs @@ -181,7 +181,7 @@ protected void Unload() private MethodInfo? GetMethod(string methodName, object[] args) { - args ??= Array.Empty(); + args ??= []; var types = new Type[args.Length]; for (int i = 0; i < args.Length; i++) { @@ -201,7 +201,7 @@ protected void Unload() private (MethodInfo? method, int parameterCount) GetFriendlyMethod(string methodName, object[] args) { typeCache ??= GetType(); - args ??= Array.Empty(); + args ??= []; IEnumerable<(MethodInfo method, ParameterInfo[] parameters)> methods = typeCache .GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static) .Where(method => method.Name == methodName) diff --git a/Obsidian.API/_Types/BitSet.cs b/Obsidian.API/_Types/BitSet.cs index 9ff434307..4bfa3321f 100644 --- a/Obsidian.API/_Types/BitSet.cs +++ b/Obsidian.API/_Types/BitSet.cs @@ -3,7 +3,7 @@ public sealed class BitSet { public ReadOnlyMemory DataStorage => data.AsMemory(); - private long[] data = Array.Empty(); + private long[] data = []; public void SetBit(int bitIndex, bool value) { diff --git a/Obsidian.API/_Types/BoundingBox.cs b/Obsidian.API/_Types/BoundingBox.cs index 0d07e57d8..ea2de23f6 100644 --- a/Obsidian.API/_Types/BoundingBox.cs +++ b/Obsidian.API/_Types/BoundingBox.cs @@ -84,8 +84,8 @@ public static BoundingBox CreateFromPoints(IEnumerable points) public VectorF[] GetCorners() { - return new[] - { + return + [ new VectorF(Min.X, Max.Y, Max.Z), new VectorF(Max.X, Max.Y, Max.Z), new VectorF(Max.X, Min.Y, Max.Z), @@ -94,7 +94,7 @@ public VectorF[] GetCorners() new VectorF(Max.X, Max.Y, Min.Z), new VectorF(Max.X, Min.Y, Min.Z), new VectorF(Min.X, Min.Y, Min.Z) - }; + ]; } public override bool Equals(object? obj) => (obj is BoundingBox box) && this.Equals(box); diff --git a/Obsidian.API/_Types/ChatMessage.cs b/Obsidian.API/_Types/ChatMessage.cs index 24444b16f..fd4c8fe52 100644 --- a/Obsidian.API/_Types/ChatMessage.cs +++ b/Obsidian.API/_Types/ChatMessage.cs @@ -171,7 +171,7 @@ public static string ReformatAmpersandPrefixes(string originalText) public ChatMessage AddChatComponent(ChatMessage message) { - this.With ??= new(); + this.With ??= []; this.With.Add(message); return this; @@ -179,7 +179,7 @@ public ChatMessage AddChatComponent(ChatMessage message) public ChatMessage AddChatComponent(IEnumerable message) { - this.With ??= new(); + this.With ??= []; this.With.AddRange(message); return this; @@ -188,7 +188,7 @@ public ChatMessage AddChatComponent(IEnumerable message) public ChatMessage AddExtra(ChatMessage message) { - Extra ??= new List(); + Extra ??= []; Extra.Add(message); return this; diff --git a/Obsidian.API/_Types/Inventory/ItemMetaBuilder.cs b/Obsidian.API/_Types/Inventory/ItemMetaBuilder.cs index aab162b91..8be5caaa2 100644 --- a/Obsidian.API/_Types/Inventory/ItemMetaBuilder.cs +++ b/Obsidian.API/_Types/Inventory/ItemMetaBuilder.cs @@ -18,12 +18,12 @@ public class ItemMetaBuilder public IReadOnlyList Lore { get; } - private readonly Dictionary enchantments = new Dictionary(); - private readonly Dictionary storedEnchantments = new Dictionary(); + private readonly Dictionary enchantments = []; + private readonly Dictionary storedEnchantments = []; - private readonly List canDestroy = new List(); + private readonly List canDestroy = []; - private readonly List lore = new List(); + private readonly List lore = []; public ItemMetaBuilder() { diff --git a/Obsidian.API/_Types/MinecraftArgumentTypes.cs b/Obsidian.API/_Types/MinecraftArgumentTypes.cs index 9405f736c..656167c8a 100644 --- a/Obsidian.API/_Types/MinecraftArgumentTypes.cs +++ b/Obsidian.API/_Types/MinecraftArgumentTypes.cs @@ -4,7 +4,7 @@ public class MinecraftArgumentTypes { // TODO maybe make a Dictionary mapping an enum to a string? private static string[] mcTypes = - { + [ "brigadier:bool", "brigadier:double", "brigadier:float", @@ -52,7 +52,7 @@ public class MinecraftArgumentTypes "minecraft:time", // OBSIDIAN TYPES "obsidian:player" - }; + ]; public static bool IsValidMcType(string? input) => mcTypes.Contains(input); } diff --git a/Obsidian.API/_Types/Traversal.cs b/Obsidian.API/_Types/Traversal.cs index ef40757f9..e7629804e 100644 --- a/Obsidian.API/_Types/Traversal.cs +++ b/Obsidian.API/_Types/Traversal.cs @@ -33,7 +33,7 @@ private static float Frac1(float x) public List Run() { - List blocks = new List(); + List blocks = []; float tMaxX, tMaxY, tMaxZ, tDeltaX, tDeltaY, tDeltaZ; VectorF voxel = new VectorF(); diff --git a/Obsidian.API/_Types/Vector.cs b/Obsidian.API/_Types/Vector.cs index f3800f7cf..361073d8b 100644 --- a/Obsidian.API/_Types/Vector.cs +++ b/Obsidian.API/_Types/Vector.cs @@ -297,7 +297,7 @@ public readonly override bool Equals(object? obj) /// public static readonly IEnumerable CardinalDirs = new[] { North, South, West, East }; - internal static readonly Vector[] AllDirections = new[] { North, South, West, East, Up, Down }; + internal static readonly Vector[] AllDirections = [North, South, West, East, Up, Down]; private string GetDebuggerDisplay() { diff --git a/Obsidian.ConsoleApp/Obsidian.ConsoleApp.csproj b/Obsidian.ConsoleApp/Obsidian.ConsoleApp.csproj index 3fd74bcf4..12ce39cec 100644 --- a/Obsidian.ConsoleApp/Obsidian.ConsoleApp.csproj +++ b/Obsidian.ConsoleApp/Obsidian.ConsoleApp.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 disable enable true diff --git a/Obsidian.Nbt/NbtCompound.cs b/Obsidian.Nbt/NbtCompound.cs index 09e6cdb0d..3c9dc4d16 100644 --- a/Obsidian.Nbt/NbtCompound.cs +++ b/Obsidian.Nbt/NbtCompound.cs @@ -5,7 +5,7 @@ namespace Obsidian.Nbt; public class NbtCompound : INbtTag, IEnumerable> { - private readonly Dictionary children = new(); + private readonly Dictionary children = []; public int Count => this.children.Count; diff --git a/Obsidian.Nbt/NbtList.cs b/Obsidian.Nbt/NbtList.cs index f313d0b26..851d7b6ce 100644 --- a/Obsidian.Nbt/NbtList.cs +++ b/Obsidian.Nbt/NbtList.cs @@ -5,7 +5,7 @@ namespace Obsidian.Nbt; public class NbtList : INbtTag, IList { - private readonly List baseList = new(); + private readonly List baseList = []; public int Count => this.baseList.Count; diff --git a/Obsidian.Nbt/Obsidian.Nbt.csproj b/Obsidian.Nbt/Obsidian.Nbt.csproj index aaeb0e3bf..615a9af8c 100644 --- a/Obsidian.Nbt/Obsidian.Nbt.csproj +++ b/Obsidian.Nbt/Obsidian.Nbt.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 diff --git a/Obsidian.SourceGenerators/Packets/Attributes/AttributeBehaviorBase.cs b/Obsidian.SourceGenerators/Packets/Attributes/AttributeBehaviorBase.cs index 26fc5aab6..d9295c248 100644 --- a/Obsidian.SourceGenerators/Packets/Attributes/AttributeBehaviorBase.cs +++ b/Obsidian.SourceGenerators/Packets/Attributes/AttributeBehaviorBase.cs @@ -14,7 +14,7 @@ internal abstract class AttributeBehaviorBase public AttributeBehaviorBase(AttributeSyntax attributeSyntax) { syntax = attributeSyntax; - arguments = attributeSyntax?.ArgumentList?.Arguments.Select(arg => arg).ToArray() ?? Array.Empty(); + arguments = attributeSyntax?.ArgumentList?.Arguments.Select(arg => arg).ToArray() ?? []; } public virtual bool Matches(AttributeOwner other) diff --git a/Obsidian.SourceGenerators/Packets/Attributes/AttributeFactory.cs b/Obsidian.SourceGenerators/Packets/Attributes/AttributeFactory.cs index d6dd8a716..7f7c512eb 100644 --- a/Obsidian.SourceGenerators/Packets/Attributes/AttributeFactory.cs +++ b/Obsidian.SourceGenerators/Packets/Attributes/AttributeFactory.cs @@ -55,7 +55,7 @@ private static Dictionary GetFactoryMethods() private static FactoryMethod GetFactoryMethod(this Type type) { var parameter = Expression.Parameter(typeof(AttributeSyntax)); - var ctor = type.GetConstructor(new[] { typeof(AttributeSyntax) }); + var ctor = type.GetConstructor([typeof(AttributeSyntax)]); var lambda = Expression.Lambda(Expression.New(ctor, parameter), parameter); return lambda.Compile(); } diff --git a/Obsidian.SourceGenerators/Packets/MethodsRegistry.cs b/Obsidian.SourceGenerators/Packets/MethodsRegistry.cs index e1608b55b..5be823e22 100644 --- a/Obsidian.SourceGenerators/Packets/MethodsRegistry.cs +++ b/Obsidian.SourceGenerators/Packets/MethodsRegistry.cs @@ -7,8 +7,8 @@ internal sealed class MethodsRegistry public IReadOnlyList WriteMethods => writeMethods; public IReadOnlyList ReadMethods => readMethods; - private readonly List writeMethods = new(); - private readonly List readMethods = new(); + private readonly List writeMethods = []; + private readonly List readMethods = []; public bool TryGetWriteMethod(Property property, out Method method) { diff --git a/Obsidian.SourceGenerators/Packets/SerializationMethodsGenerator.cs b/Obsidian.SourceGenerators/Packets/SerializationMethodsGenerator.cs index 87e5de0f8..0c3527bfd 100644 --- a/Obsidian.SourceGenerators/Packets/SerializationMethodsGenerator.cs +++ b/Obsidian.SourceGenerators/Packets/SerializationMethodsGenerator.cs @@ -15,10 +15,10 @@ public void Initialize(GeneratorInitializationContext context) varInt = new Property { Type = "int", - Attributes = new AttributeBehaviorBase[] - { + Attributes = + [ new VarLengthBehavior(null) - }, + ], Flags = AttributeFlags.Field | AttributeFlags.VarLength }; } diff --git a/Obsidian.SourceGenerators/Registry/Models/Assets.cs b/Obsidian.SourceGenerators/Registry/Models/Assets.cs index 49df728c1..c3c673724 100644 --- a/Obsidian.SourceGenerators/Registry/Models/Assets.cs +++ b/Obsidian.SourceGenerators/Registry/Models/Assets.cs @@ -45,7 +45,7 @@ public static Dictionary GetCodecs(ImmutableArray<(string name, private static Codec[] ParseCodec(string json) { if (json is null) - return Array.Empty(); + return []; using var document = JsonDocument.Parse(json); @@ -77,7 +77,7 @@ private static Codec[] ParseCodec(string json) public static Fluid[] GetFluids(string? json) { if (json is null) - return Array.Empty(); + return []; var fluids = new List(); using var document = JsonDocument.Parse(json); @@ -97,7 +97,7 @@ public static Fluid[] GetFluids(string? json) public static Block[] GetBlocks(string? json) { if (json is null) - return Array.Empty(); + return []; var blocks = new List(); using var document = JsonDocument.Parse(json); @@ -129,7 +129,7 @@ public static Block[] GetBlocks(string? json) private static Item[] GetItems(string? json) { if (json is null) - return Array.Empty(); + return []; var items = new List(); using var document = JsonDocument.Parse(json); @@ -145,7 +145,7 @@ private static Item[] GetItems(string? json) public static Tag[] GetTags(string? json, Block[] blocks, Fluid[] fluids) { if (json is null) - return Array.Empty(); + return []; var taggables = new Dictionary(); foreach (Block block in blocks) diff --git a/Obsidian.SourceGenerators/Registry/Models/BlockProperty.cs b/Obsidian.SourceGenerators/Registry/Models/BlockProperty.cs index 879fb800b..7a5124b13 100644 --- a/Obsidian.SourceGenerators/Registry/Models/BlockProperty.cs +++ b/Obsidian.SourceGenerators/Registry/Models/BlockProperty.cs @@ -15,7 +15,7 @@ internal class BlockProperty private const string BooleanName = "bool"; private const string IntegerName = "int"; - internal static Dictionary enumValuesCache = new(); + internal static Dictionary enumValuesCache = []; private BlockProperty(string name, string tag, string type, string[] values, int? customOffset = null, bool isBooleanToggled = true) { diff --git a/Obsidian.SourceGenerators/Registry/Models/Codec.cs b/Obsidian.SourceGenerators/Registry/Models/Codec.cs index 46bbed0da..806171836 100644 --- a/Obsidian.SourceGenerators/Registry/Models/Codec.cs +++ b/Obsidian.SourceGenerators/Registry/Models/Codec.cs @@ -7,7 +7,7 @@ internal sealed class Codec : IHasName, IRegistryItem public int RegistryId { get; } - public Dictionary Properties { get; set; } = new(); + public Dictionary Properties { get; set; } = []; public Codec(string name, int registryId) { diff --git a/Obsidian.SourceGenerators/Registry/Models/Customizations.cs b/Obsidian.SourceGenerators/Registry/Models/Customizations.cs index 59b041962..0f9e3dcd0 100644 --- a/Obsidian.SourceGenerators/Registry/Models/Customizations.cs +++ b/Obsidian.SourceGenerators/Registry/Models/Customizations.cs @@ -7,7 +7,7 @@ internal static class Customizations static Customizations() { - BannedNames = new(); + BannedNames = []; foreach (Type type in typeof(int).Assembly.GetTypes()) { BannedNames.Add(type.Name); diff --git a/Obsidian.SourceGenerators/Registry/Models/Tag.cs b/Obsidian.SourceGenerators/Registry/Models/Tag.cs index aba46bf98..6c2dc9401 100644 --- a/Obsidian.SourceGenerators/Registry/Models/Tag.cs +++ b/Obsidian.SourceGenerators/Registry/Models/Tag.cs @@ -65,7 +65,7 @@ public static Tag Get(JsonProperty property, Dictionary tagga private static void UpdateMissedTags(string propertyName, string valueTag, Dictionary> missedTags) { if (!missedTags.ContainsKey(propertyName)) - missedTags.Add(propertyName, new() { valueTag }); + missedTags.Add(propertyName, [valueTag]); else missedTags[propertyName].Add(valueTag); } diff --git a/Obsidian.Tests/Boolean.cs b/Obsidian.Tests/Boolean.cs index a0dd25d82..80d666617 100644 --- a/Obsidian.Tests/Boolean.cs +++ b/Obsidian.Tests/Boolean.cs @@ -27,7 +27,7 @@ public async void SerializeAsync(bool input, byte @byte) [Theory(DisplayName = "Deserialization of booleans", Timeout = 100)] public async void DeserializeAsync(bool input, byte @byte) { - using var stream = new MinecraftStream(new[] { @byte }); + using var stream = new MinecraftStream([@byte]); bool boolean = await stream.ReadBooleanAsync(); diff --git a/Obsidian.Tests/Encryption.cs b/Obsidian.Tests/Encryption.cs index d5a2968bc..0ffd7bd43 100644 --- a/Obsidian.Tests/Encryption.cs +++ b/Obsidian.Tests/Encryption.cs @@ -42,7 +42,7 @@ public static IEnumerable RandomData { var randomData = new byte[testDataLength]; random.NextBytes(randomData); - values.Add(new object[] { randomData }); + values.Add([randomData]); } return values; diff --git a/Obsidian.Tests/Obsidian.Tests.csproj b/Obsidian.Tests/Obsidian.Tests.csproj index 23ad4d069..8b4d9b3d4 100644 --- a/Obsidian.Tests/Obsidian.Tests.csproj +++ b/Obsidian.Tests/Obsidian.Tests.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 true false diff --git a/Obsidian.Tests/String.cs b/Obsidian.Tests/String.cs index eceb70ab4..0d53f3d2b 100644 --- a/Obsidian.Tests/String.cs +++ b/Obsidian.Tests/String.cs @@ -39,7 +39,7 @@ public static IEnumerable StringData value += (char)random.Next(' ', '~'); } - values.Add(new object[] { value }); + values.Add([value]); } return values; diff --git a/Obsidian/BossBar.cs b/Obsidian/BossBar.cs index ee5499568..ede46ac04 100644 --- a/Obsidian/BossBar.cs +++ b/Obsidian/BossBar.cs @@ -10,7 +10,7 @@ public class BossBar : IBossBar private Server server; private BossBarRemoveAction removeAction; - public HashSet Players { get; } = new(); + public HashSet Players { get; } = []; public Guid Uuid { get; } = Guid.NewGuid(); diff --git a/Obsidian/Client.cs b/Obsidian/Client.cs index 1bbfccfd8..7708953d5 100644 --- a/Obsidian/Client.cs +++ b/Obsidian/Client.cs @@ -179,13 +179,13 @@ public Client(ConnectionContext connectionContext, ServerConfiguration config, i id = playerId; Server = originServer; - LoadedChunks = new(); + LoadedChunks = []; packetCryptography = new(); handler = new(config); networkStream = new(connectionContext.Transport); minecraftStream = new(networkStream); - missedKeepAlives = new List(); + missedKeepAlives = []; var linkOptions = new DataflowLinkOptions { PropagateCompletion = true }; var blockOptions = new ExecutionDataflowBlockOptions { CancellationToken = cancellationSource.Token, EnsureOrdered = true }; var sendPacketBlock = new ActionBlock(packet => @@ -644,7 +644,7 @@ internal void SendKeepAlive(DateTimeOffset time) internal Task RemovePlayerFromListAsync(IPlayer player) => QueuePacketAsync(new PlayerInfoRemovePacket { - UUIDs = new() { player.Uuid } + UUIDs = [player.Uuid] }); internal async Task AddPlayerToListAsync(IPlayer player) diff --git a/Obsidian/Commands/CommandNode.cs b/Obsidian/Commands/CommandNode.cs index a6a657e13..94e60cc8b 100644 --- a/Obsidian/Commands/CommandNode.cs +++ b/Obsidian/Commands/CommandNode.cs @@ -15,7 +15,7 @@ public class CommandNode public CommandNodeType Type { get; set; } - public HashSet Children = new(); + public HashSet Children = []; public async Task CopyToAsync(MinecraftStream stream) { diff --git a/Obsidian/Commands/Framework/CommandHandler.cs b/Obsidian/Commands/Framework/CommandHandler.cs index 0aa58311b..0f77b1cc6 100644 --- a/Obsidian/Commands/Framework/CommandHandler.cs +++ b/Obsidian/Commands/Framework/CommandHandler.cs @@ -20,8 +20,8 @@ public class CommandHandler public CommandHandler() { _commandParser = new CommandParser(DefaultPrefix); - _commands = new List(); - _argumentParsers = new List(); + _commands = []; + _argumentParsers = []; _prefix = DefaultPrefix; // Find all predefined argument parsers diff --git a/Obsidian/Entities/Player.cs b/Obsidian/Entities/Player.cs index c943d5932..dfa0a5713 100644 --- a/Obsidian/Entities/Player.cs +++ b/Obsidian/Entities/Player.cs @@ -32,7 +32,7 @@ public sealed partial class Player : Living, IPlayer /// protected ILogger Logger { get; private set; } - internal HashSet visiblePlayers = new(); + internal HashSet visiblePlayers = []; //TODO: better name?? internal short inventorySlot = 36; @@ -55,7 +55,7 @@ public sealed partial class Player : Living, IPlayer public BaseContainer? OpenedContainer { get; set; } - public List SkinProperties { get; set; } = new(); + public List SkinProperties { get; set; } = []; public Vector? LastDeathLocation { get; set; } @@ -954,7 +954,7 @@ internal async Task UpdateChunksAsync(bool unloadAll = false, int distance client.LoadedChunks.Clear(); } - List<(int X, int Z)> clientNeededChunks = new(); + List<(int X, int Z)> clientNeededChunks = []; List<(int X, int Z)> clientUnneededChunks = new(client.LoadedChunks); (int playerChunkX, int playerChunkZ) = Position.ToChunkCoord(); diff --git a/Obsidian/Events/AsyncEvent.T.cs b/Obsidian/Events/AsyncEvent.T.cs index 4c8e41fd9..28e153c80 100644 --- a/Obsidian/Events/AsyncEvent.T.cs +++ b/Obsidian/Events/AsyncEvent.T.cs @@ -9,7 +9,7 @@ public sealed class AsyncEvent : IEventRegistry public string? Name { get; } // Name must be set in order to be visible to plugins private readonly SemaphoreSlim semaphore = new(1); - private readonly List> hooks = new(); + private readonly List> hooks = []; private readonly Action, Exception>? exceptionHandler; public AsyncEvent() diff --git a/Obsidian/Net/MinecraftStream.Writing.cs b/Obsidian/Net/MinecraftStream.Writing.cs index d4342ef94..1377f8282 100644 --- a/Obsidian/Net/MinecraftStream.Writing.cs +++ b/Obsidian/Net/MinecraftStream.Writing.cs @@ -46,7 +46,7 @@ public async Task WriteUnsignedByteAsync(byte value) await Globals.PacketLogger.LogDebugAsync($"Writing unsigned Byte (0x{value.ToString("X")})"); #endif - await WriteAsync(new[] { value }); + await WriteAsync([value]); } [WriteMethod] diff --git a/Obsidian/Net/Rcon/RconPacket.cs b/Obsidian/Net/Rcon/RconPacket.cs index d544b2a1d..36cdec100 100644 --- a/Obsidian/Net/Rcon/RconPacket.cs +++ b/Obsidian/Net/Rcon/RconPacket.cs @@ -20,7 +20,7 @@ public RconPacket(Encoding? encoding = null) public int Length => 4 + 4 + PayloadBytes.Length + 1; // RequestId (Int32) + Type (Int32) + PayloadBytes (varies) + padding (1) public int RequestId { get; set; } public RconPacketType Type { get; set; } - public byte[] PayloadBytes { get; set; } = { 0x00 }; + public byte[] PayloadBytes { get; set; } = [0x00]; public string PayloadText { get => PayloadBytes.Length > 1 @@ -29,7 +29,7 @@ public string PayloadText set { if (string.IsNullOrEmpty(value)) - PayloadBytes = new byte[] { 0x00 }; + PayloadBytes = [0x00]; PayloadBytes = encoding.GetBytes(value).Append((byte)0x00).ToArray(); } } @@ -124,7 +124,7 @@ public async Task WriteAsync(Stream stream, CancellationToken ct) if (PayloadBytes.Length > 0) await stream.WriteAsync(PayloadBytes, ct); - buf = new byte[] { 0x00 }; + buf = [0x00]; await stream.WriteAsync(buf, ct); // Padding } } diff --git a/Obsidian/Obsidian.csproj b/Obsidian/Obsidian.csproj index 7586df675..e0b26b826 100644 --- a/Obsidian/Obsidian.csproj +++ b/Obsidian/Obsidian.csproj @@ -2,7 +2,7 @@ Library - net7.0 + net8.0 enable true diff --git a/Obsidian/Plugins/DirectoryWatcher.cs b/Obsidian/Plugins/DirectoryWatcher.cs index a6c6f7325..5148a835e 100644 --- a/Obsidian/Plugins/DirectoryWatcher.cs +++ b/Obsidian/Plugins/DirectoryWatcher.cs @@ -4,8 +4,8 @@ namespace Obsidian.Plugins; public sealed class DirectoryWatcher : IDisposable { - private string[] _filters = Array.Empty(); - public string[] Filters { get => _filters; set => _filters = value ?? Array.Empty(); } + private string[] _filters = []; + public string[] Filters { get => _filters; set => _filters = value ?? []; } public event Action FileChanged; public event Action FileRenamed; diff --git a/Obsidian/Plugins/PluginProviders/CompiledPluginProvider.cs b/Obsidian/Plugins/PluginProviders/CompiledPluginProvider.cs index e38408dc1..b0b346866 100644 --- a/Obsidian/Plugins/PluginProviders/CompiledPluginProvider.cs +++ b/Obsidian/Plugins/PluginProviders/CompiledPluginProvider.cs @@ -20,7 +20,7 @@ internal PluginContainer HandlePlugin(PluginLoadContext loadContext, Assembly as Type pluginType = assembly.GetTypes().FirstOrDefault(type => type.IsSubclassOf(typeof(PluginBase))); PluginBase plugin; - if (pluginType == null || pluginType.GetConstructor(Array.Empty()) == null) + if (pluginType == null || pluginType.GetConstructor([]) == null) { plugin = default; logger?.LogError("Loaded assembly contains no type implementing PluginBase with public parameterless constructor."); diff --git a/Obsidian/Registries/BlocksRegistry.Properties.cs b/Obsidian/Registries/BlocksRegistry.Properties.cs index 71904d687..214e508db 100644 --- a/Obsidian/Registries/BlocksRegistry.Properties.cs +++ b/Obsidian/Registries/BlocksRegistry.Properties.cs @@ -11,7 +11,7 @@ internal partial class BlocksRegistry private static readonly ConcurrentDictionary resourceIdToName = new(); - private static readonly Type[] stateIdParameters = new[] { typeof(int) }; + private static readonly Type[] stateIdParameters = [typeof(int)]; private static readonly ParameterExpression[] stateIdParameterExpressions = stateIdParameters.GetParamExpressions(); private static readonly Type blockType = typeof(IBlock); diff --git a/Obsidian/Server.cs b/Obsidian/Server.cs index 3828f83ed..d903849c2 100644 --- a/Obsidian/Server.cs +++ b/Obsidian/Server.cs @@ -151,7 +151,7 @@ public Server( var udpClient = new UdpClient("224.0.2.60", 4445); var timer = new PeriodicTimer(TimeSpan.FromSeconds(1.5)); string? lastMotd = null; - byte[] bytes = Array.Empty(); // Cached motd as utf-8 bytes + byte[] bytes = []; // Cached motd as utf-8 bytes while (await timer.WaitForNextTickAsync(_cancelTokenSource.Token)) { if (Config.Motd != lastMotd) @@ -277,7 +277,7 @@ public async Task RunAsync() Directory.CreateDirectory(Path.Join(ServerFolderPath, "plugins")); - PluginManager.DirectoryWatcher.Filters = new[] { ".cs", ".dll" }; + PluginManager.DirectoryWatcher.Filters = [".cs", ".dll"]; PluginManager.DirectoryWatcher.Watch(Path.Join(ServerFolderPath, "plugins")); await Task.WhenAll(Config.DownloadPlugins.Select(path => PluginManager.LoadPluginAsync(path))); diff --git a/Obsidian/Utilities/Collections/DataArray.cs b/Obsidian/Utilities/Collections/DataArray.cs index 635386c59..0bc80dbf0 100644 --- a/Obsidian/Utilities/Collections/DataArray.cs +++ b/Obsidian/Utilities/Collections/DataArray.cs @@ -11,8 +11,8 @@ internal sealed class DataArray // Multiplier and shifter should be selected with index [bitsPerEntry] // This trick may yield incorrect results when "dividing" numbers out of range 0..4096, // but DataArray shouldn't be used for that many elements - private static ReadOnlySpan Multipliers => new[] { 0, 1, 1, 3121, 1, 2731, 3277, 3641, 1, 2341, 2731, 3277, 3277, 1, 1, 1, 1, 2731, 2731, 2731, 2731, 2731, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; - private static ReadOnlySpan Shifts => new[] { 0, 6, 5, 16, 4, 15, 15, 15, 3, 14, 14, 14, 14, 2, 2, 2, 2, 13, 13, 13, 13, 13, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + private static ReadOnlySpan Multipliers => [0, 1, 1, 3121, 1, 2731, 3277, 3641, 1, 2341, 2731, 3277, 3277, 1, 1, 1, 1, 2731, 2731, 2731, 2731, 2731, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; + private static ReadOnlySpan Shifts => [0, 6, 5, 16, 4, 15, 15, 15, 3, 14, 14, 14, 14, 2, 2, 2, 2, 13, 13, 13, 13, 13, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; public int BitsPerEntry => bitsPerEntry; public int Length => entriesCount; diff --git a/Obsidian/Utilities/Config.cs b/Obsidian/Utilities/Config.cs index 57e310f8b..61a1130af 100644 --- a/Obsidian/Utilities/Config.cs +++ b/Obsidian/Utilities/Config.cs @@ -44,7 +44,7 @@ public class ServerConfiguration : IServerConfiguration public long ConnectionThrottle { get; set; } = 15_000; - public string[] DownloadPlugins { get; set; } = Array.Empty(); + public string[] DownloadPlugins { get; set; } = []; public RconConfig? Rcon { get; set; } public bool UDPBroadcast = false; diff --git a/Obsidian/Utilities/Extensions.cs b/Obsidian/Utilities/Extensions.cs index 2595253a0..62de36a08 100644 --- a/Obsidian/Utilities/Extensions.cs +++ b/Obsidian/Utilities/Extensions.cs @@ -18,7 +18,7 @@ namespace Obsidian.Utilities; public static partial class Extensions { - internal readonly static EntityType[] nonLiving = new[] { EntityType.Arrow, + internal readonly static EntityType[] nonLiving = [ EntityType.Arrow, EntityType.SpectralArrow, EntityType.Boat, EntityType.DragonFireball, @@ -52,7 +52,7 @@ public static partial class Extensions EntityType.Potion, EntityType.Trident, EntityType.FishingBobber, - EntityType.EyeOfEnder}; + EntityType.EyeOfEnder]; public static void WritePacketId(this IPacket packet, MinecraftStream stream) diff --git a/Obsidian/Utilities/GuidHelper.cs b/Obsidian/Utilities/GuidHelper.cs index 3a448348c..212f8c541 100644 --- a/Obsidian/Utilities/GuidHelper.cs +++ b/Obsidian/Utilities/GuidHelper.cs @@ -30,8 +30,9 @@ public static Guid FromLongs(long mostSig, long leastSig) var mostSigBytes = BitConverter.GetBytes(mostSig); var leastSigBytes = BitConverter.GetBytes(leastSig); - Span guidBytes = stackalloc byte[16]//Is there a better way?? - { + Span guidBytes = + //Is there a better way?? + [ mostSigBytes[4], mostSigBytes[5], mostSigBytes[6], @@ -48,7 +49,7 @@ public static Guid FromLongs(long mostSig, long leastSig) leastSigBytes[2], leastSigBytes[1], leastSigBytes[0] - }; + ]; return new Guid(guidBytes); } diff --git a/Obsidian/Utilities/ServerStatus.cs b/Obsidian/Utilities/ServerStatus.cs index 8df08fce9..831589c3a 100644 --- a/Obsidian/Utilities/ServerStatus.cs +++ b/Obsidian/Utilities/ServerStatus.cs @@ -10,7 +10,7 @@ namespace Obsidian.Utilities; public class ServerStatus : IServerStatus { private readonly ILogger _logger; - private static ReadOnlySpan PngHeader => new byte[] { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A }; + private static ReadOnlySpan PngHeader => [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]; private const string b64obsidian = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAOAklEQVR42q2baXMbNxKG+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sgAD4s+FkDRsCaQeBf1zNrnMWCq1WV7olvvramCw5hvTwOdwWPLAJ2owAoMeK9nioCwFcrbkch0HkDzgodA+DXMWzjHEAHANz9efg2FWojp76rQOivTkIw3/GpvWgIAZjPylEAoOcA8HuezMP6ZWevBLGRyxMQut4+UT4PAP+GmukhEQQgip06YqvLS60QBLhW74d/EwQAW2joeTB/BoAli5BuWP1tVRJ5DoCx7w6T8FTY3AaDhhZFp8WXtgAGTpNIrnn38+BZJPSw+xwATQDA6tkATglyAkLI1ecY413gam7Nbn6HnmeX6s33GYwHGL4eAFNgDA8DfOBmMN/p5Pn/gmAva/lXYpvAveTVswEYCDS70eHo9lwAtVPSjgFY/Q/GV88AUDtffggDIAhYTjNDgBI66L9GX8+fJ1ZTswAAAABJRU5ErkJggg=="; public IServerVersion Version { get; set; } diff --git a/Obsidian/WorldData/Decorators/DecoratorFactory.cs b/Obsidian/WorldData/Decorators/DecoratorFactory.cs index 6f000e736..b527fbe46 100644 --- a/Obsidian/WorldData/Decorators/DecoratorFactory.cs +++ b/Obsidian/WorldData/Decorators/DecoratorFactory.cs @@ -5,7 +5,7 @@ namespace Obsidian.WorldData.Decorators; public static class DecoratorFactory { - private static readonly Type[] argumentCache = new[] { typeof(Biome), typeof(Chunk), typeof(Vector), typeof(GenHelper) }; + private static readonly Type[] argumentCache = [typeof(Biome), typeof(Chunk), typeof(Vector), typeof(GenHelper)]; public static readonly ParameterExpression[] expressionParameters = argumentCache.Select((t, i) => Expression.Parameter(t, $"param{i}")).ToArray(); private static readonly ConcurrentDictionary> decoratorFactory = new(); diff --git a/Obsidian/WorldData/Decorators/OverworldDecorator.cs b/Obsidian/WorldData/Decorators/OverworldDecorator.cs index 2880c8435..7060404a5 100644 --- a/Obsidian/WorldData/Decorators/OverworldDecorator.cs +++ b/Obsidian/WorldData/Decorators/OverworldDecorator.cs @@ -12,7 +12,7 @@ public static class OverworldDecorator private static readonly ConcurrentDictionary> floraCache = new(); private static readonly ConcurrentDictionary> treeCache = new(); - private static readonly Type[] argumentCache = new[] { typeof(GenHelper), typeof(Chunk) }; + private static readonly Type[] argumentCache = [typeof(GenHelper), typeof(Chunk)]; public static readonly ParameterExpression[] expressionParameters = argumentCache.Select((t, i) => Expression.Parameter(t, $"param{i}")).ToArray(); static OverworldDecorator() diff --git a/Obsidian/WorldData/Generators/IslandGenerator.cs b/Obsidian/WorldData/Generators/IslandGenerator.cs index a58fff3e9..3e22141de 100644 --- a/Obsidian/WorldData/Generators/IslandGenerator.cs +++ b/Obsidian/WorldData/Generators/IslandGenerator.cs @@ -10,7 +10,7 @@ public sealed class IslandGenerator : IWorldGenerator private GenHelper? helper; private Module? noiseGenerator; private Random? r; - private static readonly Biome[] biomes = new Biome[22] { + private static readonly Biome[] biomes = [ Biome.Badlands, Biome.BambooJungle, Biome.BirchForest, @@ -33,14 +33,14 @@ public sealed class IslandGenerator : IWorldGenerator Biome.SunflowerPlains, Biome.Taiga, Biome.WoodedBadlands - }; - private static readonly IBlock[] hangingBlocks = new IBlock[4] - { + ]; + private static readonly IBlock[] hangingBlocks = + [ BlocksRegistry.Stone, BlocksRegistry.Cobblestone, BlocksRegistry.MossyCobblestone, BlocksRegistry.Andesite - }; + ]; public async Task GenerateChunkAsync(int cx, int cz, Chunk? chunk = null, ChunkStatus minlevel = ChunkStatus.full) { diff --git a/Obsidian/WorldData/Generators/Overworld/ChunkBuilder.cs b/Obsidian/WorldData/Generators/Overworld/ChunkBuilder.cs index 9a84602ba..a16e633c9 100644 --- a/Obsidian/WorldData/Generators/Overworld/ChunkBuilder.cs +++ b/Obsidian/WorldData/Generators/Overworld/ChunkBuilder.cs @@ -10,28 +10,28 @@ internal static class ChunkBuilder private const float OreSize = 0.4F; private const float StoneAltSize = 1F; - private static readonly IBlock[] stoneAlts = new IBlock[6] - { + private static readonly IBlock[] stoneAlts = + [ BlocksRegistry.Andesite, BlocksRegistry.Diorite, BlocksRegistry.Granite, BlocksRegistry.Gravel, BlocksRegistry.Dirt, BlocksRegistry.Tuff - }; + ]; - private static readonly IBlock[] deepstoneAlts = new IBlock[6] - { + private static readonly IBlock[] deepstoneAlts = + [ BlocksRegistry.Gravel, BlocksRegistry.Tuff, BlocksRegistry.Gravel, BlocksRegistry.Tuff, BlocksRegistry.Gravel, BlocksRegistry.Tuff - }; + ]; - private static readonly IBlock[] ores = new IBlock[8] - { + private static readonly IBlock[] ores = + [ BlocksRegistry.CoalOre, BlocksRegistry.IronOre, BlocksRegistry.CopperOre, @@ -40,10 +40,10 @@ internal static class ChunkBuilder BlocksRegistry.RedstoneOre, BlocksRegistry.EmeraldOre, BlocksRegistry.DiamondOre, - }; + ]; - private static readonly IBlock[] deepores = new IBlock[8] - { + private static readonly IBlock[] deepores = + [ BlocksRegistry.DeepslateCoalOre, BlocksRegistry.DeepslateIronOre, BlocksRegistry.DeepslateCopperOre, @@ -52,7 +52,7 @@ internal static class ChunkBuilder BlocksRegistry.DeepslateRedstoneOre, BlocksRegistry.DeepslateEmeraldOre, BlocksRegistry.DeepslateDiamondOre, - }; + ]; internal enum OreType : int { diff --git a/Obsidian/WorldData/Region.cs b/Obsidian/WorldData/Region.cs index 748831ff0..db721cc3f 100644 --- a/Obsidian/WorldData/Region.cs +++ b/Obsidian/WorldData/Region.cs @@ -140,8 +140,8 @@ internal async Task BeginTickAsync(CancellationToken cts) { await Task.WhenAll(Entities.Select(entityEntry => entityEntry.Value.TickAsync())); - List neighborUpdates = new(); - List delayed = new(); + List neighborUpdates = []; + List delayed = []; foreach (var pos in blockUpdates.Keys) { @@ -315,7 +315,8 @@ private static NbtCompound SerializeChunk(Chunk chunk) foreach (var (_, blockEntity) in chunk.BlockEntities) blockEntities.Add(blockEntity); - return new NbtCompound +#pragma warning disable IDE0028 // Use collection initializers - Will not compile with this suggestion applied + return new NbtCompound { new NbtTag("xPos", chunk.X), new NbtTag("zPos", chunk.Z), @@ -331,7 +332,8 @@ private static NbtCompound SerializeChunk(Chunk chunk) sectionsCompound, new NbtTag("DataVersion", 3337)// Hardcoded version try to get data version through minecraft data and use data correctly }; - } +#pragma warning restore IDE0028 // Use collection initializers + } #endregion NBT Ops public async ValueTask DisposeAsync() => await regionFile.DisposeAsync(); diff --git a/Obsidian/WorldData/RegionFile.cs b/Obsidian/WorldData/RegionFile.cs index 750108802..81fe2aa3e 100644 --- a/Obsidian/WorldData/RegionFile.cs +++ b/Obsidian/WorldData/RegionFile.cs @@ -29,7 +29,7 @@ public sealed class RegionFile : IAsyncDisposable private bool disposed; private bool initialized; - private bool[] freeSectors = Array.Empty(); + private bool[] freeSectors = []; public int[] Locations { get; private set; } = new int[HeaderTableSize]; public int[] Timestamps { get; private set; } = new int[HeaderTableSize]; diff --git a/SamplePlugin/SamplePlugin.csproj b/SamplePlugin/SamplePlugin.csproj index bfc1ccdaf..c2d031338 100644 --- a/SamplePlugin/SamplePlugin.csproj +++ b/SamplePlugin/SamplePlugin.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 false false Library