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