From 654a16907bec7ab9a7902fbbf9257f0136a429a7 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Tue, 24 Mar 2026 01:31:17 +0000
Subject: [PATCH] Modernize data carriers to records and add primary
constructors
Convert 14 data carrier classes to records:
- VillagerInfo, MapIcon, EnchantmentData: non-positional records (mutable properties)
- ForgeMod, SkinInfo, VillagerTrade, Node, Response: positional records
- CommandNode: sealed positional record
- CommandArgumentDescriptor: readonly record struct
- ColorRGBA: record struct (multiple constructors preserved)
- RecipeConfig, Recipe, BannerLayer: non-positional records
Add primary constructors to 6 classes:
- DataTypes, Protocol18Terrain, Protocol18Forge, ItemMovingHelper,
LastSeenMessageList, Acknowledgment, SuggestionTooltip
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
MinecraftClient/ChatBots/AutoCraft.cs | 4 +-
MinecraftClient/ColorHelper.cs | 2 +-
.../CommandHandler/SuggestionTooltip.cs | 9 +--
MinecraftClient/Inventory/EnchantmentData.cs | 2 +-
MinecraftClient/Inventory/ItemMovingHelper.cs | 20 +------
MinecraftClient/Inventory/VillagerInfo.cs | 2 +-
MinecraftClient/Inventory/VillagerTrade.cs | 38 ++++---------
MinecraftClient/Mapping/MapIcon.cs | 12 ++--
MinecraftClient/Mapping/Movement.cs | 22 +-------
.../Protocol/Handlers/DataTypes.cs | 13 +----
.../Protocol/Handlers/Forge/ForgeInfo.cs | 11 +---
.../Handlers/Packet/s2c/DeclareCommands.cs | 55 +++++--------------
.../Protocol/Handlers/Protocol18Forge.cs | 27 ++-------
.../Protocol/Handlers/Protocol18Terrain.cs | 20 ++-----
.../1_20_6/BannerPatternsComponent.cs | 2 +-
.../Protocol/Message/LastSeenMessageList.cs | 21 ++-----
MinecraftClient/Protocol/MojangAPI.cs | 24 ++------
MinecraftClient/Protocol/ProxiedWebRequest.cs | 15 +----
18 files changed, 68 insertions(+), 231 deletions(-)
diff --git a/MinecraftClient/ChatBots/AutoCraft.cs b/MinecraftClient/ChatBots/AutoCraft.cs
index bc8bf957..e0156941 100644
--- a/MinecraftClient/ChatBots/AutoCraft.cs
+++ b/MinecraftClient/ChatBots/AutoCraft.cs
@@ -123,7 +123,7 @@ namespace MinecraftClient.ChatBots
public enum OnFailConfig { abort, wait }
- public class RecipeConfig
+ public record RecipeConfig
{
public string Name = "Recipe Name";
@@ -241,7 +241,7 @@ namespace MinecraftClient.ChatBots
///
/// Represent a crafting recipe
///
- private class Recipe
+ private record Recipe
{
///
/// The results item of this recipe
diff --git a/MinecraftClient/ColorHelper.cs b/MinecraftClient/ColorHelper.cs
index fe91a780..54559d58 100644
--- a/MinecraftClient/ColorHelper.cs
+++ b/MinecraftClient/ColorHelper.cs
@@ -163,7 +163,7 @@ namespace MinecraftClient
}
}
- public class ColorRGBA
+ public record struct ColorRGBA
{
public byte R { get; set; }
public byte G { get; set; }
diff --git a/MinecraftClient/CommandHandler/SuggestionTooltip.cs b/MinecraftClient/CommandHandler/SuggestionTooltip.cs
index c235f061..330c63ed 100644
--- a/MinecraftClient/CommandHandler/SuggestionTooltip.cs
+++ b/MinecraftClient/CommandHandler/SuggestionTooltip.cs
@@ -2,13 +2,8 @@
namespace MinecraftClient.CommandHandler
{
- internal class SuggestionTooltip : IMessage
+ internal class SuggestionTooltip(string tooltip) : IMessage
{
- public SuggestionTooltip(string tooltip)
- {
- String = tooltip;
- }
-
- public string String { get; set; }
+ public string String { get; set; } = tooltip;
}
}
diff --git a/MinecraftClient/Inventory/EnchantmentData.cs b/MinecraftClient/Inventory/EnchantmentData.cs
index 427fe012..55571d0c 100644
--- a/MinecraftClient/Inventory/EnchantmentData.cs
+++ b/MinecraftClient/Inventory/EnchantmentData.cs
@@ -1,6 +1,6 @@
namespace MinecraftClient.Inventory
{
- public class EnchantmentData
+ public record EnchantmentData
{
public Enchantments TopEnchantment { get; set; }
public Enchantments MiddleEnchantment { get; set; }
diff --git a/MinecraftClient/Inventory/ItemMovingHelper.cs b/MinecraftClient/Inventory/ItemMovingHelper.cs
index 48623ee0..16d7d4de 100644
--- a/MinecraftClient/Inventory/ItemMovingHelper.cs
+++ b/MinecraftClient/Inventory/ItemMovingHelper.cs
@@ -7,24 +7,10 @@ namespace MinecraftClient.Inventory
///
/// Class that contains useful methods to move item around in a container
///
- public class ItemMovingHelper
+ public class ItemMovingHelper(Container c, McClient mc)
{
- private readonly Container c;
- private readonly McClient mc;
-
- ///
- /// Create a helper that contains useful methods to move item around in container
- ///
- /// Source container to use. All method will use this container for handling first slot parameter
- /// McClient handler. Needed for sending WindowAction packet to the server
- ///
- /// If you are using ChatBot API and cannot have direct access to McClient handler, use as second parameter
- ///
- public ItemMovingHelper(Container c, McClient mc)
- {
- this.c = c;
- this.mc = mc;
- }
+ private readonly Container c = c;
+ private readonly McClient mc = mc;
///
/// Move an item fron source to dest. Source should contain an item and dest slot should be empty
diff --git a/MinecraftClient/Inventory/VillagerInfo.cs b/MinecraftClient/Inventory/VillagerInfo.cs
index c93781e8..426cd112 100644
--- a/MinecraftClient/Inventory/VillagerInfo.cs
+++ b/MinecraftClient/Inventory/VillagerInfo.cs
@@ -3,7 +3,7 @@
///
/// Properties of a villager
///
- public class VillagerInfo
+ public record VillagerInfo
{
public int Level { get; set; }
public int Experience { get; set; }
diff --git a/MinecraftClient/Inventory/VillagerTrade.cs b/MinecraftClient/Inventory/VillagerTrade.cs
index 70246cab..46cd13e9 100644
--- a/MinecraftClient/Inventory/VillagerTrade.cs
+++ b/MinecraftClient/Inventory/VillagerTrade.cs
@@ -3,31 +3,15 @@
///
/// Represents a trade of a villager
///
- public class VillagerTrade
- {
- public Item InputItem1;
- public Item OutputItem;
- public Item? InputItem2;
- public bool TradeDisabled;
- public int NumberOfTradeUses;
- public int MaximumNumberOfTradeUses;
- public int Xp;
- public int SpecialPrice;
- public float PriceMultiplier;
- public int Demand;
-
- public VillagerTrade(Item inputItem1, Item outputItem, Item? inputItem2, bool tradeDisabled, int numberOfTradeUses, int maximumNumberOfTradeUses, int xp, int specialPrice, float priceMultiplier, int demand)
- {
- InputItem1 = inputItem1;
- OutputItem = outputItem;
- InputItem2 = inputItem2;
- TradeDisabled = tradeDisabled;
- NumberOfTradeUses = numberOfTradeUses;
- MaximumNumberOfTradeUses = maximumNumberOfTradeUses;
- Xp = xp;
- SpecialPrice = specialPrice;
- PriceMultiplier = priceMultiplier;
- Demand = demand;
- }
- }
+ public record VillagerTrade(
+ Item InputItem1,
+ Item OutputItem,
+ Item? InputItem2,
+ bool TradeDisabled,
+ int NumberOfTradeUses,
+ int MaximumNumberOfTradeUses,
+ int Xp,
+ int SpecialPrice,
+ float PriceMultiplier,
+ int Demand);
}
diff --git a/MinecraftClient/Mapping/MapIcon.cs b/MinecraftClient/Mapping/MapIcon.cs
index 3862b8db..e525f1a9 100644
--- a/MinecraftClient/Mapping/MapIcon.cs
+++ b/MinecraftClient/Mapping/MapIcon.cs
@@ -1,11 +1,11 @@
namespace MinecraftClient.Mapping
{
- public class MapIcon
+ public record MapIcon
{
- public MapIconType Type { set; get; }
- public byte X { set; get; }
- public byte Z { set; get; }
- public byte Direction { set; get; }
- public string? DisplayName { set; get; } = null;
+ public MapIconType Type { get; set; }
+ public byte X { get; set; }
+ public byte Z { get; set; }
+ public byte Direction { get; set; }
+ public string? DisplayName { get; set; } = null;
}
}
diff --git a/MinecraftClient/Mapping/Movement.cs b/MinecraftClient/Mapping/Movement.cs
index 06009966..6786dbee 100644
--- a/MinecraftClient/Mapping/Movement.cs
+++ b/MinecraftClient/Mapping/Movement.cs
@@ -306,27 +306,9 @@ namespace MinecraftClient.Mapping
///
/// Represents a location and its attributes
///
- public class Node
+ public record Node(int GScore, int HScore, Location Location)
{
- // Distance to start
- public int GScore;
-
- // Distance to Goal
- public int HScore;
-
- public int FScore
- {
- get { return HScore + GScore; }
- }
-
- public Location Location;
-
- public Node(int gScore, int hScore, Location loc)
- {
- this.GScore = gScore;
- this.HScore = hScore;
- Location = loc;
- }
+ public int FScore => HScore + GScore;
}
// List which contains all nodes in form of a Binary Heap
diff --git a/MinecraftClient/Protocol/Handlers/DataTypes.cs b/MinecraftClient/Protocol/Handlers/DataTypes.cs
index 82e17ae1..2f4c59ea 100644
--- a/MinecraftClient/Protocol/Handlers/DataTypes.cs
+++ b/MinecraftClient/Protocol/Handlers/DataTypes.cs
@@ -15,21 +15,12 @@ namespace MinecraftClient.Protocol.Handlers
///
/// Handle data types encoding / decoding
///
- public class DataTypes
+ public class DataTypes(int protocol)
{
///
/// Protocol version for adjusting data types
///
- private readonly int protocolversion;
-
- ///
- /// Initialize a new DataTypes instance
- ///
- /// Protocol version
- public DataTypes(int protocol)
- {
- protocolversion = protocol;
- }
+ private readonly int protocolversion = protocol;
///
/// Protocol version used to adjust wire encodings.
diff --git a/MinecraftClient/Protocol/Handlers/Forge/ForgeInfo.cs b/MinecraftClient/Protocol/Handlers/Forge/ForgeInfo.cs
index bbe2110e..7baca1ba 100755
--- a/MinecraftClient/Protocol/Handlers/Forge/ForgeInfo.cs
+++ b/MinecraftClient/Protocol/Handlers/Forge/ForgeInfo.cs
@@ -11,17 +11,8 @@ namespace MinecraftClient.Protocol.Handlers.Forge
///
/// Represents an individual forge mod.
///
- public class ForgeMod
+ public record ForgeMod(string ModID, string Version)
{
- public ForgeMod(String ModID, String Version)
- {
- this.ModID = ModID;
- this.Version = Version;
- }
-
- public readonly String ModID;
- public readonly String Version;
-
public override string ToString()
{
return ModID + " v" + Version;
diff --git a/MinecraftClient/Protocol/Handlers/Packet/s2c/DeclareCommands.cs b/MinecraftClient/Protocol/Handlers/Packet/s2c/DeclareCommands.cs
index b4e58cc2..57f1bb92 100644
--- a/MinecraftClient/Protocol/Handlers/Packet/s2c/DeclareCommands.cs
+++ b/MinecraftClient/Protocol/Handlers/Packet/s2c/DeclareCommands.cs
@@ -729,54 +729,25 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c
ForgeEnum
}
- private sealed class CommandNode
+ private sealed record CommandNode(
+ byte Flags,
+ int[] Children,
+ int RedirectNode = -1,
+ string? Name = null,
+ CommandArgumentDescriptor? Argument = null,
+ string? SuggestionsType = null,
+ int ParserId = -1)
{
- public byte Flags { get; }
- public int[] Children { get; }
- public int RedirectNode { get; }
- public string? Name { get; }
- public CommandArgumentDescriptor? Argument { get; }
- public string? SuggestionsType { get; }
- public int ParserId { get; }
-
public CommandNodeKind Kind => (CommandNodeKind)(Flags & NodeTypeMask);
public bool IsExecutable => (Flags & NodeExecutableFlag) != 0;
public bool IsRestricted => (Flags & NodeRestrictedFlag) != 0;
-
- public CommandNode(
- byte flags,
- int[] children,
- int redirectNode = -1,
- string? name = null,
- CommandArgumentDescriptor? argument = null,
- string? suggestionsType = null,
- int parserId = -1)
- {
- Flags = flags;
- Children = children;
- RedirectNode = redirectNode;
- Name = name;
- Argument = argument;
- SuggestionsType = suggestionsType;
- ParserId = parserId;
- }
}
- private readonly struct CommandArgumentDescriptor
- {
- public string Name { get; }
- public ArgumentConsumption Consumption { get; }
- public int TokenCount { get; }
- public bool IsSigned { get; }
-
- public CommandArgumentDescriptor(string name, ArgumentConsumption consumption, int tokenCount = 1, bool isSigned = false)
- {
- Name = name;
- Consumption = consumption;
- TokenCount = tokenCount;
- IsSigned = isSigned;
- }
- }
+ private readonly record struct CommandArgumentDescriptor(
+ string Name,
+ ArgumentConsumption Consumption,
+ int TokenCount = 1,
+ bool IsSigned = false);
private readonly struct ArgumentTypeLayout
{
diff --git a/MinecraftClient/Protocol/Handlers/Protocol18Forge.cs b/MinecraftClient/Protocol/Handlers/Protocol18Forge.cs
index 3dbe753e..7359d200 100644
--- a/MinecraftClient/Protocol/Handlers/Protocol18Forge.cs
+++ b/MinecraftClient/Protocol/Handlers/Protocol18Forge.cs
@@ -12,32 +12,17 @@ namespace MinecraftClient.Protocol.Handlers
///
/// Handler for the Minecraft Forge protocol
///
- class Protocol18Forge
+ class Protocol18Forge(ForgeInfo? forgeInfo, int protocolVersion, DataTypes dataTypes, Protocol18Handler protocol18, IMinecraftComHandler mcHandler)
{
- private readonly int protocolversion;
- private readonly DataTypes dataTypes;
- private readonly Protocol18Handler protocol18;
- private readonly IMinecraftComHandler mcHandler;
+ private readonly int protocolversion = protocolVersion;
+ private readonly DataTypes dataTypes = dataTypes;
+ private readonly Protocol18Handler protocol18 = protocol18;
+ private readonly IMinecraftComHandler mcHandler = mcHandler;
- private readonly ForgeInfo? forgeInfo;
+ private readonly ForgeInfo? forgeInfo = forgeInfo;
private FMLHandshakeClientState fmlHandshakeState = FMLHandshakeClientState.START;
private bool ForgeEnabled() { return forgeInfo is not null; }
- ///
- /// Initialize a new Forge protocol handler
- ///
- /// Forge Server Information
- /// Minecraft protocol version
- /// Minecraft data types handler
- public Protocol18Forge(ForgeInfo? forgeInfo, int protocolVersion, DataTypes dataTypes, Protocol18Handler protocol18, IMinecraftComHandler mcHandler)
- {
- this.forgeInfo = forgeInfo;
- protocolversion = protocolVersion;
- this.dataTypes = dataTypes;
- this.protocol18 = protocol18;
- this.mcHandler = mcHandler;
- }
-
///
/// Get Forge-Tagged server address
///
diff --git a/MinecraftClient/Protocol/Handlers/Protocol18Terrain.cs b/MinecraftClient/Protocol/Handlers/Protocol18Terrain.cs
index 33ea43af..9bd29e87 100644
--- a/MinecraftClient/Protocol/Handlers/Protocol18Terrain.cs
+++ b/MinecraftClient/Protocol/Handlers/Protocol18Terrain.cs
@@ -12,23 +12,11 @@ namespace MinecraftClient.Protocol.Handlers
///
/// Terrain Decoding handler for Protocol18
///
- class Protocol18Terrain
+ class Protocol18Terrain(int protocolVersion, DataTypes dataTypes, IMinecraftComHandler handler)
{
- private readonly int protocolversion;
- private readonly DataTypes dataTypes;
- private readonly IMinecraftComHandler handler;
-
- ///
- /// Initialize a new Terrain Decoder
- ///
- /// Minecraft Protocol Version
- /// Minecraft Protocol Data Types
- public Protocol18Terrain(int protocolVersion, DataTypes dataTypes, IMinecraftComHandler handler)
- {
- protocolversion = protocolVersion;
- this.dataTypes = dataTypes;
- this.handler = handler;
- }
+ private readonly int protocolversion = protocolVersion;
+ private readonly DataTypes dataTypes = dataTypes;
+ private readonly IMinecraftComHandler handler = handler;
///
/// Reading the "Block states" field: consists of 4096 entries, representing all the blocks in the chunk section.
diff --git a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/BannerPatternsComponent.cs b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/BannerPatternsComponent.cs
index 6a69bc79..497dd330 100644
--- a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/BannerPatternsComponent.cs
+++ b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/BannerPatternsComponent.cs
@@ -59,7 +59,7 @@ public class BannerPatternsComponent(DataTypes dataTypes, ItemPalette itemPalett
}
}
-public class BannerLayer
+public record BannerLayer
{
public int PatternType { get; set; }
public string? AssetId { get; set; } = null!;
diff --git a/MinecraftClient/Protocol/Message/LastSeenMessageList.cs b/MinecraftClient/Protocol/Message/LastSeenMessageList.cs
index 852095dc..f6603845 100644
--- a/MinecraftClient/Protocol/Message/LastSeenMessageList.cs
+++ b/MinecraftClient/Protocol/Message/LastSeenMessageList.cs
@@ -8,17 +8,12 @@ namespace MinecraftClient.Protocol.Message
///
/// A list of messages a client has seen.
///
- public class LastSeenMessageList
+ public class LastSeenMessageList(AcknowledgedMessage[] list)
{
public static readonly LastSeenMessageList EMPTY = new(Array.Empty());
public static readonly int MAX_ENTRIES = 5;
- public AcknowledgedMessage[] entries;
-
- public LastSeenMessageList(AcknowledgedMessage[] list)
- {
- entries = list;
- }
+ public AcknowledgedMessage[] entries = list;
public void WriteForSign(List data)
{
@@ -56,16 +51,10 @@ namespace MinecraftClient.Protocol.Message
/// A record of messages acknowledged by a client.
/// This holds the messages the client has recently seen, as well as the last message they received, if any.
///
- public class Acknowledgment
+ public class Acknowledgment(LastSeenMessageList lastSeenMessageList, AcknowledgedMessage? lastReceivedMessage)
{
- public LastSeenMessageList lastSeen;
- public AcknowledgedMessage? lastReceived;
-
- public Acknowledgment(LastSeenMessageList lastSeenMessageList, AcknowledgedMessage? lastReceivedMessage)
- {
- lastSeen = lastSeenMessageList;
- lastReceived = lastReceivedMessage;
- }
+ public LastSeenMessageList lastSeen = lastSeenMessageList;
+ public AcknowledgedMessage? lastReceived = lastReceivedMessage;
}
}
diff --git a/MinecraftClient/Protocol/MojangAPI.cs b/MinecraftClient/Protocol/MojangAPI.cs
index ab1c32bb..b05e6a71 100644
--- a/MinecraftClient/Protocol/MojangAPI.cs
+++ b/MinecraftClient/Protocol/MojangAPI.cs
@@ -19,19 +19,7 @@ namespace MinecraftClient.Protocol
/// Information about a players Skin.
/// Empty string if not available.
///
- public class SkinInfo
- {
- public readonly string SkinUrl;
- public readonly string CapeUrl;
- public readonly string SkinModel;
-
- public SkinInfo(string skinUrl = "", string capeUrl = "", string skinModel = "")
- {
- SkinUrl = skinUrl;
- CapeUrl = capeUrl;
- SkinModel = skinModel;
- }
- }
+ public record SkinInfo(string SkinUrl = "", string CapeUrl = "", string SkinModel = "");
///
/// Status of the single Mojang services
@@ -254,14 +242,14 @@ namespace MinecraftClient.Protocol
// Can apparently be missing, if no custom skin is set.
if (textureObj.ContainsKey("SKIN"))
{
- return new SkinInfo(skinUrl: textureObj["SKIN"]!["url"] is not null ? textureObj["SKIN"]!["url"]!.GetStringValue() : string.Empty,
- capeUrl: textureObj.ContainsKey("CAPE") ? textureObj["CAPE"]!["url"]!.GetStringValue() : string.Empty,
- skinModel: textureObj["SKIN"]!["metadata"] is not null ? "Alex" : "Steve");
+ return new SkinInfo(SkinUrl: textureObj["SKIN"]!["url"] is not null ? textureObj["SKIN"]!["url"]!.GetStringValue() : string.Empty,
+ CapeUrl: textureObj.ContainsKey("CAPE") ? textureObj["CAPE"]!["url"]!.GetStringValue() : string.Empty,
+ SkinModel: textureObj["SKIN"]!["metadata"] is not null ? "Alex" : "Steve");
}
else
{
- return new SkinInfo(capeUrl: textureObj.ContainsKey("CAPE") ? textureObj["CAPE"]!["url"]!.GetStringValue() : string.Empty,
- skinModel: DefaultModelAlex(uuid) ? "Alex" : "Steve");
+ return new SkinInfo(CapeUrl: textureObj.ContainsKey("CAPE") ? textureObj["CAPE"]!["url"]!.GetStringValue() : string.Empty,
+ SkinModel: DefaultModelAlex(uuid) ? "Alex" : "Steve");
}
}
diff --git a/MinecraftClient/Protocol/ProxiedWebRequest.cs b/MinecraftClient/Protocol/ProxiedWebRequest.cs
index 16724b71..220ac319 100644
--- a/MinecraftClient/Protocol/ProxiedWebRequest.cs
+++ b/MinecraftClient/Protocol/ProxiedWebRequest.cs
@@ -202,21 +202,8 @@ namespace MinecraftClient.Protocol
///
/// Basic HTTP response object.
///
- public class Response
+ public record Response(int StatusCode, string Body, NameValueCollection Headers, NameValueCollection Cookies)
{
- public int StatusCode;
- public string Body;
- public NameValueCollection Headers;
- public NameValueCollection Cookies;
-
- public Response(int statusCode, string body, NameValueCollection headers, NameValueCollection cookies)
- {
- StatusCode = statusCode;
- Body = body;
- Headers = headers;
- Cookies = cookies;
- }
-
public static Response Empty() =>
new(204, "", new NameValueCollection(), new NameValueCollection());