mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +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 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;
|
||||
|
||||
/// <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>
|
||||
/// Starts the main chat client, wich will login to the server using the MinecraftCom class.
|
||||
/// </summary>
|
||||
/// <param name="user">The chosen username of a premium Minecraft Account</param>
|
||||
/// <param name="sessionID">A valid sessionID obtained with MinecraftCom.GetLogin()</param>
|
||||
/// <param name="session">A valid session obtained with MinecraftCom.GetLogin()</param>
|
||||
/// <param name="playerKeyPair">Key for message signing</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="uuid">The player's UUID for online-mode authentication</param>
|
||||
/// <param name="singlecommand">If set to true, the client will send a single command and then disconnect from the server</param>
|
||||
/// <param name="forgeInfo">ForgeInfo item stating that Forge is enabled</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;
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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 != "")
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<byte> entryDataByte = stackalloc byte[8];
|
||||
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
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue