diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs
index 4bdf6535..00bd910a 100644
--- a/MinecraftClient/McClient.cs
+++ b/MinecraftClient/McClient.cs
@@ -112,7 +112,7 @@ namespace MinecraftClient
public int GetSequenceId() { return sequenceId; }
public float GetPitch() { return playerPitch; }
public World GetWorld() { return world; }
- public Double GetServerTPS() { return averageTPS; }
+ public double GetServerTPS() { return averageTPS; }
public bool GetIsSupportPreviewsChat() { return isSupportPreviewsChat; }
public float GetHealth() { return playerHealth; }
public int GetSaturation() { return playerFoodSaturation; }
@@ -133,47 +133,17 @@ namespace MinecraftClient
public ILogger Log;
- ///
- /// Starts the main chat client
- ///
- /// The chosen username of a premium Minecraft Account
- /// The player's UUID for online-mode authentication
- /// A valid sessionID obtained after logging in
- /// The server IP
- /// The server port to use
- /// Minecraft protocol version to use
- public McClient(SessionToken session, PlayerKeyPair? playerKeyPair, int protocolversion, ForgeInfo forgeInfo, string server_ip, ushort port)
- {
- StartClient(session, playerKeyPair, server_ip, port, protocolversion, forgeInfo, false, "");
- }
-
- ///
- /// Starts the main chat client in single command sending mode
- ///
- /// The chosen username of a premium Minecraft Account
- /// The player's UUID for online-mode authentication
- /// A valid sessionID obtained after logging in
- /// The server IP
- /// The server port to use
- /// Minecraft protocol version to use
- /// The text or command to send.
- public McClient(SessionToken session, PlayerKeyPair? playerKeyPair, string server_ip, ushort port, int protocolversion, ForgeInfo forgeInfo, string command)
- {
- StartClient(session, playerKeyPair, server_ip, port, protocolversion, forgeInfo, true, command);
- }
-
///
/// Starts the main chat client, wich will login to the server using the MinecraftCom class.
///
- /// The chosen username of a premium Minecraft Account
- /// A valid sessionID obtained with MinecraftCom.GetLogin()
+ /// A valid session obtained with MinecraftCom.GetLogin()
+ /// Key for message signing
/// The server IP
/// The server port to use
/// Minecraft protocol version to use
- /// The player's UUID for online-mode authentication
- /// If set to true, the client will send a single command and then disconnect from the server
+ /// ForgeInfo item stating that Forge is enabled
/// The text or command to send. Will only be sent if singlecommand is set to true.
- private void StartClient(SessionToken session, PlayerKeyPair? playerKeyPair, string server_ip, ushort port, int protocolversion, ForgeInfo forgeInfo, bool singlecommand, string command)
+ public McClient(SessionToken session, PlayerKeyPair? playerKeyPair, string server_ip, ushort port, int protocolversion, ForgeInfo? forgeInfo, string? command)
{
terrainAndMovementsEnabled = Settings.TerrainAndMovements;
inventoryHandlingEnabled = Settings.InventoryHandling;
@@ -197,7 +167,7 @@ namespace MinecraftClient
Log.WarnEnabled = Settings.WarningMessages;
Log.ErrorEnabled = Settings.ErrorMessages;
- if (!singlecommand)
+ if (command == null)
{
/* Load commands from Commands namespace */
LoadCommands();
@@ -234,7 +204,7 @@ namespace MinecraftClient
handler = Protocol.ProtocolHandler.GetProtocolHandler(client, protocolversion, forgeInfo, this);
Log.Info(Translations.Get("mcc.version_supported"));
- if (!singlecommand)
+ if (command == null)
{
timeoutdetector = new(new Thread(new ParameterizedThreadStart(TimeoutDetector)), new CancellationTokenSource());
timeoutdetector.Item1.Name = "MCC Connection timeout detector";
@@ -245,7 +215,7 @@ namespace MinecraftClient
{
if (handler.Login(this.playerKeyPair, session))
{
- if (singlecommand)
+ if (command != null)
{
handler.SendChatMessage(command, playerKeyPair);
Log.Info(Translations.Get("mcc.single_cmd", command));
@@ -301,7 +271,7 @@ namespace MinecraftClient
ReconnectionAttemptsLeft--;
Program.Restart();
}
- else if (!singlecommand && Settings.interactiveMode)
+ else if (command == null && Settings.interactiveMode)
{
ConsoleInteractive.ConsoleReader.StopReadThread();
ConsoleInteractive.ConsoleReader.MessageReceived -= ConsoleReaderOnMessageReceived;
diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs
index fd624594..2860c05a 100644
--- a/MinecraftClient/Program.cs
+++ b/MinecraftClient/Program.cs
@@ -71,7 +71,7 @@ namespace MinecraftClient
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
// "ToLower" require "CultureInfo" to be initialized on first run, which can take a lot of time.
- // _ = "a".ToLower();
+ _ = "a".ToLower();
}).Start();
//Setup ConsoleIO
@@ -497,11 +497,8 @@ namespace MinecraftClient
try
{
//Start the main TCP client
- if (Settings.SingleCommand != "")
- {
- client = new McClient(session, playerKeyPair, Settings.ServerIP, Settings.ServerPort, protocolversion, forgeInfo, Settings.SingleCommand);
- }
- else client = new McClient(session, playerKeyPair, protocolversion, forgeInfo, Settings.ServerIP, Settings.ServerPort);
+ string? command = String.IsNullOrEmpty(Settings.SingleCommand) ? null : Settings.SingleCommand;
+ client = new McClient(session, playerKeyPair, Settings.ServerIP, Settings.ServerPort, protocolversion, forgeInfo, command);
//Update console title
if (Settings.ConsoleTitle != "")
diff --git a/MinecraftClient/Protocol/Handlers/DataTypes.cs b/MinecraftClient/Protocol/Handlers/DataTypes.cs
index 6d180a72..f562f287 100644
--- a/MinecraftClient/Protocol/Handlers/DataTypes.cs
+++ b/MinecraftClient/Protocol/Handlers/DataTypes.cs
@@ -193,8 +193,8 @@ namespace MinecraftClient.Protocol.Handlers
}
if (x >= 0x02000000) // 33,554,432
x -= 0x04000000; // 67,108,864
- if (y >= 0x00000800) // 2048
- y -= 0x00001000; // 4096
+ if (y >= 0x00000800) // 2,048
+ y -= 0x00001000; // 4,096
if (z >= 0x02000000) // 33,554,432
z -= 0x04000000; // 67,108,864
return new Location(x, y, z);
diff --git a/MinecraftClient/Protocol/Handlers/Protocol18Terrain.cs b/MinecraftClient/Protocol/Handlers/Protocol18Terrain.cs
index 8ac04bb6..151e4f70 100644
--- a/MinecraftClient/Protocol/Handlers/Protocol18Terrain.cs
+++ b/MinecraftClient/Protocol/Handlers/Protocol18Terrain.cs
@@ -56,12 +56,12 @@ namespace MinecraftClient.Protocol.Handlers
return null;
// Warning: If you need to support modification of block data, you need to create 4096 objects here
- Block[] blocks = new Block[Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ];
+ Chunk chunk = new();
for (int blockY = 0; blockY < Chunk.SizeY; blockY++)
for (int blockZ = 0; blockZ < Chunk.SizeZ; blockZ++)
for (int blockX = 0; blockX < Chunk.SizeX; blockX++)
- blocks[(blockY << 8) | (blockZ << 4) | blockX] = block;
- return new Chunk(blocks);
+ chunk.SetWithoutCheck(blockX, blockY, blockZ, block);
+ return chunk;
}
else
{
@@ -86,7 +86,7 @@ namespace MinecraftClient.Protocol.Handlers
Span entryDataByte = stackalloc byte[8];
Span entryDataLong = MemoryMarshal.Cast(entryDataByte); // Faster than MemoryMarshal.Read
- Block[] blocks = new Block[Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ];
+ Chunk chunk = new();
int startOffset = 64; // Read the first data immediately
for (int blockY = 0; blockY < Chunk.SizeY; blockY++)
{
@@ -129,11 +129,11 @@ namespace MinecraftClient.Protocol.Handlers
Block block = new((ushort)blockId);
// We have our block, save the block into the chunk
- blocks[(blockY << 8) | (blockZ << 4) | blockX] = block;
+ chunk.SetWithoutCheck(blockX, blockY, blockZ, block);
}
}
}
- return new Chunk(blocks);
+ return chunk;
}
}