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>
This commit is contained in:
copilot-swe-agent[bot] 2026-03-24 01:31:17 +00:00
parent 81b756292e
commit 654a16907b
18 changed files with 68 additions and 231 deletions

View file

@ -15,21 +15,12 @@ namespace MinecraftClient.Protocol.Handlers
/// <summary>
/// Handle data types encoding / decoding
/// </summary>
public class DataTypes
public class DataTypes(int protocol)
{
/// <summary>
/// Protocol version for adjusting data types
/// </summary>
private readonly int protocolversion;
/// <summary>
/// Initialize a new DataTypes instance
/// </summary>
/// <param name="protocol">Protocol version</param>
public DataTypes(int protocol)
{
protocolversion = protocol;
}
private readonly int protocolversion = protocol;
/// <summary>
/// Protocol version used to adjust wire encodings.

View file

@ -11,17 +11,8 @@ namespace MinecraftClient.Protocol.Handlers.Forge
/// <summary>
/// Represents an individual forge mod.
/// </summary>
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;

View file

@ -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
{

View file

@ -12,32 +12,17 @@ namespace MinecraftClient.Protocol.Handlers
/// <summary>
/// Handler for the Minecraft Forge protocol
/// </summary>
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; }
/// <summary>
/// Initialize a new Forge protocol handler
/// </summary>
/// <param name="forgeInfo">Forge Server Information</param>
/// <param name="protocolVersion">Minecraft protocol version</param>
/// <param name="dataTypes">Minecraft data types handler</param>
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;
}
/// <summary>
/// Get Forge-Tagged server address
/// </summary>

View file

@ -12,23 +12,11 @@ namespace MinecraftClient.Protocol.Handlers
/// <summary>
/// Terrain Decoding handler for Protocol18
/// </summary>
class Protocol18Terrain
class Protocol18Terrain(int protocolVersion, DataTypes dataTypes, IMinecraftComHandler handler)
{
private readonly int protocolversion;
private readonly DataTypes dataTypes;
private readonly IMinecraftComHandler handler;
/// <summary>
/// Initialize a new Terrain Decoder
/// </summary>
/// <param name="protocolVersion">Minecraft Protocol Version</param>
/// <param name="dataTypes">Minecraft Protocol Data Types</param>
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;
/// <summary>
/// Reading the "Block states" field: consists of 4096 entries, representing all the blocks in the chunk section.

View file

@ -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!;