Minecraft-Console-Client/MinecraftClient/McClient.cs

2786 lines
116 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Threading;
using System.IO;
using System.Net;
using MinecraftClient.ChatBots;
using MinecraftClient.Protocol;
using MinecraftClient.Proxy;
using MinecraftClient.Protocol.Handlers.Forge;
using MinecraftClient.Mapping;
using MinecraftClient.Inventory;
using MinecraftClient.Logger;
using MinecraftClient.Protocol.Keys;
using MinecraftClient.Protocol.Session;
2022-08-27 02:10:44 +08:00
using MinecraftClient.Protocol.Message;
namespace MinecraftClient
{
/// <summary>
/// The main client class, used to connect to a Minecraft server.
/// </summary>
public class McClient : IMinecraftComHandler
{
public static int ReconnectionAttemptsLeft = 0;
private static readonly List<string> cmd_names = new();
private static readonly Dictionary<string, Command> cmds = new();
private readonly Dictionary<Guid, PlayerInfo> onlinePlayers = new();
private static bool commandsLoaded = false;
private Queue<string> chatQueue = new();
private static DateTime nextMessageSendTime = DateTime.MinValue;
private Queue<Action> threadTasks = new();
private object threadTasksLock = new();
private readonly List<ChatBot> bots = new();
private static readonly List<ChatBot> botsOnHold = new();
private static Dictionary<int, Container> inventories = new();
private readonly Dictionary<string, List<ChatBot>> registeredBotPluginChannels = new();
private readonly List<string> registeredServerPluginChannels = new();
private bool terrainAndMovementsEnabled;
private bool terrainAndMovementsRequested = false;
private bool inventoryHandlingEnabled;
private bool inventoryHandlingRequested = false;
private bool entityHandlingEnabled;
private object locationLock = new();
private bool locationReceived = false;
private World world = new();
private Queue<Location> steps;
2022-09-04 17:34:12 +08:00
private Queue<Location>? path;
private Location location;
private float? _yaw; // Used for calculation ONLY!!! Doesn't reflect the client yaw
private float? _pitch; // Used for calculation ONLY!!! Doesn't reflect the client pitch
private float playerYaw;
private float playerPitch;
private double motionY;
Rework of MineCube.cs and further improvements to CalculatePath() (#2014) * Add function to determine if the client is executing a walking process * Add comments * Remove test bot entry * Add funtion to approach a block as close as possible * Add funtion to approach a block as close as possible * Add funtion to approach a block as close as possible * Add comment to function in McClient.cs * Improve concurrency and reduce potential calculation power * Apply code suggestions * Apply code suggestions * Improve CalculatePath() function to allow approaching * Fix typo in MinecraftClient/ChatBot.cs * Add comments to Chatbot fucntion * Add break to for loop to exit quicker * Allow to give a maxOffset to the goal * Comment the sample bot again. * Add parameter for calculation timeout * Remove TestBot again * Implement timeout in Chatbot class * Remove test commands * Update comment in Chatbot.cs * Set timeout to default 5 sec * Change order of parameters back * Add suggested improvements * Move task and fix missing methods in .NET 4.0 * Create switch for tool handling * Remove unused function * Improve movement * Improve performance of CalculatePath() - Replace Hashset OpenSet with a Binary Heap - Temporary remove maxOffset / minOffset features - Round start location for easier calculation - Add 0.5 to each location in reconstruct path to avoid getting stuck on edges * Add diagonal movement * Remove direct block movement - causes kick for invalid packet movement if moving on the block you are currently standing on * Floor start in A* and improve diagonal walking check * Add helperfunctions to McClient.cs * Prevent client from falling into danger * Add comment to function and remove dependencies * Add comments * Remove debug settings Co-authored-by: ORelio <ORelio@users.noreply.github.com>
2022-08-15 18:26:40 +02:00
public enum MovementType { Sneak, Walk, Sprint}
public int currentMovementSpeed = 4;
private int sequenceId; // User for player block synchronization (Aka. digging, placing blocks, etc..)
private string host;
private int port;
private int protocolversion;
private string username;
2022-08-27 02:10:44 +08:00
private Guid uuid;
private string uuidStr;
private string sessionid;
private PlayerKeyPair? playerKeyPair;
private DateTime lastKeepAlive;
private object lastKeepAliveLock = new();
private int respawnTicks = 0;
private int gamemode = 0;
private bool isSupportPreviewsChat;
private int playerEntityID;
// player health and hunger
private float playerHealth;
private int playerFoodSaturation;
Add SendPlaceBlock, PlayerDigging, OnExplosion, OnGamemodeUpdate, OnSetExperience (#1027) * Update ChatBot.cs + PlaceBlock * Update AutoAttack.cs + HitAnimation * Update PacketIncomingType.cs + Explosion, * Update McTcpClient.cs + OnExplosion * Update ChatBot.cs + OnExplosion * Update IMinecraftComHandler.cs + OnExplosion * Update Protocol18PacketTypes.cs + PacketIncomingType.Explosion * Update ChatBot.cs + Fix * Update AutoAttack.cs + Fix * Update ChatBot.cs + Fix * Update Protocol18PacketTypes.cs + Old versions * Update Protocol18PacketTypes.cs + 1.7 - 1.8 Explosion ID * Update Protocol18PacketTypes.cs + Fix * Update McTcpClient.cs + int ExplosionRecordCount * Update ChatBot.cs + recordcount * Update IMinecraftComHandler.cs + ExplosionRecordCount * Update Protocol18.cs * Update CSharpRunner.cs + using MinecraftClient.Inventory; * add OnGamemodeUpdate + OnGamemodeUpdate * + OnGamemodeUpdate(playername, uuid, gamemode) + OnGamemodeUpdate * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McTcpClient.cs Fix * Update McTcpClient.cs * Update Protocol18.cs + Location explodelocation * Update McTcpClient.cs + Location explode * Update ChatBot.cs + Fix * Update ChatBot.cs Remove excess + * Update Plays animation * Improve documentation * ItemType fix * OnExplosion(Location explod); * Update PacketIncomingType.cs add SetExperience, * + Old versions * Update IMinecraftComHandler.cs * Update McTcpClient.cs * Update Protocol18.cs * add GetLevel & GetTotalExperience * Fix * add GetLevel & GetTotalExperience * OnSetExpience * Update ChatBot.cs Fix * Update McTcpClient.cs + bot.OnSetExperience * Update Protocol18.cs + Fix * Update McTcpClient.cs + PlayerDigging * Update PacketOutgoingType.cs + PlayerDigging * Update Protocol18PacketTypes.cs + case PacketOutgoingType.PlayerDigging * Update Protocol18.cs + SendPlayerDigging * Update IMinecraftCom.cs + SendPlayerDigging * Update McTcpClient.cs + PlayerDigging * Update Protocol16.cs + SendPlayerDigging * Update ChatBot.cs + PlayerDigging * Update ChatBot.cs + Fix * Update McTcpClient.cs + Fix * Update ChatBot.cs Add WindowAction * ChatBot.cs Fixes * Further ChatBot.cs fixes * Further ChatBot.cs fixes * Protocol Handler fixes * Protocol Handler fixes * IMinecraftCom fixes * documentation fixes Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-05-29 23:18:34 +05:00
private int playerLevel;
private int playerTotalExperience;
private byte CurrentSlot = 0;
// Entity handling
private Dictionary<int, Entity> entities = new();
// server TPS
private long lastAge = 0;
private DateTime lastTime;
private double serverTPS = 0;
private double averageTPS = 20;
private const int maxSamples = 5;
private List<double> tpsSamples = new(maxSamples);
private double sampleSum = 0;
// ChatBot OnNetworkPacket event
private bool networkPacketCaptureEnabled = false;
public int GetServerPort() { return port; }
public string GetServerHost() { return host; }
public string GetUsername() { return username; }
2022-08-27 02:10:44 +08:00
public Guid GetUserUuid() { return uuid; }
public string GetUserUuidStr() { return uuidStr; }
public string GetSessionID() { return sessionid; }
public Location GetCurrentLocation() { return location; }
public float GetYaw() { return playerYaw; }
public int GetSequenceId() { return sequenceId; }
public float GetPitch() { return playerPitch; }
public World GetWorld() { return world; }
2022-08-31 20:46:21 +08:00
public double GetServerTPS() { return averageTPS; }
public bool GetIsSupportPreviewsChat() { return isSupportPreviewsChat; }
public float GetHealth() { return playerHealth; }
public int GetSaturation() { return playerFoodSaturation; }
Add SendPlaceBlock, PlayerDigging, OnExplosion, OnGamemodeUpdate, OnSetExperience (#1027) * Update ChatBot.cs + PlaceBlock * Update AutoAttack.cs + HitAnimation * Update PacketIncomingType.cs + Explosion, * Update McTcpClient.cs + OnExplosion * Update ChatBot.cs + OnExplosion * Update IMinecraftComHandler.cs + OnExplosion * Update Protocol18PacketTypes.cs + PacketIncomingType.Explosion * Update ChatBot.cs + Fix * Update AutoAttack.cs + Fix * Update ChatBot.cs + Fix * Update Protocol18PacketTypes.cs + Old versions * Update Protocol18PacketTypes.cs + 1.7 - 1.8 Explosion ID * Update Protocol18PacketTypes.cs + Fix * Update McTcpClient.cs + int ExplosionRecordCount * Update ChatBot.cs + recordcount * Update IMinecraftComHandler.cs + ExplosionRecordCount * Update Protocol18.cs * Update CSharpRunner.cs + using MinecraftClient.Inventory; * add OnGamemodeUpdate + OnGamemodeUpdate * + OnGamemodeUpdate(playername, uuid, gamemode) + OnGamemodeUpdate * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McTcpClient.cs Fix * Update McTcpClient.cs * Update Protocol18.cs + Location explodelocation * Update McTcpClient.cs + Location explode * Update ChatBot.cs + Fix * Update ChatBot.cs Remove excess + * Update Plays animation * Improve documentation * ItemType fix * OnExplosion(Location explod); * Update PacketIncomingType.cs add SetExperience, * + Old versions * Update IMinecraftComHandler.cs * Update McTcpClient.cs * Update Protocol18.cs * add GetLevel & GetTotalExperience * Fix * add GetLevel & GetTotalExperience * OnSetExpience * Update ChatBot.cs Fix * Update McTcpClient.cs + bot.OnSetExperience * Update Protocol18.cs + Fix * Update McTcpClient.cs + PlayerDigging * Update PacketOutgoingType.cs + PlayerDigging * Update Protocol18PacketTypes.cs + case PacketOutgoingType.PlayerDigging * Update Protocol18.cs + SendPlayerDigging * Update IMinecraftCom.cs + SendPlayerDigging * Update McTcpClient.cs + PlayerDigging * Update Protocol16.cs + SendPlayerDigging * Update ChatBot.cs + PlayerDigging * Update ChatBot.cs + Fix * Update McTcpClient.cs + Fix * Update ChatBot.cs Add WindowAction * ChatBot.cs Fixes * Further ChatBot.cs fixes * Further ChatBot.cs fixes * Protocol Handler fixes * Protocol Handler fixes * IMinecraftCom fixes * documentation fixes Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-05-29 23:18:34 +05:00
public int GetLevel() { return playerLevel; }
public int GetTotalExperience() { return playerTotalExperience; }
public byte GetCurrentSlot() { return CurrentSlot; }
public int GetGamemode() { return gamemode; }
public bool GetNetworkPacketCaptureEnabled() { return networkPacketCaptureEnabled; }
public int GetProtocolVersion() { return protocolversion; }
public ILogger GetLogger() { return this.Log; }
2021-03-21 22:17:19 +08:00
public int GetPlayerEntityID() { return playerEntityID; }
public List<ChatBot> GetLoadedChatBots() { return new List<ChatBot>(bots); }
TcpClient client;
IMinecraftCom handler;
CancellationTokenSource? cmdprompt = null;
Tuple<Thread, CancellationTokenSource>? timeoutdetector = null;
public ILogger Log;
/// <summary>
/// Starts the main chat client, wich will login to the server using the MinecraftCom class.
/// </summary>
2022-08-31 20:46:21 +08:00
/// <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>
2022-08-31 20:46:21 +08:00
/// <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>
2022-08-31 20:46:21 +08:00
public McClient(SessionToken session, PlayerKeyPair? playerKeyPair, string server_ip, ushort port, int protocolversion, ForgeInfo? forgeInfo, string? command)
{
terrainAndMovementsEnabled = Settings.TerrainAndMovements;
inventoryHandlingEnabled = Settings.InventoryHandling;
entityHandlingEnabled = Settings.EntityHandling;
bool retry = false;
this.sessionid = session.ID;
2022-09-04 10:44:25 +08:00
if (!Guid.TryParse(session.PlayerID, out this.uuid))
2022-08-29 17:13:35 +08:00
this.uuid = Guid.Empty;
2022-09-04 10:44:25 +08:00
this.uuidStr = session.PlayerID;
this.username = session.PlayerName;
this.host = server_ip;
this.port = port;
2020-10-30 22:50:48 +01:00
this.protocolversion = protocolversion;
this.playerKeyPair = playerKeyPair;
this.Log = Settings.LogToFile
? new FileLogLogger(Settings.ExpandVars(Settings.LogFile), Settings.PrependTimestamp)
: new FilteredLogger();
Log.DebugEnabled = Settings.DebugMessages;
Log.InfoEnabled = Settings.InfoMessages;
Log.ChatEnabled = Settings.ChatMessages;
Log.WarnEnabled = Settings.WarningMessages;
Log.ErrorEnabled = Settings.ErrorMessages;
2022-08-31 20:46:21 +08:00
if (command == null)
{
/* Load commands from Commands namespace */
LoadCommands();
if (botsOnHold.Count == 0)
{
if (Settings.AntiAFK_Enabled) { BotLoad(new ChatBots.AntiAFK(Settings.AntiAFK_Delay)); }
if (Settings.Hangman_Enabled) { BotLoad(new ChatBots.HangmanGame(Settings.Hangman_English)); }
if (Settings.Alerts_Enabled) { BotLoad(new ChatBots.Alerts()); }
if (Settings.ChatLog_Enabled) { BotLoad(new ChatBots.ChatLog(Settings.ExpandVars(Settings.ChatLog_File), Settings.ChatLog_Filter, Settings.ChatLog_DateTime)); }
if (Settings.PlayerLog_Enabled) { BotLoad(new ChatBots.PlayerListLogger(Settings.PlayerLog_Delay, Settings.ExpandVars(Settings.PlayerLog_File))); }
if (Settings.AutoRelog_Enabled) { BotLoad(new ChatBots.AutoRelog(Settings.AutoRelog_Delay_Min, Settings.AutoRelog_Delay_Max, Settings.AutoRelog_Retries)); }
if (Settings.ScriptScheduler_Enabled) { BotLoad(new ChatBots.ScriptScheduler(Settings.ExpandVars(Settings.ScriptScheduler_TasksFile))); }
if (Settings.RemoteCtrl_Enabled) { BotLoad(new ChatBots.RemoteControl()); }
if (Settings.AutoRespond_Enabled) { BotLoad(new ChatBots.AutoRespond(Settings.AutoRespond_Matches)); }
if (Settings.AutoAttack_Enabled) { BotLoad(new ChatBots.AutoAttack(Settings.AutoAttack_Mode, Settings.AutoAttack_Priority, Settings.AutoAttack_OverrideAttackSpeed, Settings.AutoAttack_CooldownSeconds, Settings.AutoAttack_Interaction)); }
if (Settings.AutoFishing_Enabled) { BotLoad(new ChatBots.AutoFishing()); }
if (Settings.AutoEat_Enabled) { BotLoad(new ChatBots.AutoEat(Settings.AutoEat_hungerThreshold)); }
Add Mailer bot (#1108) * Update for the mail script. As requested, I added the synchronization between the config debugmessage bool and the one in the script. Furthermore, I added a way to send anonymous mails by writing "tellonym". The messages are saved as normal mails, which lets them count to the mail cap, due to the fact that the host knows the sender. I added the script to the chat bots because of the problems, that the scripts have with serialization. Instead of rewriting the whole serialization part, my idea was to add the script to the other chat bots, to avoid the compiling issues. Then the serialization would work perfectly fine. Then you could remove the option class at some point and move all the settings to the config file with the addition to activate the whole script. * Correction of debug message loading. The object was missing and the change would be overridden a few lines later. * Update McClient.cs * Add Mail to config file * Correcting the safe file. * Small correction of Settings.c * Update Mailscript Added a failsafe version of the path changing commands. If a path could not be found, an error will be created and the path will be reseted to standart, to avoid endless chains of errors. * Fix for the mail script Removed a wrong option call. Removed the debug_msg condition around the path functions. => Users are aware of what happened (if they see the error) although they turned off debug_msg. * Added some features. Added a try statement to all number changing commands. Added a command to list all moderators to the console. * Serialization Fix There was a chance, that if two bots work on one file, and two users send messages in a short time period, that one bot deserializes the message and then the other bot deserialize the same file, before the other one could save its changes. This would lead to one message disappearing, because one bot never deserialized this message. For this I changed the whole serialization process. All changes are now committed after the interval and not after an incoming mail command directly. All mails are safed temporarily in cache and get serialized after the interval. Due to this changes, you can determit when the individual bot changes the file (there are no more direct interactions with the file after a command, which lead to a certain randomness). Furthermore you can now set an interval of e.g. 2 mins and reset the interval of one bot with "resettimer" after one minute so that the bots won't disturb eachother and no files get lost. * My idea of a manual. This is my idea of a manual for the bot. Improvements of my language / further ideas are welcome! :D * addIgnored [NAME] and removeIgnored[NAME] Added an ignored list. Moderators can add players to the list. The bot won't react to them and just log to the console that they are ignored, everytime they are sending a message, to ensure that they are not accidently ignored. (Just if debug_msg is active.) Especially useful if there are other chat bots on the server, which spam many messages that aren't useful for the mail system. Or block spammers etc. * Add the three commands to the manual. Added addignored, removeignored and getignored to the manual. * Remove moderators. Implement Console Control. Due to security concerns, I converted all moderator commands to console internal commands. Thereby only the host can change crucial settings. Special thanks to ORelio for the hint! * Added empty statement check Added if to all commands, where the syntax is not already protected by a try, so that an incorrect syntax (Empty args[] due to missing statement) won't crash the script. * Changed the serialization fail If the programm can't safe the file, because of some strange character for instance, it first tries to change the path back to normal and if this not helps, it creates a new, file. * toggle mail sending/receiving Add an option to turn mailsending and the listening to commands in chat on/off. * Updated manual. - Removed moderator commands. - Removed moderator part in the network manual + added the two new commands + added a waring for nick plugins and minecraft renames + added a small syntax example * Updated the Settings.cs file. * Smaller fixes and additions + improved command reading of 'mail' & 'tellonym' + sorted internal commands alphabetically + host can set a maximum message length + host can accept commands from public chat + host can decide if 'self mailing' (mailing yourself) is accepted + new order makes 'getsettings' easier to read + new internal commands to toggle 'publiccommands' and 'selfmailing' as well as the maximum mail size - removed the old command interpreter * Small improvements and additions Added a few commands and settings * Completing getsettings + added 'publiccomands' * Completed getsettings + Added 'publiccommand' to 'getsettings' * Removed single bolean, added Dictionary - removed all boleans in the option class - removed all functions relating them + added Dictionary for the booleans + added a single function to set/toggle all booleans * Removed Commands, added interpreter - Removed all Register commands - removed all integer methods + added a single mail command + added integer dictionary + added integer handling similar like bool handling * Small fix + Changed the numbers in several methods to adjust them to the new syntax. - removed parameters in several methods, because they got unneccesary * Even smaller fix + Sorted 'getsettings' alphabetically + corrected a typo * New Serialization method. Now serializing through the .INI format! Thanks to ORelio, who helped me a lot! :) * Added different time Added the option to switch between utc and the time of the local machine for timestamps. * Made timeinutc serializable Added the bool to the serialization method. * Adding the INIFile.cs For Dictionary serialization. * Reworked ignore feature Ignored players are now serialized in a file and reloaded, after the bot enters a server. * Mailer bot refactoring Rename Mail to Mailer Move options to MinecraftClient.ini Make the bot much simpler by removing some settings Create specific MailDatabase and IgnoreList classes However the core functionality for users is the same Settings removed: - allow_sendmail: Cannot use Mailer if it's disabled - allow_receivemail: Cannot use Mailer if it's disabled - path_setting: Settings moved to MinecraftClient.ini - debug_msg: MCC already has a setting for that with LogDebugToConsole() - auto_respawn: MCC already has a built-in auto-respawn feature - allow_selfmail: Is it really necessary to block self mails? ;) - maxcharsinmsg: Automatically calculated based on max chat message length - timeinutc: DateTime is not show to the recipient so I think it's not absolutely necessary - interval_sendmail: Set to 10 seconds for now Internal Commands removed: - changemailpath: Now a static setting in config - changesettingspath: Now a static setting in config - updatemails: Already updated every 10 seconds - getsettings: Shown on startup with debugmessages=true - resettimer: Seems only useful for debugging - setbool: Settings are static in config file - setinteger: Settings are static in config file All user commands are retained: - mail - tellonym * Reload database for mailer network feature * Merge Mail documentation to Readme.md Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-08-03 21:44:39 +02:00
if (Settings.Mailer_Enabled) { BotLoad(new ChatBots.Mailer()); }
if (Settings.AutoCraft_Enabled) { BotLoad(new AutoCraft(Settings.AutoCraft_configFile)); }
if (Settings.AutoDrop_Enabled) { BotLoad(new AutoDrop(Settings.AutoDrop_Mode, Settings.AutoDrop_items)); }
if (Settings.ReplayMod_Enabled) { BotLoad(new ReplayCapture(Settings.ReplayMod_BackupInterval)); }
2020-07-07 11:38:15 +08:00
//Add your ChatBot here by uncommenting and adapting
//BotLoad(new ChatBots.YourBot());
}
}
try
{
client = ProxyHandler.newTcpClient(host, port);
client.ReceiveBufferSize = 1024 * 1024;
client.ReceiveTimeout = 30000; // 30 seconds
handler = Protocol.ProtocolHandler.GetProtocolHandler(client, protocolversion, forgeInfo, this);
Log.Info(Translations.Get("mcc.version_supported"));
2022-08-31 20:46:21 +08:00
if (command == null)
2021-04-30 12:28:27 +08:00
{
timeoutdetector = new(new Thread(new ParameterizedThreadStart(TimeoutDetector)), new CancellationTokenSource());
timeoutdetector.Item1.Name = "MCC Connection timeout detector";
timeoutdetector.Item1.Start(timeoutdetector.Item2.Token);
2021-04-30 12:28:27 +08:00
}
try
{
if (handler.Login(this.playerKeyPair, session))
{
2022-08-31 20:46:21 +08:00
if (command != null)
{
handler.SendChatMessage(command, playerKeyPair);
Log.Info(Translations.Get("mcc.single_cmd", command));
Thread.Sleep(5000);
handler.Disconnect();
Thread.Sleep(1000);
}
else
{
foreach (ChatBot bot in botsOnHold)
BotLoad(bot, false);
botsOnHold.Clear();
Log.Info(Translations.Get("mcc.joined", (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar)));
cmdprompt = new CancellationTokenSource();
ConsoleInteractive.ConsoleReader.BeginReadThread(cmdprompt);
ConsoleInteractive.ConsoleReader.MessageReceived += ConsoleReaderOnMessageReceived;
ConsoleInteractive.ConsoleReader.OnKeyInput += ConsoleIO.AutocompleteHandler;
}
}
else
{
Log.Error(Translations.Get("error.login_failed"));
retry = true;
}
}
catch (Exception e)
{
Log.Error(e.GetType().Name + ": " + e.Message);
Log.Error(Translations.Get("error.join"));
retry = true;
}
}
catch (SocketException e)
{
Log.Error(e.Message);
Log.Error(Translations.Get("error.connect"));
retry = true;
}
if (retry)
{
2021-04-30 12:28:27 +08:00
if (timeoutdetector != null)
{
timeoutdetector.Item2.Cancel();
2021-04-30 12:28:27 +08:00
timeoutdetector = null;
}
if (ReconnectionAttemptsLeft > 0)
{
Log.Info(Translations.Get("mcc.reconnect", ReconnectionAttemptsLeft));
Thread.Sleep(5000);
ReconnectionAttemptsLeft--;
Program.Restart();
}
2022-08-31 20:46:21 +08:00
else if (command == null && Settings.interactiveMode)
{
ConsoleInteractive.ConsoleReader.StopReadThread();
ConsoleInteractive.ConsoleReader.MessageReceived -= ConsoleReaderOnMessageReceived;
ConsoleInteractive.ConsoleReader.OnKeyInput -= ConsoleIO.AutocompleteHandler;
Program.HandleFailure();
}
}
}
2022-08-31 22:52:05 +08:00
/// <summary>
/// Retrieve messages from the queue and send.
/// Note: requires external locking.
/// </summary>
private void TrySendMessageToServer()
{
while (chatQueue.Count > 0 && nextMessageSendTime < DateTime.Now)
{
string text = chatQueue.Dequeue();
handler.SendChatMessage(text, playerKeyPair);
nextMessageSendTime = DateTime.Now + Settings.messageCooldown;
}
}
/// <summary>
/// Called ~10 times per second by the protocol handler
/// </summary>
public void OnUpdate()
{
foreach (ChatBot bot in bots.ToArray())
{
try
{
bot.Update();
bot.UpdateInternal();
}
catch (Exception e)
{
2022-08-31 22:52:05 +08:00
if (e is not ThreadAbortException)
Log.Warn("Update: Got error from " + bot.ToString() + ": " + e.ToString());
2022-08-31 22:52:05 +08:00
else
throw; //ThreadAbortException should not be caught
}
}
lock (chatQueue)
{
2022-08-31 22:52:05 +08:00
TrySendMessageToServer();
}
if (terrainAndMovementsEnabled && locationReceived)
{
lock (locationLock)
{
Rework of MineCube.cs and further improvements to CalculatePath() (#2014) * Add function to determine if the client is executing a walking process * Add comments * Remove test bot entry * Add funtion to approach a block as close as possible * Add funtion to approach a block as close as possible * Add funtion to approach a block as close as possible * Add comment to function in McClient.cs * Improve concurrency and reduce potential calculation power * Apply code suggestions * Apply code suggestions * Improve CalculatePath() function to allow approaching * Fix typo in MinecraftClient/ChatBot.cs * Add comments to Chatbot fucntion * Add break to for loop to exit quicker * Allow to give a maxOffset to the goal * Comment the sample bot again. * Add parameter for calculation timeout * Remove TestBot again * Implement timeout in Chatbot class * Remove test commands * Update comment in Chatbot.cs * Set timeout to default 5 sec * Change order of parameters back * Add suggested improvements * Move task and fix missing methods in .NET 4.0 * Create switch for tool handling * Remove unused function * Improve movement * Improve performance of CalculatePath() - Replace Hashset OpenSet with a Binary Heap - Temporary remove maxOffset / minOffset features - Round start location for easier calculation - Add 0.5 to each location in reconstruct path to avoid getting stuck on edges * Add diagonal movement * Remove direct block movement - causes kick for invalid packet movement if moving on the block you are currently standing on * Floor start in A* and improve diagonal walking check * Add helperfunctions to McClient.cs * Prevent client from falling into danger * Add comment to function and remove dependencies * Add comments * Remove debug settings Co-authored-by: ORelio <ORelio@users.noreply.github.com>
2022-08-15 18:26:40 +02:00
for (int i = 0; i < currentMovementSpeed; i++) //Needs to run at 20 tps; MCC runs at 10 tps
{
if (_yaw == null || _pitch == null)
{
if (steps != null && steps.Count > 0)
{
location = steps.Dequeue();
}
else if (path != null && path.Count > 0)
{
Location next = path.Dequeue();
steps = Movement.Move2Steps(location, next, ref motionY);
if (Settings.MoveHeadWhileWalking) // Disable head movements to avoid anti-cheat triggers
{
UpdateLocation(location, next + new Location(0, 1, 0)); // Update yaw and pitch to look at next step
}
}
else
{
location = Movement.HandleGravity(world, location, ref motionY);
}
}
playerYaw = _yaw == null ? playerYaw : _yaw.Value;
playerPitch = _pitch == null ? playerPitch : _pitch.Value;
handler.SendLocationUpdate(location, Movement.IsOnGround(world, location), _yaw, _pitch);
}
// First 2 updates must be player position AND look, and player must not move (to conform with vanilla)
// Once yaw and pitch have been sent, switch back to location-only updates (without yaw and pitch)
_yaw = null;
_pitch = null;
}
}
if (Settings.AutoRespawn && respawnTicks > 0)
{
respawnTicks--;
if (respawnTicks == 0)
SendRespawnPacket();
}
lock (threadTasksLock)
{
while (threadTasks.Count > 0)
{
Action taskToRun = threadTasks.Dequeue();
taskToRun();
}
}
}
#region Connection Lost and Disconnect from Server
/// <summary>
/// Periodically checks for server keepalives and consider that connection has been lost if the last received keepalive is too old.
/// </summary>
private void TimeoutDetector(object? o)
{
2021-04-30 12:28:27 +08:00
UpdateKeepAlive();
do
{
Thread.Sleep(TimeSpan.FromSeconds(15));
if (((CancellationToken)o!).IsCancellationRequested)
return;
lock (lastKeepAliveLock)
{
if (lastKeepAlive.AddSeconds(30) < DateTime.Now)
{
if (((CancellationToken)o!).IsCancellationRequested)
return;
OnConnectionLost(ChatBot.DisconnectReason.ConnectionLost, Translations.Get("error.timeout"));
return;
}
}
}
while (!((CancellationToken)o!).IsCancellationRequested);
}
2021-04-30 12:28:27 +08:00
/// <summary>
/// Update last keep alive to current time
/// </summary>
private void UpdateKeepAlive()
{
lock (lastKeepAliveLock)
{
lastKeepAlive = DateTime.Now;
}
}
/// <summary>
/// Disconnect the client from the server (initiated from MCC)
/// </summary>
public void Disconnect()
{
DispatchBotEvent(bot => bot.OnDisconnect(ChatBot.DisconnectReason.UserLogout, ""));
botsOnHold.Clear();
botsOnHold.AddRange(bots);
if (handler != null)
{
handler.Disconnect();
handler.Dispose();
}
if (cmdprompt != null)
{
cmdprompt.Cancel();
cmdprompt = null;
}
if (timeoutdetector != null)
{
timeoutdetector.Item2.Cancel();
timeoutdetector = null;
}
if (client != null)
client.Close();
}
/// <summary>
/// When connection has been lost, login was denied or played was kicked from the server
/// </summary>
public void OnConnectionLost(ChatBot.DisconnectReason reason, string message)
{
handler.Dispose();
world.Clear();
if (timeoutdetector != null)
{
if (Thread.CurrentThread != timeoutdetector.Item1)
timeoutdetector.Item2.Cancel();
timeoutdetector = null;
}
bool will_restart = false;
switch (reason)
{
case ChatBot.DisconnectReason.ConnectionLost:
message = Translations.Get("mcc.disconnect.lost");
Log.Info(message);
break;
case ChatBot.DisconnectReason.InGameKick:
Log.Info(Translations.Get("mcc.disconnect.server"));
Log.Info(message);
break;
case ChatBot.DisconnectReason.LoginRejected:
Log.Info(Translations.Get("mcc.disconnect.login"));
Log.Info(message);
break;
case ChatBot.DisconnectReason.UserLogout:
throw new InvalidOperationException(Translations.Get("exception.user_logout"));
}
//Process AutoRelog last to make sure other bots can perform their cleanup tasks first (issue #1517)
List<ChatBot> onDisconnectBotList = bots.Where(bot => !(bot is AutoRelog)).ToList();
onDisconnectBotList.AddRange(bots.Where(bot => bot is AutoRelog));
foreach (ChatBot bot in onDisconnectBotList)
{
try
{
will_restart |= bot.OnDisconnect(reason, message);
}
catch (Exception e)
{
if (!(e is ThreadAbortException))
{
Log.Warn("OnDisconnect: Got error from " + bot.ToString() + ": " + e.ToString());
}
else throw; //ThreadAbortException should not be caught
}
}
if (!will_restart)
{
ConsoleInteractive.ConsoleReader.StopReadThread();
ConsoleInteractive.ConsoleReader.MessageReceived -= ConsoleReaderOnMessageReceived;
ConsoleInteractive.ConsoleReader.OnKeyInput -= ConsoleIO.AutocompleteHandler;
Program.HandleFailure();
}
}
#endregion
#region Command prompt and internal MCC commands
private void ConsoleReaderOnMessageReceived(object? sender, string e)
{
if (client.Client == null)
return;
if (client.Client.Connected)
{
new Thread(() =>
{
InvokeOnMainThread(() => HandleCommandPromptText(e));
}).Start();
}
else
return;
}
/// <summary>
/// Allows the user to send chat messages, commands, and leave the server.
/// Process text from the MCC command prompt on the main thread.
/// </summary>
private void HandleCommandPromptText(string text)
{
if (ConsoleIO.BasicIO && text.Length > 0 && text[0] == (char)0x00)
{
//Process a request from the GUI
2022-08-31 22:52:05 +08:00
string[] command = text[1..].Split((char)0x00);
switch (command[0].ToLower())
{
case "autocomplete":
if (command.Length > 1) { ConsoleIO.WriteLine((char)0x00 + "autocomplete" + (char)0x00 + handler.AutoComplete(command[1])); }
else ConsoleIO.WriteLine((char)0x00 + "autocomplete" + (char)0x00);
break;
}
}
else
{
text = text.Trim();
if (text.Length > 0)
{
if (Settings.internalCmdChar == ' ' || text[0] == Settings.internalCmdChar)
{
string response_msg = "";
string command = Settings.internalCmdChar == ' ' ? text : text.Substring(1);
if (!PerformInternalCommand(Settings.ExpandVars(command), ref response_msg) && Settings.internalCmdChar == '/')
{
SendText(text);
}
else if (response_msg.Length > 0)
{
Log.Info(response_msg);
}
}
else SendText(text);
}
}
}
/// <summary>
/// Register a custom console command
/// </summary>
/// <param name="cmdName">Name of the command</param>
/// <param name="cmdDesc">Description/usage of the command</param>
/// <param name="callback">Method for handling the command</param>
/// <returns>True if successfully registered</returns>
public bool RegisterCommand(string cmdName, string cmdDesc, string cmdUsage, ChatBot.CommandRunner callback)
{
if (cmds.ContainsKey(cmdName.ToLower()))
{
return false;
}
else
{
Command cmd = new ChatBot.ChatBotCommand(cmdName, cmdDesc, cmdUsage, callback);
cmds.Add(cmdName.ToLower(), cmd);
cmd_names.Add(cmdName.ToLower());
return true;
}
}
/// <summary>
/// Unregister a console command
/// </summary>
/// <remarks>
/// There is no check for the command is registered by above method or is embedded command.
/// Which mean this can unload any command
/// </remarks>
/// <param name="cmdName">The name of command to be unregistered</param>
/// <returns></returns>
public bool UnregisterCommand(string cmdName)
{
if (cmds.ContainsKey(cmdName.ToLower()))
{
cmds.Remove(cmdName.ToLower());
cmd_names.Remove(cmdName.ToLower());
return true;
}
else return false;
}
/// <summary>
/// Perform an internal MCC command (not a server command, use SendText() instead for that!)
/// </summary>
/// <param name="command">The command</param>
/// <param name="response_msg">May contain a confirmation or error message after processing the command, or "" otherwise.</param>
/// <param name="localVars">Local variables passed along with the command</param>
/// <returns>TRUE if the command was indeed an internal MCC command</returns>
public bool PerformInternalCommand(string command, ref string response_msg, Dictionary<string, object>? localVars = null)
{
/* Process the provided command */
string command_name = command.Split(' ')[0].ToLower();
if (command_name == "help")
{
if (Command.hasArg(command))
{
string help_cmdname = Command.getArgs(command)[0].ToLower();
if (help_cmdname == "help")
{
response_msg = Translations.Get("icmd.help");
}
else if (cmds.ContainsKey(help_cmdname))
{
response_msg = cmds[help_cmdname].GetCmdDescTranslated();
}
else response_msg = Translations.Get("icmd.unknown", command_name);
}
else response_msg = Translations.Get("icmd.list", String.Join(", ", cmd_names.ToArray()), Settings.internalCmdChar);
}
else if (cmds.ContainsKey(command_name))
{
response_msg = cmds[command_name].Run(this, command, localVars);
foreach (ChatBot bot in bots.ToArray())
{
try
{
bot.OnInternalCommand(command_name, string.Join(" ", Command.getArgs(command)), response_msg);
}
catch (Exception e)
{
if (!(e is ThreadAbortException))
{
Log.Warn(Translations.Get("icmd.error", bot.ToString(), e.ToString()));
}
else throw; //ThreadAbortException should not be caught
}
}
}
else
{
response_msg = Translations.Get("icmd.unknown", command_name);
return false;
}
return true;
}
public void LoadCommands()
{
/* Load commands from the 'Commands' namespace */
if (!commandsLoaded)
{
Type[] cmds_classes = Program.GetTypesInNamespace("MinecraftClient.Commands");
foreach (Type type in cmds_classes)
{
if (type.IsSubclassOf(typeof(Command)))
{
try
{
Command cmd = (Command)Activator.CreateInstance(type);
2022-08-31 18:00:00 +08:00
cmds[Settings.ToLowerIfNeed(cmd.CmdName)] = cmd;
cmd_names.Add(Settings.ToLowerIfNeed(cmd.CmdName));
foreach (string alias in cmd.getCMDAliases())
2022-08-31 18:00:00 +08:00
cmds[Settings.ToLowerIfNeed(alias)] = cmd;
}
catch (Exception e)
{
Log.Warn(e.Message);
}
}
}
commandsLoaded = true;
}
}
#endregion
#region Thread-Invoke: Cross-thread method calls
/// <summary>
/// Invoke a task on the main thread, wait for completion and retrieve return value.
/// </summary>
/// <param name="task">Task to run with any type or return value</param>
/// <returns>Any result returned from task, result type is inferred from the task</returns>
/// <example>bool result = InvokeOnMainThread(methodThatReturnsAbool);</example>
/// <example>bool result = InvokeOnMainThread(() => methodThatReturnsAbool(argument));</example>
/// <example>int result = InvokeOnMainThread(() => { yourCode(); return 42; });</example>
/// <typeparam name="T">Type of the return value</typeparam>
public T InvokeOnMainThread<T>(Func<T> task)
{
if (!InvokeRequired)
{
return task();
}
else
{
TaskWithResult<T> taskWithResult = new TaskWithResult<T>(task);
lock (threadTasksLock)
{
threadTasks.Enqueue(taskWithResult.ExecuteSynchronously);
}
return taskWithResult.WaitGetResult();
}
}
/// <summary>
/// Invoke a task on the main thread and wait for completion
/// </summary>
/// <param name="task">Task to run without return value</param>
/// <example>InvokeOnMainThread(methodThatReturnsNothing);</example>
/// <example>InvokeOnMainThread(() => methodThatReturnsNothing(argument));</example>
/// <example>InvokeOnMainThread(() => { yourCode(); });</example>
public void InvokeOnMainThread(Action task)
{
InvokeOnMainThread(() => { task(); return true; });
}
/// <summary>
/// Clear all tasks
/// </summary>
public void ClearTasks()
{
lock (threadTasksLock)
{
threadTasks.Clear();
}
}
/// <summary>
/// Check if running on a different thread and InvokeOnMainThread is required
/// </summary>
/// <returns>True if calling thread is not the main thread</returns>
public bool InvokeRequired
{
get
{
int callingThreadId = Thread.CurrentThread.ManagedThreadId;
if (handler != null)
{
return handler.GetNetMainThreadId() != callingThreadId;
}
else
{
// net read thread (main thread) not yet ready
return false;
}
}
}
#endregion
#region Management: Load/Unload ChatBots and Enable/Disable settings
/// <summary>
/// Load a new bot
/// </summary>
public void BotLoad(ChatBot b, bool init = true)
{
if (InvokeRequired)
{
InvokeOnMainThread(() => BotLoad(b, init));
return;
}
b.SetHandler(this);
bots.Add(b);
if (init)
DispatchBotEvent(bot => bot.Initialize(), new ChatBot[] { b });
if (this.handler != null)
DispatchBotEvent(bot => bot.AfterGameJoined(), new ChatBot[] { b });
Settings.SingleCommand = "";
}
/// <summary>
/// Unload a bot
/// </summary>
public void BotUnLoad(ChatBot b)
{
if (InvokeRequired)
{
InvokeOnMainThread(() => BotUnLoad(b));
return;
}
bots.RemoveAll(item => object.ReferenceEquals(item, b));
// ToList is needed to avoid an InvalidOperationException from modfiying the list while it's being iterated upon.
var botRegistrations = registeredBotPluginChannels.Where(entry => entry.Value.Contains(b)).ToList();
foreach (var entry in botRegistrations)
{
UnregisterPluginChannel(entry.Key, b);
}
}
/// <summary>
/// Clear bots
/// </summary>
public void BotClear()
{
InvokeOnMainThread(bots.Clear);
}
/// <summary>
/// Get Terrain and Movements status.
/// </summary>
public bool GetTerrainEnabled()
{
return terrainAndMovementsEnabled;
}
/// <summary>
/// Get Inventory Handling Mode
/// </summary>
public bool GetInventoryEnabled()
{
return inventoryHandlingEnabled;
}
/// <summary>
/// Get entity handling status
/// </summary>
/// <returns></returns>
/// <remarks>Entity Handling cannot be enabled in runtime (or after joining server)</remarks>
public bool GetEntityHandlingEnabled()
{
return entityHandlingEnabled;
}
/// <summary>
/// Enable or disable Terrain and Movements.
/// Please note that Enabling will be deferred until next relog, respawn or world change.
/// </summary>
/// <param name="enabled">Enabled</param>
/// <returns>TRUE if the setting was applied immediately, FALSE if delayed.</returns>
public bool SetTerrainEnabled(bool enabled)
{
if (InvokeRequired)
return InvokeOnMainThread(() => SetTerrainEnabled(enabled));
if (enabled)
{
if (!terrainAndMovementsEnabled)
{
terrainAndMovementsRequested = true;
return false;
}
}
else
{
terrainAndMovementsEnabled = false;
terrainAndMovementsRequested = false;
locationReceived = false;
world.Clear();
}
return true;
}
/// <summary>
/// Enable or disable Inventories.
/// Please note that Enabling will be deferred until next relog.
/// </summary>
/// <param name="enabled">Enabled</param>
/// <returns>TRUE if the setting was applied immediately, FALSE if delayed.</returns>
public bool SetInventoryEnabled(bool enabled)
{
if (InvokeRequired)
return InvokeOnMainThread(() => SetInventoryEnabled(enabled));
if (enabled)
{
if (!inventoryHandlingEnabled)
{
inventoryHandlingRequested = true;
return false;
}
}
else
{
inventoryHandlingEnabled = false;
inventoryHandlingRequested = false;
inventories.Clear();
}
return true;
}
/// <summary>
/// Enable or disable Entity handling.
/// Please note that Enabling will be deferred until next relog.
/// </summary>
/// <param name="enabled">Enabled</param>
/// <returns>TRUE if the setting was applied immediately, FALSE if delayed.</returns>
public bool SetEntityHandlingEnabled(bool enabled)
{
if (InvokeRequired)
return InvokeOnMainThread(() => SetEntityHandlingEnabled(enabled));
if (!enabled)
{
if (entityHandlingEnabled)
{
entityHandlingEnabled = false;
return true;
}
else
{
return false;
}
}
else
{
// Entity Handling cannot be enabled in runtime (or after joining server)
return false;
}
}
/// <summary>
/// Enable or disable network packet event calling.
/// </summary>
/// <remarks>
/// Enable this may increase memory usage.
/// </remarks>
/// <param name="enabled"></param>
public void SetNetworkPacketCaptureEnabled(bool enabled)
{
if (InvokeRequired)
{
InvokeOnMainThread(() => SetNetworkPacketCaptureEnabled(enabled));
return;
}
networkPacketCaptureEnabled = enabled;
}
#endregion
#region Getters: Retrieve data for use in other methods or ChatBots
Add Mailer bot (#1108) * Update for the mail script. As requested, I added the synchronization between the config debugmessage bool and the one in the script. Furthermore, I added a way to send anonymous mails by writing "tellonym". The messages are saved as normal mails, which lets them count to the mail cap, due to the fact that the host knows the sender. I added the script to the chat bots because of the problems, that the scripts have with serialization. Instead of rewriting the whole serialization part, my idea was to add the script to the other chat bots, to avoid the compiling issues. Then the serialization would work perfectly fine. Then you could remove the option class at some point and move all the settings to the config file with the addition to activate the whole script. * Correction of debug message loading. The object was missing and the change would be overridden a few lines later. * Update McClient.cs * Add Mail to config file * Correcting the safe file. * Small correction of Settings.c * Update Mailscript Added a failsafe version of the path changing commands. If a path could not be found, an error will be created and the path will be reseted to standart, to avoid endless chains of errors. * Fix for the mail script Removed a wrong option call. Removed the debug_msg condition around the path functions. => Users are aware of what happened (if they see the error) although they turned off debug_msg. * Added some features. Added a try statement to all number changing commands. Added a command to list all moderators to the console. * Serialization Fix There was a chance, that if two bots work on one file, and two users send messages in a short time period, that one bot deserializes the message and then the other bot deserialize the same file, before the other one could save its changes. This would lead to one message disappearing, because one bot never deserialized this message. For this I changed the whole serialization process. All changes are now committed after the interval and not after an incoming mail command directly. All mails are safed temporarily in cache and get serialized after the interval. Due to this changes, you can determit when the individual bot changes the file (there are no more direct interactions with the file after a command, which lead to a certain randomness). Furthermore you can now set an interval of e.g. 2 mins and reset the interval of one bot with "resettimer" after one minute so that the bots won't disturb eachother and no files get lost. * My idea of a manual. This is my idea of a manual for the bot. Improvements of my language / further ideas are welcome! :D * addIgnored [NAME] and removeIgnored[NAME] Added an ignored list. Moderators can add players to the list. The bot won't react to them and just log to the console that they are ignored, everytime they are sending a message, to ensure that they are not accidently ignored. (Just if debug_msg is active.) Especially useful if there are other chat bots on the server, which spam many messages that aren't useful for the mail system. Or block spammers etc. * Add the three commands to the manual. Added addignored, removeignored and getignored to the manual. * Remove moderators. Implement Console Control. Due to security concerns, I converted all moderator commands to console internal commands. Thereby only the host can change crucial settings. Special thanks to ORelio for the hint! * Added empty statement check Added if to all commands, where the syntax is not already protected by a try, so that an incorrect syntax (Empty args[] due to missing statement) won't crash the script. * Changed the serialization fail If the programm can't safe the file, because of some strange character for instance, it first tries to change the path back to normal and if this not helps, it creates a new, file. * toggle mail sending/receiving Add an option to turn mailsending and the listening to commands in chat on/off. * Updated manual. - Removed moderator commands. - Removed moderator part in the network manual + added the two new commands + added a waring for nick plugins and minecraft renames + added a small syntax example * Updated the Settings.cs file. * Smaller fixes and additions + improved command reading of 'mail' & 'tellonym' + sorted internal commands alphabetically + host can set a maximum message length + host can accept commands from public chat + host can decide if 'self mailing' (mailing yourself) is accepted + new order makes 'getsettings' easier to read + new internal commands to toggle 'publiccommands' and 'selfmailing' as well as the maximum mail size - removed the old command interpreter * Small improvements and additions Added a few commands and settings * Completing getsettings + added 'publiccomands' * Completed getsettings + Added 'publiccommand' to 'getsettings' * Removed single bolean, added Dictionary - removed all boleans in the option class - removed all functions relating them + added Dictionary for the booleans + added a single function to set/toggle all booleans * Removed Commands, added interpreter - Removed all Register commands - removed all integer methods + added a single mail command + added integer dictionary + added integer handling similar like bool handling * Small fix + Changed the numbers in several methods to adjust them to the new syntax. - removed parameters in several methods, because they got unneccesary * Even smaller fix + Sorted 'getsettings' alphabetically + corrected a typo * New Serialization method. Now serializing through the .INI format! Thanks to ORelio, who helped me a lot! :) * Added different time Added the option to switch between utc and the time of the local machine for timestamps. * Made timeinutc serializable Added the bool to the serialization method. * Adding the INIFile.cs For Dictionary serialization. * Reworked ignore feature Ignored players are now serialized in a file and reloaded, after the bot enters a server. * Mailer bot refactoring Rename Mail to Mailer Move options to MinecraftClient.ini Make the bot much simpler by removing some settings Create specific MailDatabase and IgnoreList classes However the core functionality for users is the same Settings removed: - allow_sendmail: Cannot use Mailer if it's disabled - allow_receivemail: Cannot use Mailer if it's disabled - path_setting: Settings moved to MinecraftClient.ini - debug_msg: MCC already has a setting for that with LogDebugToConsole() - auto_respawn: MCC already has a built-in auto-respawn feature - allow_selfmail: Is it really necessary to block self mails? ;) - maxcharsinmsg: Automatically calculated based on max chat message length - timeinutc: DateTime is not show to the recipient so I think it's not absolutely necessary - interval_sendmail: Set to 10 seconds for now Internal Commands removed: - changemailpath: Now a static setting in config - changesettingspath: Now a static setting in config - updatemails: Already updated every 10 seconds - getsettings: Shown on startup with debugmessages=true - resettimer: Seems only useful for debugging - setbool: Settings are static in config file - setinteger: Settings are static in config file All user commands are retained: - mail - tellonym * Reload database for mailer network feature * Merge Mail documentation to Readme.md Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-08-03 21:44:39 +02:00
/// <summary>
/// Get max length for chat messages
/// </summary>
/// <returns>Max length, in characters</returns>
public int GetMaxChatMessageLength()
{
return handler.GetMaxChatMessageLength();
}
/// <summary>
/// Get a list of disallowed characters in chat
/// </summary>
/// <returns></returns>
public static char[] GetDisallowedChatCharacters()
{
return new char[] { (char)167, (char)127 }; // Minecraft color code and ASCII code DEL
}
/// <summary>
/// Get all inventories. ID 0 is the player inventory.
/// </summary>
/// <returns>All inventories</returns>
public Dictionary<int, Container> GetInventories()
{
return inventories;
}
ChatBot API: OnScoreboardObjective, OnEntityEffect, OnUpdateScore, EntityInteract, Hand list (#1097) * Create Effect.cs * Rename Effect.cs to Effects.cs * Update MinecraftClient.csproj * Update Effects.cs * Update Effects.cs * add EntityEffect * Update McClient.cs * Update Protocol18.cs + EntityEffect * Update IMinecraftComHandler.cs * Update Protocol18PacketTypes.cs + EntityEffect * Update ChatBot.cs + OnEntityEquipment * Update PacketIncomingType.cs + ScoreboardObjective * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnScoreboardObjective * Update McClient.cs + OnScoreboardObjective * Update ChatBot.cs + OnScoreboardObjective event * Update Protocol18.cs: fix scoreboard * Update McClient.cs * Update ChatBot.cs * Update PacketIncomingType.cs * Update ChatBot.cs + OnUpdateScore * Update McClient.cs + OnUpdateScore * Update IMinecraftComHandler.cs + OnUpdateScore * Update Protocol18.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs + fix micro lags * Update Protocol18.cs * Update Protocol18.cs * Update Protocol18.cs * Update Protocol16.cs * Update Protocol18.cs * Update McClient.cs * Update IMinecraftCom.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs + GetEntities() * Create Hand.cs * Update MinecraftClient.csproj * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs: fix * Update AutoAttack.cs: Fix * Update McClient.cs: compile fix * Update ChatBot.cs * Update AutoAttack.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McClient.cs * Update McClient.cs: remove check distance * Update EntityActionType.cs: more actions * Create CommandBlockMode.cs * Create CommandBlockFlags.cs * Update IMinecraftCom.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update Protocol16.cs * Update PacketOutgoingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs
2020-07-04 13:45:51 +05:00
/// <summary>
/// Get all Entities
ChatBot API: OnScoreboardObjective, OnEntityEffect, OnUpdateScore, EntityInteract, Hand list (#1097) * Create Effect.cs * Rename Effect.cs to Effects.cs * Update MinecraftClient.csproj * Update Effects.cs * Update Effects.cs * add EntityEffect * Update McClient.cs * Update Protocol18.cs + EntityEffect * Update IMinecraftComHandler.cs * Update Protocol18PacketTypes.cs + EntityEffect * Update ChatBot.cs + OnEntityEquipment * Update PacketIncomingType.cs + ScoreboardObjective * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnScoreboardObjective * Update McClient.cs + OnScoreboardObjective * Update ChatBot.cs + OnScoreboardObjective event * Update Protocol18.cs: fix scoreboard * Update McClient.cs * Update ChatBot.cs * Update PacketIncomingType.cs * Update ChatBot.cs + OnUpdateScore * Update McClient.cs + OnUpdateScore * Update IMinecraftComHandler.cs + OnUpdateScore * Update Protocol18.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs + fix micro lags * Update Protocol18.cs * Update Protocol18.cs * Update Protocol18.cs * Update Protocol16.cs * Update Protocol18.cs * Update McClient.cs * Update IMinecraftCom.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs + GetEntities() * Create Hand.cs * Update MinecraftClient.csproj * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs: fix * Update AutoAttack.cs: Fix * Update McClient.cs: compile fix * Update ChatBot.cs * Update AutoAttack.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McClient.cs * Update McClient.cs: remove check distance * Update EntityActionType.cs: more actions * Create CommandBlockMode.cs * Create CommandBlockFlags.cs * Update IMinecraftCom.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update Protocol16.cs * Update PacketOutgoingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs
2020-07-04 13:45:51 +05:00
/// </summary>
/// <returns>All Entities</returns>
public Dictionary<int, Entity> GetEntities()
{
return entities;
}
/// <summary>
/// Get all players latency
/// </summary>
/// <returns>All players latency</returns>
public Dictionary<string, int> GetPlayersLatency()
{
Dictionary<string, int> playersLatency = new();
foreach (var player in onlinePlayers)
playersLatency.Add(player.Value.Name, player.Value.Ping);
return playersLatency;
}
/// <summary>
/// Get client player's inventory items
/// </summary>
/// <param name="inventoryID">Window ID of the requested inventory</param>
/// <returns> Item Dictionary indexed by Slot ID (Check wiki.vg for slot ID)</returns>
public Container GetInventory(int inventoryID)
{
if (InvokeRequired)
return InvokeOnMainThread(() => GetInventory(inventoryID));
if (inventories.ContainsKey(inventoryID))
return inventories[inventoryID];
return null;
}
/// <summary>
/// Get client player's inventory items
/// </summary>
/// <returns> Item Dictionary indexed by Slot ID (Check wiki.vg for slot ID)</returns>
public Container GetPlayerInventory()
{
return GetInventory(0);
}
/// <summary>
/// Get a set of online player names
/// </summary>
/// <returns>Online player names</returns>
public string[] GetOnlinePlayers()
{
lock (onlinePlayers)
{
string[] playerNames = new string[onlinePlayers.Count];
int idx = 0;
foreach (var player in onlinePlayers)
playerNames[idx++] = player.Value.Name;
return playerNames;
}
}
/// <summary>
/// Get a dictionary of online player names and their corresponding UUID
/// </summary>
/// <returns>Dictionay of online players, key is UUID, value is Player name</returns>
public Dictionary<string, string> GetOnlinePlayersWithUUID()
{
Dictionary<string, string> uuid2Player = new Dictionary<string, string>();
lock (onlinePlayers)
{
foreach (Guid key in onlinePlayers.Keys)
{
uuid2Player.Add(key.ToString(), onlinePlayers[key].Name);
}
}
return uuid2Player;
}
/// <summary>
/// Get player info from uuid
/// </summary>
/// <param name="uuid">Player's UUID</param>
/// <returns>Player info</returns>
public PlayerInfo? GetPlayerInfo(Guid uuid)
{
lock (onlinePlayers)
{
if (onlinePlayers.ContainsKey(uuid))
return onlinePlayers[uuid];
else
return null;
}
}
#endregion
#region Action methods: Perform an action on the Server
/// <summary>
/// Move to the specified location
/// </summary>
/// <param name="location">Location to reach</param>
/// <param name="allowUnsafe">Allow possible but unsafe locations thay may hurt the player: lava, cactus...</param>
/// <param name="allowDirectTeleport">Allow non-vanilla direct teleport instead of computing path, but may cause invalid moves and/or trigger anti-cheat plugins</param>
/// <param name="maxOffset">If no valid path can be found, also allow locations within specified distance of destination</param>
/// <param name="minOffset">Do not get closer of destination than specified distance</param>
/// <param name="timeout">How long to wait until the path is evaluated (default: 5 seconds)</param>
/// <remarks>When location is unreachable, computation will reach timeout, then optionally fallback to a close location within maxOffset</remarks>
/// <returns>True if a path has been found</returns>
public bool MoveTo(Location location, bool allowUnsafe = false, bool allowDirectTeleport = false, int maxOffset = 0, int minOffset = 0, TimeSpan? timeout = null)
{
lock (locationLock)
{
if (allowDirectTeleport)
{
// 1-step path to the desired location without checking anything
UpdateLocation(location, location); // Update yaw and pitch to look at next step
handler.SendLocationUpdate(location, Movement.IsOnGround(world, location), _yaw, _pitch);
return true;
}
else
{
// Calculate path through pathfinding. Path contains a list of 1-block movement that will be divided into steps
Rework of MineCube.cs and further improvements to CalculatePath() (#2014) * Add function to determine if the client is executing a walking process * Add comments * Remove test bot entry * Add funtion to approach a block as close as possible * Add funtion to approach a block as close as possible * Add funtion to approach a block as close as possible * Add comment to function in McClient.cs * Improve concurrency and reduce potential calculation power * Apply code suggestions * Apply code suggestions * Improve CalculatePath() function to allow approaching * Fix typo in MinecraftClient/ChatBot.cs * Add comments to Chatbot fucntion * Add break to for loop to exit quicker * Allow to give a maxOffset to the goal * Comment the sample bot again. * Add parameter for calculation timeout * Remove TestBot again * Implement timeout in Chatbot class * Remove test commands * Update comment in Chatbot.cs * Set timeout to default 5 sec * Change order of parameters back * Add suggested improvements * Move task and fix missing methods in .NET 4.0 * Create switch for tool handling * Remove unused function * Improve movement * Improve performance of CalculatePath() - Replace Hashset OpenSet with a Binary Heap - Temporary remove maxOffset / minOffset features - Round start location for easier calculation - Add 0.5 to each location in reconstruct path to avoid getting stuck on edges * Add diagonal movement * Remove direct block movement - causes kick for invalid packet movement if moving on the block you are currently standing on * Floor start in A* and improve diagonal walking check * Add helperfunctions to McClient.cs * Prevent client from falling into danger * Add comment to function and remove dependencies * Add comments * Remove debug settings Co-authored-by: ORelio <ORelio@users.noreply.github.com>
2022-08-15 18:26:40 +02:00
path = Movement.CalculatePath(world, this.location, location, allowUnsafe, maxOffset, minOffset, timeout ?? TimeSpan.FromSeconds(5));
return path != null;
}
}
}
/// <summary>
/// Send a chat message or command to the server
/// </summary>
/// <param name="text">Text to send to the server</param>
public void SendText(string text)
{
2022-09-02 09:29:24 +08:00
if (String.IsNullOrEmpty(text))
return;
int maxLength = handler.GetMaxChatMessageLength();
lock (chatQueue)
{
if (text.Length > maxLength) //Message is too long?
{
if (text[0] == '/')
{
//Send the first 100/256 chars of the command
2022-09-02 09:29:24 +08:00
text = text[..maxLength];
chatQueue.Enqueue(text);
}
else
{
//Split the message into several messages
while (text.Length > maxLength)
{
2022-09-02 09:29:24 +08:00
chatQueue.Enqueue(text[..maxLength]);
text = text[maxLength..];
}
chatQueue.Enqueue(text);
}
}
2022-09-02 09:29:24 +08:00
else
chatQueue.Enqueue(text);
2022-08-31 22:52:05 +08:00
TrySendMessageToServer();
}
}
/// <summary>
/// Allow to respawn after death
/// </summary>
/// <returns>True if packet successfully sent</returns>
public bool SendRespawnPacket()
{
if (InvokeRequired)
return InvokeOnMainThread<bool>(SendRespawnPacket);
return handler.SendRespawnPacket();
}
/// <summary>
/// Registers the given plugin channel for the given bot.
/// </summary>
/// <param name="channel">The channel to register.</param>
/// <param name="bot">The bot to register the channel for.</param>
public void RegisterPluginChannel(string channel, ChatBot bot)
{
if (InvokeRequired)
{
InvokeOnMainThread(() => RegisterPluginChannel(channel, bot));
return;
}
if (registeredBotPluginChannels.ContainsKey(channel))
{
registeredBotPluginChannels[channel].Add(bot);
}
else
{
List<ChatBot> bots = new List<ChatBot>();
bots.Add(bot);
registeredBotPluginChannels[channel] = bots;
SendPluginChannelMessage("REGISTER", Encoding.UTF8.GetBytes(channel), true);
}
}
/// <summary>
/// Unregisters the given plugin channel for the given bot.
/// </summary>
/// <param name="channel">The channel to unregister.</param>
/// <param name="bot">The bot to unregister the channel for.</param>
public void UnregisterPluginChannel(string channel, ChatBot bot)
{
if (InvokeRequired)
{
InvokeOnMainThread(() => UnregisterPluginChannel(channel, bot));
return;
}
if (registeredBotPluginChannels.ContainsKey(channel))
{
List<ChatBot> registeredBots = registeredBotPluginChannels[channel];
registeredBots.RemoveAll(item => object.ReferenceEquals(item, bot));
if (registeredBots.Count == 0)
{
registeredBotPluginChannels.Remove(channel);
SendPluginChannelMessage("UNREGISTER", Encoding.UTF8.GetBytes(channel), true);
}
}
}
/// <summary>
/// Sends a plugin channel packet to the server. See http://wiki.vg/Plugin_channel for more information
/// about plugin channels.
/// </summary>
/// <param name="channel">The channel to send the packet on.</param>
/// <param name="data">The payload for the packet.</param>
/// <param name="sendEvenIfNotRegistered">Whether the packet should be sent even if the server or the client hasn't registered it yet.</param>
/// <returns>Whether the packet was sent: true if it was sent, false if there was a connection error or it wasn't registered.</returns>
public bool SendPluginChannelMessage(string channel, byte[] data, bool sendEvenIfNotRegistered = false)
{
if (InvokeRequired)
return InvokeOnMainThread(() => SendPluginChannelMessage(channel, data, sendEvenIfNotRegistered));
if (!sendEvenIfNotRegistered)
{
if (!registeredBotPluginChannels.ContainsKey(channel))
{
return false;
}
if (!registeredServerPluginChannels.Contains(channel))
{
return false;
}
}
return handler.SendPluginChannelPacket(channel, data);
}
/// <summary>
/// Send the Entity Action packet with the Specified ID
/// </summary>
/// <returns>TRUE if the item was successfully used</returns>
public bool SendEntityAction(EntityActionType entityAction)
{
return InvokeOnMainThread(() => handler.SendEntityAction(playerEntityID, (int)entityAction));
}
/// <summary>
/// Use the item currently in the player's hand
/// </summary>
/// <returns>TRUE if the item was successfully used</returns>
public bool UseItemOnHand()
{
return InvokeOnMainThread(() => handler.SendUseItem(0, this.sequenceId));
}
/// <summary>
/// Click a slot in the specified window
/// </summary>
/// <returns>TRUE if the slot was successfully clicked</returns>
public bool DoWindowAction(int windowId, int slotId, WindowActionType action)
{
if (InvokeRequired)
return InvokeOnMainThread(() => DoWindowAction(windowId, slotId, action));
Item item = null;
if (inventories.ContainsKey(windowId) && inventories[windowId].Items.ContainsKey(slotId))
item = inventories[windowId].Items[slotId];
2022-07-25 01:13:41 +08:00
List<Tuple<short, Item>> changedSlots = new List<Tuple<short, Item>>(); // List<Slot ID, Changed Items>
// Update our inventory base on action type
var inventory = GetInventory(windowId);
var playerInventory = GetInventory(0);
if (inventory != null)
{
switch (action)
{
case WindowActionType.LeftClick:
// Check if cursor have item (slot -1)
if (playerInventory.Items.ContainsKey(-1))
{
// When item on cursor and clicking slot 0, nothing will happen
if (slotId == 0) break;
// Check target slot also have item?
if (inventory.Items.ContainsKey(slotId))
{
// Check if both item are the same?
if (inventory.Items[slotId].Type == playerInventory.Items[-1].Type)
{
int maxCount = inventory.Items[slotId].Type.StackCount();
// Check item stacking
if ((inventory.Items[slotId].Count + playerInventory.Items[-1].Count) <= maxCount)
{
// Put cursor item to target
inventory.Items[slotId].Count += playerInventory.Items[-1].Count;
playerInventory.Items.Remove(-1);
}
else
{
// Leave some item on cursor
playerInventory.Items[-1].Count -= (maxCount - inventory.Items[slotId].Count);
inventory.Items[slotId].Count = maxCount;
}
}
else
{
// Swap two items
var itemTmp = playerInventory.Items[-1];
playerInventory.Items[-1] = inventory.Items[slotId];
inventory.Items[slotId] = itemTmp;
}
}
else
{
// Put cursor item to target
inventory.Items[slotId] = playerInventory.Items[-1];
playerInventory.Items.Remove(-1);
}
2022-07-25 01:13:41 +08:00
if (inventory.Items.ContainsKey(slotId))
changedSlots.Add(new Tuple<short, Item>((short)slotId, inventory.Items[slotId]));
else
changedSlots.Add(new Tuple<short, Item>((short)slotId, null));
}
else
{
// Check target slot have item?
if (inventory.Items.ContainsKey(slotId))
{
// When taking item from slot 0, server will update us
if (slotId == 0) break;
// Put target slot item to cursor
playerInventory.Items[-1] = inventory.Items[slotId];
inventory.Items.Remove(slotId);
2022-07-25 01:13:41 +08:00
changedSlots.Add(new Tuple<short, Item>((short)slotId, null));
}
}
break;
case WindowActionType.RightClick:
// Check if cursor have item (slot -1)
if (playerInventory.Items.ContainsKey(-1))
{
// When item on cursor and clicking slot 0, nothing will happen
if (slotId == 0) break;
// Check target slot have item?
if (inventory.Items.ContainsKey(slotId))
{
// Check if both item are the same?
if (inventory.Items[slotId].Type == playerInventory.Items[-1].Type)
{
// Check item stacking
if (inventory.Items[slotId].Count < inventory.Items[slotId].Type.StackCount())
{
// Drop 1 item count from cursor
playerInventory.Items[-1].Count--;
inventory.Items[slotId].Count++;
}
}
else
{
// Swap two items
var itemTmp = playerInventory.Items[-1];
playerInventory.Items[-1] = inventory.Items[slotId];
inventory.Items[slotId] = itemTmp;
}
}
else
{
// Drop 1 item count from cursor
var itemTmp = playerInventory.Items[-1];
var itemClone = new Item(itemTmp.Type, 1, itemTmp.NBT);
inventory.Items[slotId] = itemClone;
playerInventory.Items[-1].Count--;
}
}
else
{
// Check target slot have item?
if (inventory.Items.ContainsKey(slotId))
{
if (slotId == 0)
{
// no matter how many item in slot 0, only 1 will be taken out
// Also server will update us
break;
}
if (inventory.Items[slotId].Count == 1)
{
// Only 1 item count. Put it to cursor
playerInventory.Items[-1] = inventory.Items[slotId];
inventory.Items.Remove(slotId);
}
else
{
// Take half of the item stack to cursor
if (inventory.Items[slotId].Count % 2 == 0)
{
// Can be evenly divided
Item itemTmp = inventory.Items[slotId];
playerInventory.Items[-1] = new Item(itemTmp.Type, itemTmp.Count / 2, itemTmp.NBT);
inventory.Items[slotId].Count = itemTmp.Count / 2;
}
else
{
// Cannot be evenly divided. item count on cursor is always larger than item on inventory
Item itemTmp = inventory.Items[slotId];
playerInventory.Items[-1] = new Item(itemTmp.Type, (itemTmp.Count + 1) / 2, itemTmp.NBT);
inventory.Items[slotId].Count = (itemTmp.Count - 1) / 2;
}
}
}
}
if (inventory.Items.ContainsKey(slotId))
changedSlots.Add(new Tuple<short, Item>((short)slotId, inventory.Items[slotId]));
else
changedSlots.Add(new Tuple<short, Item>((short)slotId, null));
break;
case WindowActionType.ShiftClick:
if (slotId == 0) break;
if (inventory.Items.ContainsKey(slotId))
{
/* Target slot have item */
int upperStartSlot = 9;
int upperEndSlot = 35;
switch (inventory.Type)
{
case ContainerType.PlayerInventory:
upperStartSlot = 9;
upperEndSlot = 35;
break;
case ContainerType.Crafting:
upperStartSlot = 1;
upperEndSlot = 9;
break;
// TODO: Define more container type here
}
// Cursor have item or not doesn't matter
// If hotbar already have same item, will put on it first until every stack are full
// If no more same item , will put on the first empty slot (smaller slot id)
// If inventory full, item will not move
2022-07-25 01:13:41 +08:00
int itemCount = inventory.Items[slotId].Count;
if (slotId <= upperEndSlot)
{
// Clicked slot is on upper side inventory, put it to hotbar
// Now try to find same item and put on them
var itemsClone = playerInventory.Items.ToDictionary(entry => entry.Key, entry => entry.Value);
foreach (KeyValuePair<int, Item> _item in itemsClone)
{
if (_item.Key <= upperEndSlot) continue;
int maxCount = _item.Value.Type.StackCount();
if (_item.Value.Type == inventory.Items[slotId].Type && _item.Value.Count < maxCount)
2020-07-09 14:30:24 +08:00
{
// Put item on that stack
int spaceLeft = maxCount - _item.Value.Count;
if (inventory.Items[slotId].Count <= spaceLeft)
2020-07-09 14:30:24 +08:00
{
// Can fit into the stack
inventory.Items[_item.Key].Count += inventory.Items[slotId].Count;
inventory.Items.Remove(slotId);
2022-07-25 01:13:41 +08:00
changedSlots.Add(new Tuple<short, Item>((short)_item.Key, inventory.Items[_item.Key]));
changedSlots.Add(new Tuple<short, Item>((short)slotId, null));
}
else
{
inventory.Items[slotId].Count -= spaceLeft;
inventory.Items[_item.Key].Count = inventory.Items[_item.Key].Type.StackCount();
2022-07-25 01:13:41 +08:00
changedSlots.Add(new Tuple<short, Item>((short)_item.Key, inventory.Items[_item.Key]));
2020-07-09 14:30:24 +08:00
}
}
}
if (inventory.Items[slotId].Count > 0)
{
int[] emptySlots = inventory.GetEmpytSlots();
int emptySlot = -2;
foreach (int slot in emptySlots)
{
if (slot <= upperEndSlot) continue;
emptySlot = slot;
break;
}
if (emptySlot != -2)
{
var itemTmp = inventory.Items[slotId];
inventory.Items[emptySlot] = new Item(itemTmp.Type, itemTmp.Count, itemTmp.NBT);
inventory.Items.Remove(slotId);
2022-07-25 01:13:41 +08:00
changedSlots.Add(new Tuple<short, Item>((short)emptySlot, inventory.Items[emptySlot]));
changedSlots.Add(new Tuple<short, Item>((short)slotId, null));
}
else if (inventory.Items[slotId].Count != itemCount)
{
changedSlots.Add(new Tuple<short, Item>((short)slotId, inventory.Items[slotId]));
}
}
}
else
{
// Clicked slot is on hotbar, put it to upper inventory
// Now try to find same item and put on them
var itemsClone = playerInventory.Items.ToDictionary(entry => entry.Key, entry => entry.Value);
foreach (KeyValuePair<int, Item> _item in itemsClone)
{
if (_item.Key < upperStartSlot) continue;
if (_item.Key >= upperEndSlot) break;
2020-07-09 14:30:24 +08:00
int maxCount = _item.Value.Type.StackCount();
if (_item.Value.Type == inventory.Items[slotId].Type && _item.Value.Count < maxCount)
{
// Put item on that stack
int spaceLeft = maxCount - _item.Value.Count;
if (inventory.Items[slotId].Count <= spaceLeft)
{
// Can fit into the stack
inventory.Items[_item.Key].Count += inventory.Items[slotId].Count;
inventory.Items.Remove(slotId);
2022-07-25 01:13:41 +08:00
changedSlots.Add(new Tuple<short, Item>((short)_item.Key, inventory.Items[_item.Key]));
changedSlots.Add(new Tuple<short, Item>((short)slotId, null));
}
else
{
inventory.Items[slotId].Count -= spaceLeft;
inventory.Items[_item.Key].Count = inventory.Items[_item.Key].Type.StackCount();
2022-07-25 01:13:41 +08:00
changedSlots.Add(new Tuple<short, Item>((short)_item.Key, inventory.Items[_item.Key]));
}
2020-07-09 14:30:24 +08:00
}
}
if (inventory.Items[slotId].Count > 0)
{
int[] emptySlots = inventory.GetEmpytSlots();
int emptySlot = -2;
foreach (int slot in emptySlots)
{
if (slot < upperStartSlot) continue;
if (slot >= upperEndSlot) break;
emptySlot = slot;
break;
}
if (emptySlot != -2)
{
var itemTmp = inventory.Items[slotId];
inventory.Items[emptySlot] = new Item(itemTmp.Type, itemTmp.Count, itemTmp.NBT);
inventory.Items.Remove(slotId);
2022-07-25 01:13:41 +08:00
changedSlots.Add(new Tuple<short, Item>((short)emptySlot, inventory.Items[emptySlot]));
changedSlots.Add(new Tuple<short, Item>((short)slotId, null));
}
else if (inventory.Items[slotId].Count != itemCount)
{
changedSlots.Add(new Tuple<short, Item>((short)slotId, inventory.Items[slotId]));
}
}
2020-07-09 14:30:24 +08:00
}
}
break;
case WindowActionType.DropItem:
if (inventory.Items.ContainsKey(slotId))
{
inventory.Items[slotId].Count--;
changedSlots.Add(new Tuple<short, Item>((short)slotId, inventory.Items[slotId]));
}
if (inventory.Items[slotId].Count <= 0)
{
inventory.Items.Remove(slotId);
changedSlots.Add(new Tuple<short, Item>((short)slotId, null));
}
2022-07-25 01:13:41 +08:00
break;
case WindowActionType.DropItemStack:
inventory.Items.Remove(slotId);
2022-07-25 01:13:41 +08:00
changedSlots.Add(new Tuple<short, Item>((short)slotId, null));
break;
}
}
2022-07-25 01:13:41 +08:00
return handler.SendWindowAction(windowId, slotId, action, item, changedSlots, inventories[windowId].StateID);
}
/// <summary>
/// Give Creative Mode items into regular/survival Player Inventory
/// </summary>
/// <remarks>(obviously) requires to be in creative mode</remarks>
/// <param name="slot">Destination inventory slot</param>
/// <param name="itemType">Item type</param>
/// <param name="count">Item count</param>
/// <param name="nbt">Item NBT</param>
/// <returns>TRUE if item given successfully</returns>
public bool DoCreativeGive(int slot, ItemType itemType, int count, Dictionary<string, object>? nbt = null)
{
return InvokeOnMainThread(() => handler.SendCreativeInventoryAction(slot, itemType, count, nbt));
}
/// <summary>
/// Plays animation (Player arm swing)
/// </summary>
/// <param name="animation">0 for left arm, 1 for right arm</param>
/// <returns>TRUE if animation successfully done</returns>
public bool DoAnimation(int animation)
{
return InvokeOnMainThread(() => handler.SendAnimation(animation, playerEntityID));
}
/// <summary>
/// Close the specified inventory window
/// </summary>
/// <param name="windowId">Window ID</param>
/// <returns>TRUE if the window was successfully closed</returns>
2020-07-09 22:21:39 +08:00
/// <remarks>Sending close window for inventory 0 can cause server to update our inventory if there are any item in the crafting area</remarks>
public bool CloseInventory(int windowId)
{
if (InvokeRequired)
return InvokeOnMainThread(() => CloseInventory(windowId));
if (inventories.ContainsKey(windowId))
{
if (windowId != 0)
inventories.Remove(windowId);
return handler.SendCloseWindow(windowId);
}
return false;
}
/// <summary>
/// Clean all inventory
/// </summary>
/// <returns>TRUE if the uccessfully clear</returns>
public bool ClearInventories()
{
if (!inventoryHandlingEnabled)
return false;
if (InvokeRequired)
return InvokeOnMainThread<bool>(ClearInventories);
inventories.Clear();
inventories[0] = new Container(0, ContainerType.PlayerInventory, "Player Inventory");
return true;
}
/// <summary>
/// Interact with an entity
/// </summary>
/// <param name="EntityID"></param>
/// <param name="type">Type of interaction (interact, attack...)</param>
ChatBot API: OnScoreboardObjective, OnEntityEffect, OnUpdateScore, EntityInteract, Hand list (#1097) * Create Effect.cs * Rename Effect.cs to Effects.cs * Update MinecraftClient.csproj * Update Effects.cs * Update Effects.cs * add EntityEffect * Update McClient.cs * Update Protocol18.cs + EntityEffect * Update IMinecraftComHandler.cs * Update Protocol18PacketTypes.cs + EntityEffect * Update ChatBot.cs + OnEntityEquipment * Update PacketIncomingType.cs + ScoreboardObjective * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnScoreboardObjective * Update McClient.cs + OnScoreboardObjective * Update ChatBot.cs + OnScoreboardObjective event * Update Protocol18.cs: fix scoreboard * Update McClient.cs * Update ChatBot.cs * Update PacketIncomingType.cs * Update ChatBot.cs + OnUpdateScore * Update McClient.cs + OnUpdateScore * Update IMinecraftComHandler.cs + OnUpdateScore * Update Protocol18.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs + fix micro lags * Update Protocol18.cs * Update Protocol18.cs * Update Protocol18.cs * Update Protocol16.cs * Update Protocol18.cs * Update McClient.cs * Update IMinecraftCom.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs + GetEntities() * Create Hand.cs * Update MinecraftClient.csproj * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs: fix * Update AutoAttack.cs: Fix * Update McClient.cs: compile fix * Update ChatBot.cs * Update AutoAttack.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McClient.cs * Update McClient.cs: remove check distance * Update EntityActionType.cs: more actions * Create CommandBlockMode.cs * Create CommandBlockFlags.cs * Update IMinecraftCom.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update Protocol16.cs * Update PacketOutgoingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs
2020-07-04 13:45:51 +05:00
/// <param name="hand">Hand.MainHand or Hand.OffHand</param>
/// <returns>TRUE if interaction succeeded</returns>
public bool InteractEntity(int entityID, InteractType type, Hand hand = Hand.MainHand)
{
if (InvokeRequired)
return InvokeOnMainThread(() => InteractEntity(entityID, type, hand));
if (entities.ContainsKey(entityID))
ChatBot API: OnScoreboardObjective, OnEntityEffect, OnUpdateScore, EntityInteract, Hand list (#1097) * Create Effect.cs * Rename Effect.cs to Effects.cs * Update MinecraftClient.csproj * Update Effects.cs * Update Effects.cs * add EntityEffect * Update McClient.cs * Update Protocol18.cs + EntityEffect * Update IMinecraftComHandler.cs * Update Protocol18PacketTypes.cs + EntityEffect * Update ChatBot.cs + OnEntityEquipment * Update PacketIncomingType.cs + ScoreboardObjective * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnScoreboardObjective * Update McClient.cs + OnScoreboardObjective * Update ChatBot.cs + OnScoreboardObjective event * Update Protocol18.cs: fix scoreboard * Update McClient.cs * Update ChatBot.cs * Update PacketIncomingType.cs * Update ChatBot.cs + OnUpdateScore * Update McClient.cs + OnUpdateScore * Update IMinecraftComHandler.cs + OnUpdateScore * Update Protocol18.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs + fix micro lags * Update Protocol18.cs * Update Protocol18.cs * Update Protocol18.cs * Update Protocol16.cs * Update Protocol18.cs * Update McClient.cs * Update IMinecraftCom.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs + GetEntities() * Create Hand.cs * Update MinecraftClient.csproj * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs: fix * Update AutoAttack.cs: Fix * Update McClient.cs: compile fix * Update ChatBot.cs * Update AutoAttack.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McClient.cs * Update McClient.cs: remove check distance * Update EntityActionType.cs: more actions * Create CommandBlockMode.cs * Create CommandBlockFlags.cs * Update IMinecraftCom.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update Protocol16.cs * Update PacketOutgoingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs
2020-07-04 13:45:51 +05:00
{
if (type == InteractType.Interact)
ChatBot API: OnScoreboardObjective, OnEntityEffect, OnUpdateScore, EntityInteract, Hand list (#1097) * Create Effect.cs * Rename Effect.cs to Effects.cs * Update MinecraftClient.csproj * Update Effects.cs * Update Effects.cs * add EntityEffect * Update McClient.cs * Update Protocol18.cs + EntityEffect * Update IMinecraftComHandler.cs * Update Protocol18PacketTypes.cs + EntityEffect * Update ChatBot.cs + OnEntityEquipment * Update PacketIncomingType.cs + ScoreboardObjective * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnScoreboardObjective * Update McClient.cs + OnScoreboardObjective * Update ChatBot.cs + OnScoreboardObjective event * Update Protocol18.cs: fix scoreboard * Update McClient.cs * Update ChatBot.cs * Update PacketIncomingType.cs * Update ChatBot.cs + OnUpdateScore * Update McClient.cs + OnUpdateScore * Update IMinecraftComHandler.cs + OnUpdateScore * Update Protocol18.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs + fix micro lags * Update Protocol18.cs * Update Protocol18.cs * Update Protocol18.cs * Update Protocol16.cs * Update Protocol18.cs * Update McClient.cs * Update IMinecraftCom.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs + GetEntities() * Create Hand.cs * Update MinecraftClient.csproj * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs: fix * Update AutoAttack.cs: Fix * Update McClient.cs: compile fix * Update ChatBot.cs * Update AutoAttack.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McClient.cs * Update McClient.cs: remove check distance * Update EntityActionType.cs: more actions * Create CommandBlockMode.cs * Create CommandBlockFlags.cs * Update IMinecraftCom.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update Protocol16.cs * Update PacketOutgoingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs
2020-07-04 13:45:51 +05:00
{
return handler.SendInteractEntity(entityID, (int)type, (int)hand);
}
else
{
return handler.SendInteractEntity(entityID, (int)type);
ChatBot API: OnScoreboardObjective, OnEntityEffect, OnUpdateScore, EntityInteract, Hand list (#1097) * Create Effect.cs * Rename Effect.cs to Effects.cs * Update MinecraftClient.csproj * Update Effects.cs * Update Effects.cs * add EntityEffect * Update McClient.cs * Update Protocol18.cs + EntityEffect * Update IMinecraftComHandler.cs * Update Protocol18PacketTypes.cs + EntityEffect * Update ChatBot.cs + OnEntityEquipment * Update PacketIncomingType.cs + ScoreboardObjective * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnScoreboardObjective * Update McClient.cs + OnScoreboardObjective * Update ChatBot.cs + OnScoreboardObjective event * Update Protocol18.cs: fix scoreboard * Update McClient.cs * Update ChatBot.cs * Update PacketIncomingType.cs * Update ChatBot.cs + OnUpdateScore * Update McClient.cs + OnUpdateScore * Update IMinecraftComHandler.cs + OnUpdateScore * Update Protocol18.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs + fix micro lags * Update Protocol18.cs * Update Protocol18.cs * Update Protocol18.cs * Update Protocol16.cs * Update Protocol18.cs * Update McClient.cs * Update IMinecraftCom.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs + GetEntities() * Create Hand.cs * Update MinecraftClient.csproj * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs: fix * Update AutoAttack.cs: Fix * Update McClient.cs: compile fix * Update ChatBot.cs * Update AutoAttack.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McClient.cs * Update McClient.cs: remove check distance * Update EntityActionType.cs: more actions * Create CommandBlockMode.cs * Create CommandBlockFlags.cs * Update IMinecraftCom.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update Protocol16.cs * Update PacketOutgoingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs
2020-07-04 13:45:51 +05:00
}
}
else return false;
}
/// <summary>
/// Place the block at hand in the Minecraft world
/// </summary>
/// <param name="location">Location to place block to</param>
/// <param name="blockFace">Block face (e.g. Direction.Down when clicking on the block below to place this block)</param>
/// <returns>TRUE if successfully placed</returns>
ChatBot API: OnScoreboardObjective, OnEntityEffect, OnUpdateScore, EntityInteract, Hand list (#1097) * Create Effect.cs * Rename Effect.cs to Effects.cs * Update MinecraftClient.csproj * Update Effects.cs * Update Effects.cs * add EntityEffect * Update McClient.cs * Update Protocol18.cs + EntityEffect * Update IMinecraftComHandler.cs * Update Protocol18PacketTypes.cs + EntityEffect * Update ChatBot.cs + OnEntityEquipment * Update PacketIncomingType.cs + ScoreboardObjective * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnScoreboardObjective * Update McClient.cs + OnScoreboardObjective * Update ChatBot.cs + OnScoreboardObjective event * Update Protocol18.cs: fix scoreboard * Update McClient.cs * Update ChatBot.cs * Update PacketIncomingType.cs * Update ChatBot.cs + OnUpdateScore * Update McClient.cs + OnUpdateScore * Update IMinecraftComHandler.cs + OnUpdateScore * Update Protocol18.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs + fix micro lags * Update Protocol18.cs * Update Protocol18.cs * Update Protocol18.cs * Update Protocol16.cs * Update Protocol18.cs * Update McClient.cs * Update IMinecraftCom.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs + GetEntities() * Create Hand.cs * Update MinecraftClient.csproj * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs: fix * Update AutoAttack.cs: Fix * Update McClient.cs: compile fix * Update ChatBot.cs * Update AutoAttack.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McClient.cs * Update McClient.cs: remove check distance * Update EntityActionType.cs: more actions * Create CommandBlockMode.cs * Create CommandBlockFlags.cs * Update IMinecraftCom.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update Protocol16.cs * Update PacketOutgoingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs
2020-07-04 13:45:51 +05:00
public bool PlaceBlock(Location location, Direction blockFace, Hand hand = Hand.MainHand)
{
return InvokeOnMainThread(() => handler.SendPlayerBlockPlacement((int)hand, location, blockFace, this.sequenceId));
}
/// <summary>
/// Attempt to dig a block at the specified location
/// </summary>
/// <param name="location">Location of block to dig</param>
/// <param name="swingArms">Also perform the "arm swing" animation</param>
/// <param name="lookAtBlock">Also look at the block before digging</param>
public bool DigBlock(Location location, bool swingArms = true, bool lookAtBlock = true)
{
if (!GetTerrainEnabled())
return false;
if (InvokeRequired)
return InvokeOnMainThread(() => DigBlock(location, swingArms, lookAtBlock));
// TODO select best face from current player location
Direction blockFace = Direction.Down;
// Look at block before attempting to break it
if (lookAtBlock)
UpdateLocation(GetCurrentLocation(), location);
// Send dig start and dig end, will need to wait for server response to know dig result
// See https://wiki.vg/How_to_Write_a_Client#Digging for more details
return handler.SendPlayerDigging(0, location, blockFace, this.sequenceId)
&& (!swingArms || DoAnimation((int)Hand.MainHand))
&& handler.SendPlayerDigging(2, location, blockFace, this.sequenceId);
}
/// <summary>
/// Change active slot in the player inventory
/// </summary>
/// <param name="slot">Slot to activate (0 to 8)</param>
/// <returns>TRUE if the slot was changed</returns>
public bool ChangeSlot(short slot)
{
if (slot < 0 || slot > 8)
return false;
if (InvokeRequired)
return InvokeOnMainThread(() => ChangeSlot(slot));
CurrentSlot = Convert.ToByte(slot);
return handler.SendHeldItemChange(slot);
}
/// <summary>
/// Update sign text
/// </summary>
/// <param name="location">sign location</param>
/// <param name="line1">text one</param>
/// <param name="line2">text two</param>
/// <param name="line3">text three</param>
/// <param name="line4">text1 four</param>
public bool UpdateSign(Location location, string line1, string line2, string line3, string line4)
{
// TODO Open sign editor first https://wiki.vg/Protocol#Open_Sign_Editor
return InvokeOnMainThread(() => handler.SendUpdateSign(location, line1, line2, line3, line4));
}
/// <summary>
/// Select villager trade
/// </summary>
/// <param name="selectedSlot">The slot of the trade, starts at 0.</param>
public bool SelectTrade(int selectedSlot)
{
return InvokeOnMainThread(() => handler.SelectTrade(selectedSlot));
}
ChatBot API: OnScoreboardObjective, OnEntityEffect, OnUpdateScore, EntityInteract, Hand list (#1097) * Create Effect.cs * Rename Effect.cs to Effects.cs * Update MinecraftClient.csproj * Update Effects.cs * Update Effects.cs * add EntityEffect * Update McClient.cs * Update Protocol18.cs + EntityEffect * Update IMinecraftComHandler.cs * Update Protocol18PacketTypes.cs + EntityEffect * Update ChatBot.cs + OnEntityEquipment * Update PacketIncomingType.cs + ScoreboardObjective * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnScoreboardObjective * Update McClient.cs + OnScoreboardObjective * Update ChatBot.cs + OnScoreboardObjective event * Update Protocol18.cs: fix scoreboard * Update McClient.cs * Update ChatBot.cs * Update PacketIncomingType.cs * Update ChatBot.cs + OnUpdateScore * Update McClient.cs + OnUpdateScore * Update IMinecraftComHandler.cs + OnUpdateScore * Update Protocol18.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs + fix micro lags * Update Protocol18.cs * Update Protocol18.cs * Update Protocol18.cs * Update Protocol16.cs * Update Protocol18.cs * Update McClient.cs * Update IMinecraftCom.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs + GetEntities() * Create Hand.cs * Update MinecraftClient.csproj * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs: fix * Update AutoAttack.cs: Fix * Update McClient.cs: compile fix * Update ChatBot.cs * Update AutoAttack.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McClient.cs * Update McClient.cs: remove check distance * Update EntityActionType.cs: more actions * Create CommandBlockMode.cs * Create CommandBlockFlags.cs * Update IMinecraftCom.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update Protocol16.cs * Update PacketOutgoingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs
2020-07-04 13:45:51 +05:00
/// <summary>
/// Update command block
/// </summary>
/// <param name="location">command block location</param>
/// <param name="command">command</param>
/// <param name="mode">command block mode</param>
/// <param name="flags">command block flags</param>
public bool UpdateCommandBlock(Location location, string command, CommandBlockMode mode, CommandBlockFlags flags)
{
return InvokeOnMainThread(() => handler.UpdateCommandBlock(location, command, mode, flags));
ChatBot API: OnScoreboardObjective, OnEntityEffect, OnUpdateScore, EntityInteract, Hand list (#1097) * Create Effect.cs * Rename Effect.cs to Effects.cs * Update MinecraftClient.csproj * Update Effects.cs * Update Effects.cs * add EntityEffect * Update McClient.cs * Update Protocol18.cs + EntityEffect * Update IMinecraftComHandler.cs * Update Protocol18PacketTypes.cs + EntityEffect * Update ChatBot.cs + OnEntityEquipment * Update PacketIncomingType.cs + ScoreboardObjective * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnScoreboardObjective * Update McClient.cs + OnScoreboardObjective * Update ChatBot.cs + OnScoreboardObjective event * Update Protocol18.cs: fix scoreboard * Update McClient.cs * Update ChatBot.cs * Update PacketIncomingType.cs * Update ChatBot.cs + OnUpdateScore * Update McClient.cs + OnUpdateScore * Update IMinecraftComHandler.cs + OnUpdateScore * Update Protocol18.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs + fix micro lags * Update Protocol18.cs * Update Protocol18.cs * Update Protocol18.cs * Update Protocol16.cs * Update Protocol18.cs * Update McClient.cs * Update IMinecraftCom.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs + GetEntities() * Create Hand.cs * Update MinecraftClient.csproj * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs: fix * Update AutoAttack.cs: Fix * Update McClient.cs: compile fix * Update ChatBot.cs * Update AutoAttack.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McClient.cs * Update McClient.cs: remove check distance * Update EntityActionType.cs: more actions * Create CommandBlockMode.cs * Create CommandBlockFlags.cs * Update IMinecraftCom.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update Protocol16.cs * Update PacketOutgoingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs
2020-07-04 13:45:51 +05:00
}
/// <summary>
/// Teleport to player in spectator mode
/// </summary>
/// <param name="entity">Player to teleport to</param>
/// Teleporting to other entityies is NOT implemented yet
public bool Spectate(Entity entity)
{
if (entity.Type == EntityType.Player)
{
return SpectateByUUID(entity.UUID);
}
else
{
return false;
}
}
/// <summary>
/// Teleport to player/entity in spectator mode
/// </summary>
/// <param name="UUID">UUID of player/entity to teleport to</param>
public bool SpectateByUUID(Guid UUID)
{
if (GetGamemode() == 3)
{
if (InvokeRequired)
return InvokeOnMainThread(() => SpectateByUUID(UUID));
return handler.SendSpectate(UUID);
}
else
{
return false;
}
}
#endregion
#region Event handlers: An event occurs on the Server
/// <summary>
/// Dispatch a ChatBot event with automatic exception handling
/// </summary>
/// <example>
/// Example for calling SomeEvent() on all bots at once:
/// DispatchBotEvent(bot => bot.SomeEvent());
/// </example>
/// <param name="action">Action to execute on each bot</param>
/// <param name="botList">Only fire the event for the specified bot list (default: all bots)</param>
private void DispatchBotEvent(Action<ChatBot> action, IEnumerable<ChatBot>? botList = null)
{
ChatBot[] selectedBots;
if (botList != null)
{
selectedBots = botList.ToArray();
}
else
{
selectedBots = bots.ToArray();
}
foreach (ChatBot bot in selectedBots)
{
try
{
action(bot);
}
catch (Exception e)
{
if (!(e is ThreadAbortException))
{
//Retrieve parent method name to determine which event caused the exception
System.Diagnostics.StackFrame frame = new System.Diagnostics.StackFrame(1);
System.Reflection.MethodBase method = frame.GetMethod();
string parentMethodName = method.Name;
//Display a meaningful error message to help debugging the ChatBot
Log.Error(parentMethodName + ": Got error from " + bot.ToString() + ": " + e.ToString());
}
else throw; //ThreadAbortException should not be caught here as in can happen when disconnecting from server
}
}
}
/// <summary>
/// Called when a network packet received or sent
/// </summary>
/// <remarks>
/// Only called if <see cref="networkPacketEventEnabled"/> is set to True
/// </remarks>
/// <param name="packetID">Packet ID</param>
/// <param name="packetData">A copy of Packet Data</param>
/// <param name="isLogin">The packet is login phase or playing phase</param>
/// <param name="isInbound">The packet is received from server or sent by client</param>
public void OnNetworkPacket(int packetID, List<byte> packetData, bool isLogin, bool isInbound)
{
DispatchBotEvent(bot => bot.OnNetworkPacket(packetID, packetData, isLogin, isInbound));
}
/// <summary>
/// Called when a server was successfully joined
/// </summary>
public void OnGameJoined()
{
if (!String.IsNullOrWhiteSpace(Settings.BrandInfo))
handler.SendBrandInfo(Settings.BrandInfo.Trim());
if (Settings.MCSettings_Enabled)
handler.SendClientSettings(
Settings.MCSettings_Locale,
Settings.MCSettings_RenderDistance,
Settings.MCSettings_Difficulty,
Settings.MCSettings_ChatMode,
Settings.MCSettings_ChatColors,
Settings.MCSettings_Skin_All,
Settings.MCSettings_MainHand);
if (inventoryHandlingRequested)
{
inventoryHandlingRequested = false;
inventoryHandlingEnabled = true;
Log.Info(Translations.Get("extra.inventory_enabled"));
}
ClearInventories();
DispatchBotEvent(bot => bot.AfterGameJoined());
}
/// <summary>
/// Called when the player respawns, which happens on login, respawn and world change.
/// </summary>
public void OnRespawn()
{
ClearTasks();
if (terrainAndMovementsRequested)
{
terrainAndMovementsEnabled = true;
terrainAndMovementsRequested = false;
Log.Info(Translations.Get("extra.terrainandmovement_enabled"));
}
if (terrainAndMovementsEnabled)
{
world.Clear();
}
Add Entity.Item, Entity.CustomName, OnEntityMetadata event (#1222) * Add New Event * new Event * Add OnEntityMetadaTa * Update ChatBot.cs * Update Protocol18.cs * Update Entity.cs * EntityCMD Update * Update IMinecraftComHandler.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs * Update McClient.cs * Update Entity.cs * Create EntityPose.cs * Update MinecraftClient.csproj * Update McClient.cs * Update EntityPose.cs * Update Entity.cs * Update McClient.cs * Remove debug line * Update Entitycmd.cs * Update Entity.cs * Update McClient.cs * Update Entity.cs * Update McClient.cs * Update McClient.cs * Update Entity.cs * Update McClient.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update McClient.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entity.cs * Update McClient.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Crash Fix on Item * Crashes Fix * Update McClient.cs * Crashes fix * Update McClient.cs * Update Entity.cs * Update Entity.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update Protocol18.cs * Update ChatBot.cs * Update IMinecraftComHandler.cs * Update Protocol18.cs * Update McClient.cs * Fix unaddressed issues Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-08-20 21:36:50 +05:00
entities.Clear();
ClearInventories();
DispatchBotEvent(bot => bot.OnRespawn());
}
/// <summary>
/// Check if the client is currently processing a Movement.
/// </summary>
/// <returns>true if a movement is currently handled</returns>
public bool ClientIsMoving()
{
return terrainAndMovementsEnabled && locationReceived && ((steps != null && steps.Count > 0) || (path != null && path.Count > 0));
}
Rework of MineCube.cs and further improvements to CalculatePath() (#2014) * Add function to determine if the client is executing a walking process * Add comments * Remove test bot entry * Add funtion to approach a block as close as possible * Add funtion to approach a block as close as possible * Add funtion to approach a block as close as possible * Add comment to function in McClient.cs * Improve concurrency and reduce potential calculation power * Apply code suggestions * Apply code suggestions * Improve CalculatePath() function to allow approaching * Fix typo in MinecraftClient/ChatBot.cs * Add comments to Chatbot fucntion * Add break to for loop to exit quicker * Allow to give a maxOffset to the goal * Comment the sample bot again. * Add parameter for calculation timeout * Remove TestBot again * Implement timeout in Chatbot class * Remove test commands * Update comment in Chatbot.cs * Set timeout to default 5 sec * Change order of parameters back * Add suggested improvements * Move task and fix missing methods in .NET 4.0 * Create switch for tool handling * Remove unused function * Improve movement * Improve performance of CalculatePath() - Replace Hashset OpenSet with a Binary Heap - Temporary remove maxOffset / minOffset features - Round start location for easier calculation - Add 0.5 to each location in reconstruct path to avoid getting stuck on edges * Add diagonal movement * Remove direct block movement - causes kick for invalid packet movement if moving on the block you are currently standing on * Floor start in A* and improve diagonal walking check * Add helperfunctions to McClient.cs * Prevent client from falling into danger * Add comment to function and remove dependencies * Add comments * Remove debug settings Co-authored-by: ORelio <ORelio@users.noreply.github.com>
2022-08-15 18:26:40 +02:00
/// <summary>
/// Get the current goal
/// </summary>
/// <returns>Current goal of movement. Location.Zero if not set.</returns>
public Location GetCurrentMovementGoal()
{
return ClientIsMoving() ? Location.Zero : path.Last();
}
/// <summary>
/// Cancels the current movement
/// </summary>
/// <returns>True if there was an active path</returns>
public bool CancelMovement()
{
bool success = ClientIsMoving();
path = null;
return success;
}
/// <summary>
/// Change the amount of sent movement packets per time
/// </summary>
/// <param name="newSpeed">Set a new walking type</param>
public void SetMovementSpeed(MovementType newSpeed)
{
switch (newSpeed)
{
case MovementType.Sneak:
// https://minecraft.fandom.com/wiki/Sneaking#Effects - Sneaking 1.31m/s
currentMovementSpeed = 2;
break;
case MovementType.Walk:
// https://minecraft.fandom.com/wiki/Walking#Usage - Walking 4.317 m/s
currentMovementSpeed = 4;
break;
case MovementType.Sprint:
// https://minecraft.fandom.com/wiki/Sprinting#Usage - Sprinting 5.612 m/s
currentMovementSpeed = 5;
break;
}
}
/// <summary>
/// Called when the server sends a new player location,
/// or if a ChatBot whishes to update the player's location.
/// </summary>
/// <param name="location">The new location</param>
/// <param name="relative">If true, the location is relative to the current location</param>
public void UpdateLocation(Location location, bool relative)
{
lock (locationLock)
{
if (relative)
{
this.location += location;
}
else this.location = location;
locationReceived = true;
}
}
/// <summary>
/// Called when the server sends a new player location,
/// or if a ChatBot whishes to update the player's location.
/// </summary>
/// <param name="location">The new location</param>
/// <param name="yaw">Yaw to look at</param>
/// <param name="pitch">Pitch to look at</param>
public void UpdateLocation(Location location, float yaw, float pitch)
{
this._yaw = yaw;
this._pitch = pitch;
UpdateLocation(location, false);
}
/// <summary>
/// Called when the server sends a new player location,
/// or if a ChatBot whishes to update the player's location.
/// </summary>
/// <param name="location">The new location</param>
/// <param name="lookAtLocation">Block coordinates to look at</param>
public void UpdateLocation(Location location, Location lookAtLocation)
{
double dx = lookAtLocation.X - (location.X - 0.5);
double dy = lookAtLocation.Y - (location.Y + 1);
double dz = lookAtLocation.Z - (location.Z - 0.5);
double r = Math.Sqrt(dx * dx + dy * dy + dz * dz);
float yaw = Convert.ToSingle(-Math.Atan2(dx, dz) / Math.PI * 180);
float pitch = Convert.ToSingle(-Math.Asin(dy / r) / Math.PI * 180);
if (yaw < 0) yaw += 360;
UpdateLocation(location, yaw, pitch);
}
/// <summary>
/// Called when the server sends a new player location,
/// or if a ChatBot whishes to update the player's location.
/// </summary>
/// <param name="location">The new location</param>
/// <param name="direction">Direction to look at</param>
public void UpdateLocation(Location location, Direction direction)
{
float yaw = 0;
float pitch = 0;
switch (direction)
{
case Direction.Up:
pitch = -90;
break;
case Direction.Down:
pitch = 90;
break;
case Direction.East:
yaw = 270;
break;
case Direction.West:
yaw = 90;
break;
case Direction.North:
yaw = 180;
break;
case Direction.South:
break;
default:
throw new ArgumentException(Translations.Get("exception.unknown_direction"), "direction");
}
UpdateLocation(location, yaw, pitch);
}
/// <summary>
/// Received chat/system message from the server
/// </summary>
/// <param name="message">Message received</param>
public void OnTextReceived(ChatMessage message)
{
2021-04-30 12:28:27 +08:00
UpdateKeepAlive();
List<string> links = new();
string messageText;
2022-08-27 02:10:44 +08:00
if (message.isSignedChat)
{
2022-08-27 02:10:44 +08:00
if (!Settings.ShowIllegalSignedChat && !message.isSystemChat && !(bool)message.isSignatureLegal!)
return;
messageText = ChatParser.ParseSignedChat(message, links);
}
else
{
2022-08-27 02:10:44 +08:00
if (message.isJson)
messageText = ChatParser.ParseText(message.content, links);
else
messageText = message.content;
}
Log.Chat(messageText);
if (Settings.DisplayChatLinks)
foreach (string link in links)
Log.Chat(Translations.Get("mcc.link", link));
DispatchBotEvent(bot => bot.GetText(messageText));
DispatchBotEvent(bot => bot.GetText(messageText, message.content));
}
/// <summary>
/// Received a connection keep-alive from the server
/// </summary>
public void OnServerKeepAlive()
{
2021-04-30 12:28:27 +08:00
UpdateKeepAlive();
}
/// <summary>
/// When an inventory is opened
/// </summary>
/// <param name="inventory">The inventory</param>
/// <param name="inventoryID">Inventory ID</param>
public void OnInventoryOpen(int inventoryID, Container inventory)
{
inventories[inventoryID] = inventory;
if (inventoryID != 0)
{
Log.Info(Translations.Get("extra.inventory_open", inventoryID, inventory.Title));
Log.Info(Translations.Get("extra.inventory_interact"));
DispatchBotEvent(bot => bot.OnInventoryOpen(inventoryID));
}
}
/// <summary>
/// When an inventory is close
/// </summary>
/// <param name="inventoryID">Inventory ID</param>
public void OnInventoryClose(int inventoryID)
{
if (inventories.ContainsKey(inventoryID))
{
if (inventoryID == 0)
inventories[0].Items.Clear(); // Don't delete player inventory
else
inventories.Remove(inventoryID);
}
if (inventoryID != 0)
{
Log.Info(Translations.Get("extra.inventory_close", inventoryID));
DispatchBotEvent(bot => bot.OnInventoryClose(inventoryID));
}
}
/// <summary>
/// When received window items from server.
/// </summary>
/// <param name="inventoryID">Inventory ID</param>
/// <param name="itemList">Item list, key = slot ID, value = Item information</param>
public void OnWindowItems(byte inventoryID, Dictionary<int, Inventory.Item> itemList, int stateId)
{
if (inventories.ContainsKey(inventoryID))
{
inventories[inventoryID].Items = itemList;
inventories[inventoryID].StateID = stateId;
DispatchBotEvent(bot => bot.OnInventoryUpdate(inventoryID));
}
}
/// <summary>
/// When a slot is set inside window items
/// </summary>
/// <param name="inventoryID">Window ID</param>
/// <param name="slotID">Slot ID</param>
/// <param name="item">Item (may be null for empty slot)</param>
2022-07-25 01:13:41 +08:00
public void OnSetSlot(byte inventoryID, short slotID, Item item, int stateId)
{
2022-07-25 01:13:41 +08:00
if (inventories.ContainsKey(inventoryID))
inventories[inventoryID].StateID = stateId;
// Handle inventoryID -2 - Add item to player inventory without animation
if (inventoryID == 254)
inventoryID = 0;
// Handle cursor item
if (inventoryID == 255 && slotID == -1)
{
inventoryID = 0; // Prevent key not found for some bots relied to this event
if (inventories.ContainsKey(0))
{
if (item != null)
inventories[0].Items[-1] = item;
else
inventories[0].Items.Remove(-1);
}
}
else
{
if (inventories.ContainsKey(inventoryID))
{
if (item == null || item.IsEmpty)
{
if (inventories[inventoryID].Items.ContainsKey(slotID))
inventories[inventoryID].Items.Remove(slotID);
}
else inventories[inventoryID].Items[slotID] = item;
}
}
DispatchBotEvent(bot => bot.OnInventoryUpdate(inventoryID));
}
/// <summary>
/// Set client player's ID for later receiving player's own properties
/// </summary>
/// <param name="EntityID">Player Entity ID</param>
public void OnReceivePlayerEntityID(int EntityID)
{
playerEntityID = EntityID;
}
/// <summary>
/// Triggered when a new player joins the game
/// </summary>
/// <param name="player">player info</param>
public void OnPlayerJoin(PlayerInfo player)
{
//Ignore placeholders eg 0000tab# from TabListPlus
if (!ChatBot.IsValidName(player.Name))
return;
if (player.Name == username)
{
// 1.19+ offline server is possible to return different uuid
2022-08-27 02:10:44 +08:00
this.uuid = player.Uuid;
this.uuidStr = player.Uuid.ToString().Replace("-", string.Empty);
}
lock (onlinePlayers)
{
2022-08-27 02:10:44 +08:00
onlinePlayers[player.Uuid] = player;
}
2022-08-27 02:10:44 +08:00
DispatchBotEvent(bot => bot.OnPlayerJoin(player.Uuid, player.Name));
}
/// <summary>
/// Triggered when a player has left the game
/// </summary>
/// <param name="uuid">UUID of the player</param>
public void OnPlayerLeave(Guid uuid)
{
string? username = null;
lock (onlinePlayers)
{
if (onlinePlayers.ContainsKey(uuid))
{
username = onlinePlayers[uuid].Name;
onlinePlayers.Remove(uuid);
}
}
DispatchBotEvent(bot => bot.OnPlayerLeave(uuid, username));
}
/// <summary>
/// Called when a plugin channel message was sent from the server.
/// </summary>
/// <param name="channel">The channel the message was sent on</param>
/// <param name="data">The data from the channel</param>
public void OnPluginChannelMessage(string channel, byte[] data)
{
if (channel == "REGISTER")
{
string[] channels = Encoding.UTF8.GetString(data).Split('\0');
foreach (string chan in channels)
{
if (!registeredServerPluginChannels.Contains(chan))
{
registeredServerPluginChannels.Add(chan);
}
}
}
if (channel == "UNREGISTER")
{
string[] channels = Encoding.UTF8.GetString(data).Split('\0');
foreach (string chan in channels)
{
registeredServerPluginChannels.Remove(chan);
}
}
if (registeredBotPluginChannels.ContainsKey(channel))
{
DispatchBotEvent(bot => bot.OnPluginMessage(channel, data), registeredBotPluginChannels[channel]);
}
}
/// <summary>
/// Called when an entity spawned
/// </summary>
public void OnSpawnEntity(Entity entity)
{
// The entity should not already exist, but if it does, let's consider the previous one is being destroyed
if (entities.ContainsKey(entity.ID))
OnDestroyEntities(new[] { entity.ID });
entities.Add(entity.ID, entity);
DispatchBotEvent(bot => bot.OnEntitySpawn(entity));
}
ChatBot API: OnScoreboardObjective, OnEntityEffect, OnUpdateScore, EntityInteract, Hand list (#1097) * Create Effect.cs * Rename Effect.cs to Effects.cs * Update MinecraftClient.csproj * Update Effects.cs * Update Effects.cs * add EntityEffect * Update McClient.cs * Update Protocol18.cs + EntityEffect * Update IMinecraftComHandler.cs * Update Protocol18PacketTypes.cs + EntityEffect * Update ChatBot.cs + OnEntityEquipment * Update PacketIncomingType.cs + ScoreboardObjective * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnScoreboardObjective * Update McClient.cs + OnScoreboardObjective * Update ChatBot.cs + OnScoreboardObjective event * Update Protocol18.cs: fix scoreboard * Update McClient.cs * Update ChatBot.cs * Update PacketIncomingType.cs * Update ChatBot.cs + OnUpdateScore * Update McClient.cs + OnUpdateScore * Update IMinecraftComHandler.cs + OnUpdateScore * Update Protocol18.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs + fix micro lags * Update Protocol18.cs * Update Protocol18.cs * Update Protocol18.cs * Update Protocol16.cs * Update Protocol18.cs * Update McClient.cs * Update IMinecraftCom.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs + GetEntities() * Create Hand.cs * Update MinecraftClient.csproj * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs: fix * Update AutoAttack.cs: Fix * Update McClient.cs: compile fix * Update ChatBot.cs * Update AutoAttack.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McClient.cs * Update McClient.cs: remove check distance * Update EntityActionType.cs: more actions * Create CommandBlockMode.cs * Create CommandBlockFlags.cs * Update IMinecraftCom.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update Protocol16.cs * Update PacketOutgoingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs
2020-07-04 13:45:51 +05:00
/// <summary>
/// Called when an entity effects
/// </summary>
public void OnEntityEffect(int entityid, Effects effect, int amplifier, int duration, byte flags, bool hasFactorData, Dictionary<string, object>? factorCodec)
ChatBot API: OnScoreboardObjective, OnEntityEffect, OnUpdateScore, EntityInteract, Hand list (#1097) * Create Effect.cs * Rename Effect.cs to Effects.cs * Update MinecraftClient.csproj * Update Effects.cs * Update Effects.cs * add EntityEffect * Update McClient.cs * Update Protocol18.cs + EntityEffect * Update IMinecraftComHandler.cs * Update Protocol18PacketTypes.cs + EntityEffect * Update ChatBot.cs + OnEntityEquipment * Update PacketIncomingType.cs + ScoreboardObjective * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnScoreboardObjective * Update McClient.cs + OnScoreboardObjective * Update ChatBot.cs + OnScoreboardObjective event * Update Protocol18.cs: fix scoreboard * Update McClient.cs * Update ChatBot.cs * Update PacketIncomingType.cs * Update ChatBot.cs + OnUpdateScore * Update McClient.cs + OnUpdateScore * Update IMinecraftComHandler.cs + OnUpdateScore * Update Protocol18.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs + fix micro lags * Update Protocol18.cs * Update Protocol18.cs * Update Protocol18.cs * Update Protocol16.cs * Update Protocol18.cs * Update McClient.cs * Update IMinecraftCom.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs + GetEntities() * Create Hand.cs * Update MinecraftClient.csproj * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs: fix * Update AutoAttack.cs: Fix * Update McClient.cs: compile fix * Update ChatBot.cs * Update AutoAttack.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McClient.cs * Update McClient.cs: remove check distance * Update EntityActionType.cs: more actions * Create CommandBlockMode.cs * Create CommandBlockFlags.cs * Update IMinecraftCom.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update Protocol16.cs * Update PacketOutgoingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs
2020-07-04 13:45:51 +05:00
{
if (entities.ContainsKey(entityid))
DispatchBotEvent(bot => bot.OnEntityEffect(entities[entityid], effect, amplifier, duration, flags));
}
/// <summary>
/// Called when a player spawns or enters the client's render distance
/// </summary>
public void OnSpawnPlayer(int entityID, Guid uuid, Location location, byte Yaw, byte Pitch)
{
string? playerName = null;
if (onlinePlayers.ContainsKey(uuid))
playerName = onlinePlayers[uuid].Name;
Entity playerEntity = new(entityID, EntityType.Player, location, uuid, playerName);
OnSpawnEntity(playerEntity);
}
Implement OnMapData, OnTitle, UpdateSign, OnEntityEquipment, Useblock (#1071) * + Fix null PlayerInventory + Fix null PlayerInventory * Update Protocol18.cs * Update McTcpClient.cs + Fix https://github.com/ORelio/Minecraft-Console-Client/issues/1022 * Update Protocol18.cs + MapData * Update PacketIncomingType.cs + MapData * Update Protocol18PacketTypes.cs * Update IMinecraftComHandler.cs + OnMapData * Update McTcpClient.cs + OnMapData * Update ChatBot.cs + OnMapData * Update Protocol18.cs * Update Protocol18PacketTypes.cs + Fix * Update PacketIncomingType.cs + Title * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnTitle * Update McTcpClient.cs * Update ChatBot.cs + OnTitle * Update Protocol18.cs Fix * Update IMinecraftComHandler.cs * Update McTcpClient.cs * add ClearInventories() * add ClearInventories() * Update McTcpClient.cs + OnTitle * Preparing to Add BlockAction * Update PacketOutgoingType.cs * Update PacketOutgoingType.cs * Update Protocol18.cs + SendUpdateSign * Update Protocol16.cs + SendUpdateSign * Update IMinecraftCom.cs + SendUpdateSign * Update McTcpClient.cs + UpdateSign * Update ChatBot.cs + UpdateSign * Update McTcpClient.cs Update PlaceBlock * Update ChatBot.cs * Update McTcpClient.cs * add SendCreativeInventoryAction nbt add SendCreativeInventoryAction nbt * Update Protocol18.cs * Update Protocol16.cs * Update McTcpClient.cs * Update ChatBot.cs * Update Inventory.cs * Update Protocol18PacketTypes.cs * Update PacketIncomingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18PacketTypes.cs Fix * Update Protocol18PacketTypes.cs Fix * Update IMinecraftComHandler.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McTcpClient.cs + OnEntityEquipment * Update Protocol18.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update Protocol18.cs * Update McTcpClient.cs * Update ChatBot.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update Protocol18.cs * Create Useblock.cs * Update MinecraftClient.csproj * Update McTcpClient.cs
2020-06-20 17:57:07 +05:00
/// <summary>
/// Called on Entity Equipment
/// </summary>
/// <param name="entityid"> Entity ID</param>
/// <param name="slot"> Equipment slot. 0: main hand, 1: off hand, 25: armor slot (2: boots, 3: leggings, 4: chestplate, 5: helmet)</param>
/// <param name="item"> Item)</param>
public void OnEntityEquipment(int entityid, int slot, Item item)
{
if (entities.ContainsKey(entityid))
Implement OnMapData, OnTitle, UpdateSign, OnEntityEquipment, Useblock (#1071) * + Fix null PlayerInventory + Fix null PlayerInventory * Update Protocol18.cs * Update McTcpClient.cs + Fix https://github.com/ORelio/Minecraft-Console-Client/issues/1022 * Update Protocol18.cs + MapData * Update PacketIncomingType.cs + MapData * Update Protocol18PacketTypes.cs * Update IMinecraftComHandler.cs + OnMapData * Update McTcpClient.cs + OnMapData * Update ChatBot.cs + OnMapData * Update Protocol18.cs * Update Protocol18PacketTypes.cs + Fix * Update PacketIncomingType.cs + Title * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnTitle * Update McTcpClient.cs * Update ChatBot.cs + OnTitle * Update Protocol18.cs Fix * Update IMinecraftComHandler.cs * Update McTcpClient.cs * add ClearInventories() * add ClearInventories() * Update McTcpClient.cs + OnTitle * Preparing to Add BlockAction * Update PacketOutgoingType.cs * Update PacketOutgoingType.cs * Update Protocol18.cs + SendUpdateSign * Update Protocol16.cs + SendUpdateSign * Update IMinecraftCom.cs + SendUpdateSign * Update McTcpClient.cs + UpdateSign * Update ChatBot.cs + UpdateSign * Update McTcpClient.cs Update PlaceBlock * Update ChatBot.cs * Update McTcpClient.cs * add SendCreativeInventoryAction nbt add SendCreativeInventoryAction nbt * Update Protocol18.cs * Update Protocol16.cs * Update McTcpClient.cs * Update ChatBot.cs * Update Inventory.cs * Update Protocol18PacketTypes.cs * Update PacketIncomingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18PacketTypes.cs Fix * Update Protocol18PacketTypes.cs Fix * Update IMinecraftComHandler.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McTcpClient.cs + OnEntityEquipment * Update Protocol18.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update Protocol18.cs * Update McTcpClient.cs * Update ChatBot.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update Protocol18.cs * Create Useblock.cs * Update MinecraftClient.csproj * Update McTcpClient.cs
2020-06-20 17:57:07 +05:00
{
Entity entity = entities[entityid];
if (entity.Equipment.ContainsKey(slot))
entity.Equipment.Remove(slot);
if (item != null)
entity.Equipment[slot] = item;
DispatchBotEvent(bot => bot.OnEntityEquipment(entities[entityid], slot, item));
Implement OnMapData, OnTitle, UpdateSign, OnEntityEquipment, Useblock (#1071) * + Fix null PlayerInventory + Fix null PlayerInventory * Update Protocol18.cs * Update McTcpClient.cs + Fix https://github.com/ORelio/Minecraft-Console-Client/issues/1022 * Update Protocol18.cs + MapData * Update PacketIncomingType.cs + MapData * Update Protocol18PacketTypes.cs * Update IMinecraftComHandler.cs + OnMapData * Update McTcpClient.cs + OnMapData * Update ChatBot.cs + OnMapData * Update Protocol18.cs * Update Protocol18PacketTypes.cs + Fix * Update PacketIncomingType.cs + Title * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnTitle * Update McTcpClient.cs * Update ChatBot.cs + OnTitle * Update Protocol18.cs Fix * Update IMinecraftComHandler.cs * Update McTcpClient.cs * add ClearInventories() * add ClearInventories() * Update McTcpClient.cs + OnTitle * Preparing to Add BlockAction * Update PacketOutgoingType.cs * Update PacketOutgoingType.cs * Update Protocol18.cs + SendUpdateSign * Update Protocol16.cs + SendUpdateSign * Update IMinecraftCom.cs + SendUpdateSign * Update McTcpClient.cs + UpdateSign * Update ChatBot.cs + UpdateSign * Update McTcpClient.cs Update PlaceBlock * Update ChatBot.cs * Update McTcpClient.cs * add SendCreativeInventoryAction nbt add SendCreativeInventoryAction nbt * Update Protocol18.cs * Update Protocol16.cs * Update McTcpClient.cs * Update ChatBot.cs * Update Inventory.cs * Update Protocol18PacketTypes.cs * Update PacketIncomingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18PacketTypes.cs Fix * Update Protocol18PacketTypes.cs Fix * Update IMinecraftComHandler.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McTcpClient.cs + OnEntityEquipment * Update Protocol18.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update Protocol18.cs * Update McTcpClient.cs * Update ChatBot.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update Protocol18.cs * Create Useblock.cs * Update MinecraftClient.csproj * Update McTcpClient.cs
2020-06-20 17:57:07 +05:00
}
}
Add SendPlaceBlock, PlayerDigging, OnExplosion, OnGamemodeUpdate, OnSetExperience (#1027) * Update ChatBot.cs + PlaceBlock * Update AutoAttack.cs + HitAnimation * Update PacketIncomingType.cs + Explosion, * Update McTcpClient.cs + OnExplosion * Update ChatBot.cs + OnExplosion * Update IMinecraftComHandler.cs + OnExplosion * Update Protocol18PacketTypes.cs + PacketIncomingType.Explosion * Update ChatBot.cs + Fix * Update AutoAttack.cs + Fix * Update ChatBot.cs + Fix * Update Protocol18PacketTypes.cs + Old versions * Update Protocol18PacketTypes.cs + 1.7 - 1.8 Explosion ID * Update Protocol18PacketTypes.cs + Fix * Update McTcpClient.cs + int ExplosionRecordCount * Update ChatBot.cs + recordcount * Update IMinecraftComHandler.cs + ExplosionRecordCount * Update Protocol18.cs * Update CSharpRunner.cs + using MinecraftClient.Inventory; * add OnGamemodeUpdate + OnGamemodeUpdate * + OnGamemodeUpdate(playername, uuid, gamemode) + OnGamemodeUpdate * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McTcpClient.cs Fix * Update McTcpClient.cs * Update Protocol18.cs + Location explodelocation * Update McTcpClient.cs + Location explode * Update ChatBot.cs + Fix * Update ChatBot.cs Remove excess + * Update Plays animation * Improve documentation * ItemType fix * OnExplosion(Location explod); * Update PacketIncomingType.cs add SetExperience, * + Old versions * Update IMinecraftComHandler.cs * Update McTcpClient.cs * Update Protocol18.cs * add GetLevel & GetTotalExperience * Fix * add GetLevel & GetTotalExperience * OnSetExpience * Update ChatBot.cs Fix * Update McTcpClient.cs + bot.OnSetExperience * Update Protocol18.cs + Fix * Update McTcpClient.cs + PlayerDigging * Update PacketOutgoingType.cs + PlayerDigging * Update Protocol18PacketTypes.cs + case PacketOutgoingType.PlayerDigging * Update Protocol18.cs + SendPlayerDigging * Update IMinecraftCom.cs + SendPlayerDigging * Update McTcpClient.cs + PlayerDigging * Update Protocol16.cs + SendPlayerDigging * Update ChatBot.cs + PlayerDigging * Update ChatBot.cs + Fix * Update McTcpClient.cs + Fix * Update ChatBot.cs Add WindowAction * ChatBot.cs Fixes * Further ChatBot.cs fixes * Further ChatBot.cs fixes * Protocol Handler fixes * Protocol Handler fixes * IMinecraftCom fixes * documentation fixes Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-05-29 23:18:34 +05:00
/// <summary>
/// Called when the Game Mode has been updated for a player
/// </summary>
/// <param name="playername">Player Name</param>
/// <param name="uuid">Player UUID (Empty for initial gamemode on login)</param>
Add SendPlaceBlock, PlayerDigging, OnExplosion, OnGamemodeUpdate, OnSetExperience (#1027) * Update ChatBot.cs + PlaceBlock * Update AutoAttack.cs + HitAnimation * Update PacketIncomingType.cs + Explosion, * Update McTcpClient.cs + OnExplosion * Update ChatBot.cs + OnExplosion * Update IMinecraftComHandler.cs + OnExplosion * Update Protocol18PacketTypes.cs + PacketIncomingType.Explosion * Update ChatBot.cs + Fix * Update AutoAttack.cs + Fix * Update ChatBot.cs + Fix * Update Protocol18PacketTypes.cs + Old versions * Update Protocol18PacketTypes.cs + 1.7 - 1.8 Explosion ID * Update Protocol18PacketTypes.cs + Fix * Update McTcpClient.cs + int ExplosionRecordCount * Update ChatBot.cs + recordcount * Update IMinecraftComHandler.cs + ExplosionRecordCount * Update Protocol18.cs * Update CSharpRunner.cs + using MinecraftClient.Inventory; * add OnGamemodeUpdate + OnGamemodeUpdate * + OnGamemodeUpdate(playername, uuid, gamemode) + OnGamemodeUpdate * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McTcpClient.cs Fix * Update McTcpClient.cs * Update Protocol18.cs + Location explodelocation * Update McTcpClient.cs + Location explode * Update ChatBot.cs + Fix * Update ChatBot.cs Remove excess + * Update Plays animation * Improve documentation * ItemType fix * OnExplosion(Location explod); * Update PacketIncomingType.cs add SetExperience, * + Old versions * Update IMinecraftComHandler.cs * Update McTcpClient.cs * Update Protocol18.cs * add GetLevel & GetTotalExperience * Fix * add GetLevel & GetTotalExperience * OnSetExpience * Update ChatBot.cs Fix * Update McTcpClient.cs + bot.OnSetExperience * Update Protocol18.cs + Fix * Update McTcpClient.cs + PlayerDigging * Update PacketOutgoingType.cs + PlayerDigging * Update Protocol18PacketTypes.cs + case PacketOutgoingType.PlayerDigging * Update Protocol18.cs + SendPlayerDigging * Update IMinecraftCom.cs + SendPlayerDigging * Update McTcpClient.cs + PlayerDigging * Update Protocol16.cs + SendPlayerDigging * Update ChatBot.cs + PlayerDigging * Update ChatBot.cs + Fix * Update McTcpClient.cs + Fix * Update ChatBot.cs Add WindowAction * ChatBot.cs Fixes * Further ChatBot.cs fixes * Further ChatBot.cs fixes * Protocol Handler fixes * Protocol Handler fixes * IMinecraftCom fixes * documentation fixes Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-05-29 23:18:34 +05:00
/// <param name="gamemode">New Game Mode (0: Survival, 1: Creative, 2: Adventure, 3: Spectator).</param>
public void OnGamemodeUpdate(Guid uuid, int gamemode)
{
// Initial gamemode on login
if (uuid == Guid.Empty)
this.gamemode = gamemode;
// Further regular gamemode change events
Add SendPlaceBlock, PlayerDigging, OnExplosion, OnGamemodeUpdate, OnSetExperience (#1027) * Update ChatBot.cs + PlaceBlock * Update AutoAttack.cs + HitAnimation * Update PacketIncomingType.cs + Explosion, * Update McTcpClient.cs + OnExplosion * Update ChatBot.cs + OnExplosion * Update IMinecraftComHandler.cs + OnExplosion * Update Protocol18PacketTypes.cs + PacketIncomingType.Explosion * Update ChatBot.cs + Fix * Update AutoAttack.cs + Fix * Update ChatBot.cs + Fix * Update Protocol18PacketTypes.cs + Old versions * Update Protocol18PacketTypes.cs + 1.7 - 1.8 Explosion ID * Update Protocol18PacketTypes.cs + Fix * Update McTcpClient.cs + int ExplosionRecordCount * Update ChatBot.cs + recordcount * Update IMinecraftComHandler.cs + ExplosionRecordCount * Update Protocol18.cs * Update CSharpRunner.cs + using MinecraftClient.Inventory; * add OnGamemodeUpdate + OnGamemodeUpdate * + OnGamemodeUpdate(playername, uuid, gamemode) + OnGamemodeUpdate * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McTcpClient.cs Fix * Update McTcpClient.cs * Update Protocol18.cs + Location explodelocation * Update McTcpClient.cs + Location explode * Update ChatBot.cs + Fix * Update ChatBot.cs Remove excess + * Update Plays animation * Improve documentation * ItemType fix * OnExplosion(Location explod); * Update PacketIncomingType.cs add SetExperience, * + Old versions * Update IMinecraftComHandler.cs * Update McTcpClient.cs * Update Protocol18.cs * add GetLevel & GetTotalExperience * Fix * add GetLevel & GetTotalExperience * OnSetExpience * Update ChatBot.cs Fix * Update McTcpClient.cs + bot.OnSetExperience * Update Protocol18.cs + Fix * Update McTcpClient.cs + PlayerDigging * Update PacketOutgoingType.cs + PlayerDigging * Update Protocol18PacketTypes.cs + case PacketOutgoingType.PlayerDigging * Update Protocol18.cs + SendPlayerDigging * Update IMinecraftCom.cs + SendPlayerDigging * Update McTcpClient.cs + PlayerDigging * Update Protocol16.cs + SendPlayerDigging * Update ChatBot.cs + PlayerDigging * Update ChatBot.cs + Fix * Update McTcpClient.cs + Fix * Update ChatBot.cs Add WindowAction * ChatBot.cs Fixes * Further ChatBot.cs fixes * Further ChatBot.cs fixes * Protocol Handler fixes * Protocol Handler fixes * IMinecraftCom fixes * documentation fixes Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-05-29 23:18:34 +05:00
if (onlinePlayers.ContainsKey(uuid))
{
string playerName = onlinePlayers[uuid].Name;
if (playerName == this.username)
this.gamemode = gamemode;
DispatchBotEvent(bot => bot.OnGamemodeUpdate(playerName, uuid, gamemode));
Add SendPlaceBlock, PlayerDigging, OnExplosion, OnGamemodeUpdate, OnSetExperience (#1027) * Update ChatBot.cs + PlaceBlock * Update AutoAttack.cs + HitAnimation * Update PacketIncomingType.cs + Explosion, * Update McTcpClient.cs + OnExplosion * Update ChatBot.cs + OnExplosion * Update IMinecraftComHandler.cs + OnExplosion * Update Protocol18PacketTypes.cs + PacketIncomingType.Explosion * Update ChatBot.cs + Fix * Update AutoAttack.cs + Fix * Update ChatBot.cs + Fix * Update Protocol18PacketTypes.cs + Old versions * Update Protocol18PacketTypes.cs + 1.7 - 1.8 Explosion ID * Update Protocol18PacketTypes.cs + Fix * Update McTcpClient.cs + int ExplosionRecordCount * Update ChatBot.cs + recordcount * Update IMinecraftComHandler.cs + ExplosionRecordCount * Update Protocol18.cs * Update CSharpRunner.cs + using MinecraftClient.Inventory; * add OnGamemodeUpdate + OnGamemodeUpdate * + OnGamemodeUpdate(playername, uuid, gamemode) + OnGamemodeUpdate * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McTcpClient.cs Fix * Update McTcpClient.cs * Update Protocol18.cs + Location explodelocation * Update McTcpClient.cs + Location explode * Update ChatBot.cs + Fix * Update ChatBot.cs Remove excess + * Update Plays animation * Improve documentation * ItemType fix * OnExplosion(Location explod); * Update PacketIncomingType.cs add SetExperience, * + Old versions * Update IMinecraftComHandler.cs * Update McTcpClient.cs * Update Protocol18.cs * add GetLevel & GetTotalExperience * Fix * add GetLevel & GetTotalExperience * OnSetExpience * Update ChatBot.cs Fix * Update McTcpClient.cs + bot.OnSetExperience * Update Protocol18.cs + Fix * Update McTcpClient.cs + PlayerDigging * Update PacketOutgoingType.cs + PlayerDigging * Update Protocol18PacketTypes.cs + case PacketOutgoingType.PlayerDigging * Update Protocol18.cs + SendPlayerDigging * Update IMinecraftCom.cs + SendPlayerDigging * Update McTcpClient.cs + PlayerDigging * Update Protocol16.cs + SendPlayerDigging * Update ChatBot.cs + PlayerDigging * Update ChatBot.cs + Fix * Update McTcpClient.cs + Fix * Update ChatBot.cs Add WindowAction * ChatBot.cs Fixes * Further ChatBot.cs fixes * Further ChatBot.cs fixes * Protocol Handler fixes * Protocol Handler fixes * IMinecraftCom fixes * documentation fixes Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-05-29 23:18:34 +05:00
}
}
/// <summary>
/// Called when entities dead/despawn.
/// </summary>
public void OnDestroyEntities(int[] Entities)
{
foreach (int a in Entities)
{
if (entities.ContainsKey(a))
{
DispatchBotEvent(bot => bot.OnEntityDespawn(entities[a]));
entities.Remove(a);
}
}
}
/// <summary>
/// Called when an entity's position changed within 8 block of its previous position.
/// </summary>
/// <param name="EntityID"></param>
/// <param name="Dx"></param>
/// <param name="Dy"></param>
/// <param name="Dz"></param>
/// <param name="onGround"></param>
public void OnEntityPosition(int EntityID, Double Dx, Double Dy, Double Dz, bool onGround)
{
if (entities.ContainsKey(EntityID))
{
Location L = entities[EntityID].Location;
L.X += Dx;
L.Y += Dy;
L.Z += Dz;
entities[EntityID].Location = L;
DispatchBotEvent(bot => bot.OnEntityMove(entities[EntityID]));
}
}
/// <summary>
/// Called when an entity moved over 8 block.
/// </summary>
/// <param name="EntityID"></param>
/// <param name="X"></param>
/// <param name="Y"></param>
/// <param name="Z"></param>
/// <param name="onGround"></param>
public void OnEntityTeleport(int EntityID, Double X, Double Y, Double Z, bool onGround)
{
if (entities.ContainsKey(EntityID))
{
Location location = new Location(X, Y, Z);
entities[EntityID].Location = location;
DispatchBotEvent(bot => bot.OnEntityMove(entities[EntityID]));
}
}
/// <summary>
/// Called when received entity properties from server.
/// </summary>
/// <param name="EntityID"></param>
/// <param name="prop"></param>
public void OnEntityProperties(int EntityID, Dictionary<string, Double> prop)
{
if (EntityID == playerEntityID)
{
DispatchBotEvent(bot => bot.OnPlayerProperty(prop));
}
}
2021-03-21 22:17:19 +08:00
/// <summary>
/// Called when the status of an entity have been changed
/// </summary>
/// <param name="entityID">Entity ID</param>
/// <param name="status">Status ID</param>
public void OnEntityStatus(int entityID, byte status)
{
if (entityID == playerEntityID)
{
DispatchBotEvent(bot => bot.OnPlayerStatus(status));
}
}
/// <summary>
/// Called when server sent a Time Update packet.
/// </summary>
/// <param name="WorldAge"></param>
/// <param name="TimeOfDay"></param>
public void OnTimeUpdate(long WorldAge, long TimeOfDay)
{
2021-04-30 12:28:27 +08:00
// TimeUpdate sent every server tick hence used as timeout detect
UpdateKeepAlive();
// calculate server tps
if (lastAge != 0)
{
DateTime currentTime = DateTime.Now;
long tickDiff = WorldAge - lastAge;
Double tps = tickDiff / (currentTime - lastTime).TotalSeconds;
lastAge = WorldAge;
lastTime = currentTime;
if (tps <= 20 && tps > 0)
{
// calculate average tps
if (tpsSamples.Count >= maxSamples)
{
// full
sampleSum -= tpsSamples[0];
tpsSamples.RemoveAt(0);
}
tpsSamples.Add(tps);
sampleSum += tps;
averageTPS = sampleSum / tpsSamples.Count;
serverTPS = tps;
DispatchBotEvent(bot => bot.OnServerTpsUpdate(tps));
}
}
else
{
lastAge = WorldAge;
lastTime = DateTime.Now;
}
DispatchBotEvent(bot => bot.OnTimeUpdate(WorldAge, TimeOfDay));
}
Add SendPlaceBlock, PlayerDigging, OnExplosion, OnGamemodeUpdate, OnSetExperience (#1027) * Update ChatBot.cs + PlaceBlock * Update AutoAttack.cs + HitAnimation * Update PacketIncomingType.cs + Explosion, * Update McTcpClient.cs + OnExplosion * Update ChatBot.cs + OnExplosion * Update IMinecraftComHandler.cs + OnExplosion * Update Protocol18PacketTypes.cs + PacketIncomingType.Explosion * Update ChatBot.cs + Fix * Update AutoAttack.cs + Fix * Update ChatBot.cs + Fix * Update Protocol18PacketTypes.cs + Old versions * Update Protocol18PacketTypes.cs + 1.7 - 1.8 Explosion ID * Update Protocol18PacketTypes.cs + Fix * Update McTcpClient.cs + int ExplosionRecordCount * Update ChatBot.cs + recordcount * Update IMinecraftComHandler.cs + ExplosionRecordCount * Update Protocol18.cs * Update CSharpRunner.cs + using MinecraftClient.Inventory; * add OnGamemodeUpdate + OnGamemodeUpdate * + OnGamemodeUpdate(playername, uuid, gamemode) + OnGamemodeUpdate * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McTcpClient.cs Fix * Update McTcpClient.cs * Update Protocol18.cs + Location explodelocation * Update McTcpClient.cs + Location explode * Update ChatBot.cs + Fix * Update ChatBot.cs Remove excess + * Update Plays animation * Improve documentation * ItemType fix * OnExplosion(Location explod); * Update PacketIncomingType.cs add SetExperience, * + Old versions * Update IMinecraftComHandler.cs * Update McTcpClient.cs * Update Protocol18.cs * add GetLevel & GetTotalExperience * Fix * add GetLevel & GetTotalExperience * OnSetExpience * Update ChatBot.cs Fix * Update McTcpClient.cs + bot.OnSetExperience * Update Protocol18.cs + Fix * Update McTcpClient.cs + PlayerDigging * Update PacketOutgoingType.cs + PlayerDigging * Update Protocol18PacketTypes.cs + case PacketOutgoingType.PlayerDigging * Update Protocol18.cs + SendPlayerDigging * Update IMinecraftCom.cs + SendPlayerDigging * Update McTcpClient.cs + PlayerDigging * Update Protocol16.cs + SendPlayerDigging * Update ChatBot.cs + PlayerDigging * Update ChatBot.cs + Fix * Update McTcpClient.cs + Fix * Update ChatBot.cs Add WindowAction * ChatBot.cs Fixes * Further ChatBot.cs fixes * Further ChatBot.cs fixes * Protocol Handler fixes * Protocol Handler fixes * IMinecraftCom fixes * documentation fixes Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-05-29 23:18:34 +05:00
/// <summary>
/// Called when client player's health changed, e.g. getting attack
/// </summary>
/// <param name="health">Player current health</param>
public void OnUpdateHealth(float health, int food)
{
playerHealth = health;
playerFoodSaturation = food;
if (health <= 0)
{
if (Settings.AutoRespawn)
{
Log.Info(Translations.Get("mcc.player_dead_respawn"));
respawnTicks = 10;
}
else
{
Log.Info(Translations.Get("mcc.player_dead"));
}
DispatchBotEvent(bot => bot.OnDeath());
}
DispatchBotEvent(bot => bot.OnHealthUpdate(health, food));
}
Add SendPlaceBlock, PlayerDigging, OnExplosion, OnGamemodeUpdate, OnSetExperience (#1027) * Update ChatBot.cs + PlaceBlock * Update AutoAttack.cs + HitAnimation * Update PacketIncomingType.cs + Explosion, * Update McTcpClient.cs + OnExplosion * Update ChatBot.cs + OnExplosion * Update IMinecraftComHandler.cs + OnExplosion * Update Protocol18PacketTypes.cs + PacketIncomingType.Explosion * Update ChatBot.cs + Fix * Update AutoAttack.cs + Fix * Update ChatBot.cs + Fix * Update Protocol18PacketTypes.cs + Old versions * Update Protocol18PacketTypes.cs + 1.7 - 1.8 Explosion ID * Update Protocol18PacketTypes.cs + Fix * Update McTcpClient.cs + int ExplosionRecordCount * Update ChatBot.cs + recordcount * Update IMinecraftComHandler.cs + ExplosionRecordCount * Update Protocol18.cs * Update CSharpRunner.cs + using MinecraftClient.Inventory; * add OnGamemodeUpdate + OnGamemodeUpdate * + OnGamemodeUpdate(playername, uuid, gamemode) + OnGamemodeUpdate * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McTcpClient.cs Fix * Update McTcpClient.cs * Update Protocol18.cs + Location explodelocation * Update McTcpClient.cs + Location explode * Update ChatBot.cs + Fix * Update ChatBot.cs Remove excess + * Update Plays animation * Improve documentation * ItemType fix * OnExplosion(Location explod); * Update PacketIncomingType.cs add SetExperience, * + Old versions * Update IMinecraftComHandler.cs * Update McTcpClient.cs * Update Protocol18.cs * add GetLevel & GetTotalExperience * Fix * add GetLevel & GetTotalExperience * OnSetExpience * Update ChatBot.cs Fix * Update McTcpClient.cs + bot.OnSetExperience * Update Protocol18.cs + Fix * Update McTcpClient.cs + PlayerDigging * Update PacketOutgoingType.cs + PlayerDigging * Update Protocol18PacketTypes.cs + case PacketOutgoingType.PlayerDigging * Update Protocol18.cs + SendPlayerDigging * Update IMinecraftCom.cs + SendPlayerDigging * Update McTcpClient.cs + PlayerDigging * Update Protocol16.cs + SendPlayerDigging * Update ChatBot.cs + PlayerDigging * Update ChatBot.cs + Fix * Update McTcpClient.cs + Fix * Update ChatBot.cs Add WindowAction * ChatBot.cs Fixes * Further ChatBot.cs fixes * Further ChatBot.cs fixes * Protocol Handler fixes * Protocol Handler fixes * IMinecraftCom fixes * documentation fixes Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-05-29 23:18:34 +05:00
/// <summary>
/// Called when experience updates
/// </summary>
/// <param name="Experiencebar">Between 0 and 1</param>
/// <param name="Level">Level</param>
/// <param name="TotalExperience">Total Experience</param>
public void OnSetExperience(float Experiencebar, int Level, int TotalExperience)
{
playerLevel = Level;
playerTotalExperience = TotalExperience;
DispatchBotEvent(bot => bot.OnSetExperience(Experiencebar, Level, TotalExperience));
Add SendPlaceBlock, PlayerDigging, OnExplosion, OnGamemodeUpdate, OnSetExperience (#1027) * Update ChatBot.cs + PlaceBlock * Update AutoAttack.cs + HitAnimation * Update PacketIncomingType.cs + Explosion, * Update McTcpClient.cs + OnExplosion * Update ChatBot.cs + OnExplosion * Update IMinecraftComHandler.cs + OnExplosion * Update Protocol18PacketTypes.cs + PacketIncomingType.Explosion * Update ChatBot.cs + Fix * Update AutoAttack.cs + Fix * Update ChatBot.cs + Fix * Update Protocol18PacketTypes.cs + Old versions * Update Protocol18PacketTypes.cs + 1.7 - 1.8 Explosion ID * Update Protocol18PacketTypes.cs + Fix * Update McTcpClient.cs + int ExplosionRecordCount * Update ChatBot.cs + recordcount * Update IMinecraftComHandler.cs + ExplosionRecordCount * Update Protocol18.cs * Update CSharpRunner.cs + using MinecraftClient.Inventory; * add OnGamemodeUpdate + OnGamemodeUpdate * + OnGamemodeUpdate(playername, uuid, gamemode) + OnGamemodeUpdate * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McTcpClient.cs Fix * Update McTcpClient.cs * Update Protocol18.cs + Location explodelocation * Update McTcpClient.cs + Location explode * Update ChatBot.cs + Fix * Update ChatBot.cs Remove excess + * Update Plays animation * Improve documentation * ItemType fix * OnExplosion(Location explod); * Update PacketIncomingType.cs add SetExperience, * + Old versions * Update IMinecraftComHandler.cs * Update McTcpClient.cs * Update Protocol18.cs * add GetLevel & GetTotalExperience * Fix * add GetLevel & GetTotalExperience * OnSetExpience * Update ChatBot.cs Fix * Update McTcpClient.cs + bot.OnSetExperience * Update Protocol18.cs + Fix * Update McTcpClient.cs + PlayerDigging * Update PacketOutgoingType.cs + PlayerDigging * Update Protocol18PacketTypes.cs + case PacketOutgoingType.PlayerDigging * Update Protocol18.cs + SendPlayerDigging * Update IMinecraftCom.cs + SendPlayerDigging * Update McTcpClient.cs + PlayerDigging * Update Protocol16.cs + SendPlayerDigging * Update ChatBot.cs + PlayerDigging * Update ChatBot.cs + Fix * Update McTcpClient.cs + Fix * Update ChatBot.cs Add WindowAction * ChatBot.cs Fixes * Further ChatBot.cs fixes * Further ChatBot.cs fixes * Protocol Handler fixes * Protocol Handler fixes * IMinecraftCom fixes * documentation fixes Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-05-29 23:18:34 +05:00
}
/// <summary>
/// Called when and explosion occurs on the server
/// </summary>
/// <param name="location">Explosion location</param>
/// <param name="strength">Explosion strength</param>
/// <param name="affectedBlocks">Amount of affected blocks</param>
public void OnExplosion(Location location, float strength, int affectedBlocks)
{
DispatchBotEvent(bot => bot.OnExplosion(location, strength, affectedBlocks));
Add SendPlaceBlock, PlayerDigging, OnExplosion, OnGamemodeUpdate, OnSetExperience (#1027) * Update ChatBot.cs + PlaceBlock * Update AutoAttack.cs + HitAnimation * Update PacketIncomingType.cs + Explosion, * Update McTcpClient.cs + OnExplosion * Update ChatBot.cs + OnExplosion * Update IMinecraftComHandler.cs + OnExplosion * Update Protocol18PacketTypes.cs + PacketIncomingType.Explosion * Update ChatBot.cs + Fix * Update AutoAttack.cs + Fix * Update ChatBot.cs + Fix * Update Protocol18PacketTypes.cs + Old versions * Update Protocol18PacketTypes.cs + 1.7 - 1.8 Explosion ID * Update Protocol18PacketTypes.cs + Fix * Update McTcpClient.cs + int ExplosionRecordCount * Update ChatBot.cs + recordcount * Update IMinecraftComHandler.cs + ExplosionRecordCount * Update Protocol18.cs * Update CSharpRunner.cs + using MinecraftClient.Inventory; * add OnGamemodeUpdate + OnGamemodeUpdate * + OnGamemodeUpdate(playername, uuid, gamemode) + OnGamemodeUpdate * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McTcpClient.cs Fix * Update McTcpClient.cs * Update Protocol18.cs + Location explodelocation * Update McTcpClient.cs + Location explode * Update ChatBot.cs + Fix * Update ChatBot.cs Remove excess + * Update Plays animation * Improve documentation * ItemType fix * OnExplosion(Location explod); * Update PacketIncomingType.cs add SetExperience, * + Old versions * Update IMinecraftComHandler.cs * Update McTcpClient.cs * Update Protocol18.cs * add GetLevel & GetTotalExperience * Fix * add GetLevel & GetTotalExperience * OnSetExpience * Update ChatBot.cs Fix * Update McTcpClient.cs + bot.OnSetExperience * Update Protocol18.cs + Fix * Update McTcpClient.cs + PlayerDigging * Update PacketOutgoingType.cs + PlayerDigging * Update Protocol18PacketTypes.cs + case PacketOutgoingType.PlayerDigging * Update Protocol18.cs + SendPlayerDigging * Update IMinecraftCom.cs + SendPlayerDigging * Update McTcpClient.cs + PlayerDigging * Update Protocol16.cs + SendPlayerDigging * Update ChatBot.cs + PlayerDigging * Update ChatBot.cs + Fix * Update McTcpClient.cs + Fix * Update ChatBot.cs Add WindowAction * ChatBot.cs Fixes * Further ChatBot.cs fixes * Further ChatBot.cs fixes * Protocol Handler fixes * Protocol Handler fixes * IMinecraftCom fixes * documentation fixes Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-05-29 23:18:34 +05:00
}
/// <summary>
/// Called when Latency is updated
/// </summary>
/// <param name="uuid">player uuid</param>
/// <param name="latency">Latency</param>
public void OnLatencyUpdate(Guid uuid, int latency)
{
if (onlinePlayers.ContainsKey(uuid))
{
PlayerInfo player = onlinePlayers[uuid];
player.Ping = latency;
string playerName = player.Name;
Add Entity.Item, Entity.CustomName, OnEntityMetadata event (#1222) * Add New Event * new Event * Add OnEntityMetadaTa * Update ChatBot.cs * Update Protocol18.cs * Update Entity.cs * EntityCMD Update * Update IMinecraftComHandler.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs * Update McClient.cs * Update Entity.cs * Create EntityPose.cs * Update MinecraftClient.csproj * Update McClient.cs * Update EntityPose.cs * Update Entity.cs * Update McClient.cs * Remove debug line * Update Entitycmd.cs * Update Entity.cs * Update McClient.cs * Update Entity.cs * Update McClient.cs * Update McClient.cs * Update Entity.cs * Update McClient.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update McClient.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entity.cs * Update McClient.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Crash Fix on Item * Crashes Fix * Update McClient.cs * Crashes fix * Update McClient.cs * Update Entity.cs * Update Entity.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update Protocol18.cs * Update ChatBot.cs * Update IMinecraftComHandler.cs * Update Protocol18.cs * Update McClient.cs * Fix unaddressed issues Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-08-20 21:36:50 +05:00
foreach (KeyValuePair<int, Entity> ent in entities)
{
if (ent.Value.UUID == uuid && ent.Value.Name == playerName)
{
ent.Value.Latency = latency;
DispatchBotEvent(bot => bot.OnLatencyUpdate(ent.Value, playerName, uuid, latency));
Add Entity.Item, Entity.CustomName, OnEntityMetadata event (#1222) * Add New Event * new Event * Add OnEntityMetadaTa * Update ChatBot.cs * Update Protocol18.cs * Update Entity.cs * EntityCMD Update * Update IMinecraftComHandler.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs * Update McClient.cs * Update Entity.cs * Create EntityPose.cs * Update MinecraftClient.csproj * Update McClient.cs * Update EntityPose.cs * Update Entity.cs * Update McClient.cs * Remove debug line * Update Entitycmd.cs * Update Entity.cs * Update McClient.cs * Update Entity.cs * Update McClient.cs * Update McClient.cs * Update Entity.cs * Update McClient.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update McClient.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entity.cs * Update McClient.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Crash Fix on Item * Crashes Fix * Update McClient.cs * Crashes fix * Update McClient.cs * Update Entity.cs * Update Entity.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update Protocol18.cs * Update ChatBot.cs * Update IMinecraftComHandler.cs * Update Protocol18.cs * Update McClient.cs * Fix unaddressed issues Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-08-20 21:36:50 +05:00
break;
}
}
DispatchBotEvent(bot => bot.OnLatencyUpdate(playerName, uuid, latency));
}
}
Add SendPlaceBlock, PlayerDigging, OnExplosion, OnGamemodeUpdate, OnSetExperience (#1027) * Update ChatBot.cs + PlaceBlock * Update AutoAttack.cs + HitAnimation * Update PacketIncomingType.cs + Explosion, * Update McTcpClient.cs + OnExplosion * Update ChatBot.cs + OnExplosion * Update IMinecraftComHandler.cs + OnExplosion * Update Protocol18PacketTypes.cs + PacketIncomingType.Explosion * Update ChatBot.cs + Fix * Update AutoAttack.cs + Fix * Update ChatBot.cs + Fix * Update Protocol18PacketTypes.cs + Old versions * Update Protocol18PacketTypes.cs + 1.7 - 1.8 Explosion ID * Update Protocol18PacketTypes.cs + Fix * Update McTcpClient.cs + int ExplosionRecordCount * Update ChatBot.cs + recordcount * Update IMinecraftComHandler.cs + ExplosionRecordCount * Update Protocol18.cs * Update CSharpRunner.cs + using MinecraftClient.Inventory; * add OnGamemodeUpdate + OnGamemodeUpdate * + OnGamemodeUpdate(playername, uuid, gamemode) + OnGamemodeUpdate * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McTcpClient.cs Fix * Update McTcpClient.cs * Update Protocol18.cs + Location explodelocation * Update McTcpClient.cs + Location explode * Update ChatBot.cs + Fix * Update ChatBot.cs Remove excess + * Update Plays animation * Improve documentation * ItemType fix * OnExplosion(Location explod); * Update PacketIncomingType.cs add SetExperience, * + Old versions * Update IMinecraftComHandler.cs * Update McTcpClient.cs * Update Protocol18.cs * add GetLevel & GetTotalExperience * Fix * add GetLevel & GetTotalExperience * OnSetExpience * Update ChatBot.cs Fix * Update McTcpClient.cs + bot.OnSetExperience * Update Protocol18.cs + Fix * Update McTcpClient.cs + PlayerDigging * Update PacketOutgoingType.cs + PlayerDigging * Update Protocol18PacketTypes.cs + case PacketOutgoingType.PlayerDigging * Update Protocol18.cs + SendPlayerDigging * Update IMinecraftCom.cs + SendPlayerDigging * Update McTcpClient.cs + PlayerDigging * Update Protocol16.cs + SendPlayerDigging * Update ChatBot.cs + PlayerDigging * Update ChatBot.cs + Fix * Update McTcpClient.cs + Fix * Update ChatBot.cs Add WindowAction * ChatBot.cs Fixes * Further ChatBot.cs fixes * Further ChatBot.cs fixes * Protocol Handler fixes * Protocol Handler fixes * IMinecraftCom fixes * documentation fixes Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-05-29 23:18:34 +05:00
/// <summary>
Implement OnMapData, OnTitle, UpdateSign, OnEntityEquipment, Useblock (#1071) * + Fix null PlayerInventory + Fix null PlayerInventory * Update Protocol18.cs * Update McTcpClient.cs + Fix https://github.com/ORelio/Minecraft-Console-Client/issues/1022 * Update Protocol18.cs + MapData * Update PacketIncomingType.cs + MapData * Update Protocol18PacketTypes.cs * Update IMinecraftComHandler.cs + OnMapData * Update McTcpClient.cs + OnMapData * Update ChatBot.cs + OnMapData * Update Protocol18.cs * Update Protocol18PacketTypes.cs + Fix * Update PacketIncomingType.cs + Title * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnTitle * Update McTcpClient.cs * Update ChatBot.cs + OnTitle * Update Protocol18.cs Fix * Update IMinecraftComHandler.cs * Update McTcpClient.cs * add ClearInventories() * add ClearInventories() * Update McTcpClient.cs + OnTitle * Preparing to Add BlockAction * Update PacketOutgoingType.cs * Update PacketOutgoingType.cs * Update Protocol18.cs + SendUpdateSign * Update Protocol16.cs + SendUpdateSign * Update IMinecraftCom.cs + SendUpdateSign * Update McTcpClient.cs + UpdateSign * Update ChatBot.cs + UpdateSign * Update McTcpClient.cs Update PlaceBlock * Update ChatBot.cs * Update McTcpClient.cs * add SendCreativeInventoryAction nbt add SendCreativeInventoryAction nbt * Update Protocol18.cs * Update Protocol16.cs * Update McTcpClient.cs * Update ChatBot.cs * Update Inventory.cs * Update Protocol18PacketTypes.cs * Update PacketIncomingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18PacketTypes.cs Fix * Update Protocol18PacketTypes.cs Fix * Update IMinecraftComHandler.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McTcpClient.cs + OnEntityEquipment * Update Protocol18.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update Protocol18.cs * Update McTcpClient.cs * Update ChatBot.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update Protocol18.cs * Create Useblock.cs * Update MinecraftClient.csproj * Update McTcpClient.cs
2020-06-20 17:57:07 +05:00
/// Called when held item change
Add SendPlaceBlock, PlayerDigging, OnExplosion, OnGamemodeUpdate, OnSetExperience (#1027) * Update ChatBot.cs + PlaceBlock * Update AutoAttack.cs + HitAnimation * Update PacketIncomingType.cs + Explosion, * Update McTcpClient.cs + OnExplosion * Update ChatBot.cs + OnExplosion * Update IMinecraftComHandler.cs + OnExplosion * Update Protocol18PacketTypes.cs + PacketIncomingType.Explosion * Update ChatBot.cs + Fix * Update AutoAttack.cs + Fix * Update ChatBot.cs + Fix * Update Protocol18PacketTypes.cs + Old versions * Update Protocol18PacketTypes.cs + 1.7 - 1.8 Explosion ID * Update Protocol18PacketTypes.cs + Fix * Update McTcpClient.cs + int ExplosionRecordCount * Update ChatBot.cs + recordcount * Update IMinecraftComHandler.cs + ExplosionRecordCount * Update Protocol18.cs * Update CSharpRunner.cs + using MinecraftClient.Inventory; * add OnGamemodeUpdate + OnGamemodeUpdate * + OnGamemodeUpdate(playername, uuid, gamemode) + OnGamemodeUpdate * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McTcpClient.cs Fix * Update McTcpClient.cs * Update Protocol18.cs + Location explodelocation * Update McTcpClient.cs + Location explode * Update ChatBot.cs + Fix * Update ChatBot.cs Remove excess + * Update Plays animation * Improve documentation * ItemType fix * OnExplosion(Location explod); * Update PacketIncomingType.cs add SetExperience, * + Old versions * Update IMinecraftComHandler.cs * Update McTcpClient.cs * Update Protocol18.cs * add GetLevel & GetTotalExperience * Fix * add GetLevel & GetTotalExperience * OnSetExpience * Update ChatBot.cs Fix * Update McTcpClient.cs + bot.OnSetExperience * Update Protocol18.cs + Fix * Update McTcpClient.cs + PlayerDigging * Update PacketOutgoingType.cs + PlayerDigging * Update Protocol18PacketTypes.cs + case PacketOutgoingType.PlayerDigging * Update Protocol18.cs + SendPlayerDigging * Update IMinecraftCom.cs + SendPlayerDigging * Update McTcpClient.cs + PlayerDigging * Update Protocol16.cs + SendPlayerDigging * Update ChatBot.cs + PlayerDigging * Update ChatBot.cs + Fix * Update McTcpClient.cs + Fix * Update ChatBot.cs Add WindowAction * ChatBot.cs Fixes * Further ChatBot.cs fixes * Further ChatBot.cs fixes * Protocol Handler fixes * Protocol Handler fixes * IMinecraftCom fixes * documentation fixes Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-05-29 23:18:34 +05:00
/// </summary>
Implement OnMapData, OnTitle, UpdateSign, OnEntityEquipment, Useblock (#1071) * + Fix null PlayerInventory + Fix null PlayerInventory * Update Protocol18.cs * Update McTcpClient.cs + Fix https://github.com/ORelio/Minecraft-Console-Client/issues/1022 * Update Protocol18.cs + MapData * Update PacketIncomingType.cs + MapData * Update Protocol18PacketTypes.cs * Update IMinecraftComHandler.cs + OnMapData * Update McTcpClient.cs + OnMapData * Update ChatBot.cs + OnMapData * Update Protocol18.cs * Update Protocol18PacketTypes.cs + Fix * Update PacketIncomingType.cs + Title * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnTitle * Update McTcpClient.cs * Update ChatBot.cs + OnTitle * Update Protocol18.cs Fix * Update IMinecraftComHandler.cs * Update McTcpClient.cs * add ClearInventories() * add ClearInventories() * Update McTcpClient.cs + OnTitle * Preparing to Add BlockAction * Update PacketOutgoingType.cs * Update PacketOutgoingType.cs * Update Protocol18.cs + SendUpdateSign * Update Protocol16.cs + SendUpdateSign * Update IMinecraftCom.cs + SendUpdateSign * Update McTcpClient.cs + UpdateSign * Update ChatBot.cs + UpdateSign * Update McTcpClient.cs Update PlaceBlock * Update ChatBot.cs * Update McTcpClient.cs * add SendCreativeInventoryAction nbt add SendCreativeInventoryAction nbt * Update Protocol18.cs * Update Protocol16.cs * Update McTcpClient.cs * Update ChatBot.cs * Update Inventory.cs * Update Protocol18PacketTypes.cs * Update PacketIncomingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18PacketTypes.cs Fix * Update Protocol18PacketTypes.cs Fix * Update IMinecraftComHandler.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McTcpClient.cs + OnEntityEquipment * Update Protocol18.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update Protocol18.cs * Update McTcpClient.cs * Update ChatBot.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update Protocol18.cs * Create Useblock.cs * Update MinecraftClient.csproj * Update McTcpClient.cs
2020-06-20 17:57:07 +05:00
/// <param name="slot"> item slot</param>
public void OnHeldItemChange(byte slot)
{
CurrentSlot = slot;
DispatchBotEvent(bot => bot.OnHeldItemChange(slot));
}
Implement OnMapData, OnTitle, UpdateSign, OnEntityEquipment, Useblock (#1071) * + Fix null PlayerInventory + Fix null PlayerInventory * Update Protocol18.cs * Update McTcpClient.cs + Fix https://github.com/ORelio/Minecraft-Console-Client/issues/1022 * Update Protocol18.cs + MapData * Update PacketIncomingType.cs + MapData * Update Protocol18PacketTypes.cs * Update IMinecraftComHandler.cs + OnMapData * Update McTcpClient.cs + OnMapData * Update ChatBot.cs + OnMapData * Update Protocol18.cs * Update Protocol18PacketTypes.cs + Fix * Update PacketIncomingType.cs + Title * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnTitle * Update McTcpClient.cs * Update ChatBot.cs + OnTitle * Update Protocol18.cs Fix * Update IMinecraftComHandler.cs * Update McTcpClient.cs * add ClearInventories() * add ClearInventories() * Update McTcpClient.cs + OnTitle * Preparing to Add BlockAction * Update PacketOutgoingType.cs * Update PacketOutgoingType.cs * Update Protocol18.cs + SendUpdateSign * Update Protocol16.cs + SendUpdateSign * Update IMinecraftCom.cs + SendUpdateSign * Update McTcpClient.cs + UpdateSign * Update ChatBot.cs + UpdateSign * Update McTcpClient.cs Update PlaceBlock * Update ChatBot.cs * Update McTcpClient.cs * add SendCreativeInventoryAction nbt add SendCreativeInventoryAction nbt * Update Protocol18.cs * Update Protocol16.cs * Update McTcpClient.cs * Update ChatBot.cs * Update Inventory.cs * Update Protocol18PacketTypes.cs * Update PacketIncomingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18PacketTypes.cs Fix * Update Protocol18PacketTypes.cs Fix * Update IMinecraftComHandler.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McTcpClient.cs + OnEntityEquipment * Update Protocol18.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update Protocol18.cs * Update McTcpClient.cs * Update ChatBot.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update Protocol18.cs * Create Useblock.cs * Update MinecraftClient.csproj * Update McTcpClient.cs
2020-06-20 17:57:07 +05:00
/// <summary>
/// Called map data
/// </summary>
/// <param name="mapid"></param>
/// <param name="scale"></param>
/// <param name="trackingposition"></param>
/// <param name="locked"></param>
/// <param name="iconcount"></param>
public void OnMapData(int mapid, byte scale, bool trackingposition, bool locked, int iconcount)
{
DispatchBotEvent(bot => bot.OnMapData(mapid, scale, trackingposition, locked, iconcount));
Implement OnMapData, OnTitle, UpdateSign, OnEntityEquipment, Useblock (#1071) * + Fix null PlayerInventory + Fix null PlayerInventory * Update Protocol18.cs * Update McTcpClient.cs + Fix https://github.com/ORelio/Minecraft-Console-Client/issues/1022 * Update Protocol18.cs + MapData * Update PacketIncomingType.cs + MapData * Update Protocol18PacketTypes.cs * Update IMinecraftComHandler.cs + OnMapData * Update McTcpClient.cs + OnMapData * Update ChatBot.cs + OnMapData * Update Protocol18.cs * Update Protocol18PacketTypes.cs + Fix * Update PacketIncomingType.cs + Title * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnTitle * Update McTcpClient.cs * Update ChatBot.cs + OnTitle * Update Protocol18.cs Fix * Update IMinecraftComHandler.cs * Update McTcpClient.cs * add ClearInventories() * add ClearInventories() * Update McTcpClient.cs + OnTitle * Preparing to Add BlockAction * Update PacketOutgoingType.cs * Update PacketOutgoingType.cs * Update Protocol18.cs + SendUpdateSign * Update Protocol16.cs + SendUpdateSign * Update IMinecraftCom.cs + SendUpdateSign * Update McTcpClient.cs + UpdateSign * Update ChatBot.cs + UpdateSign * Update McTcpClient.cs Update PlaceBlock * Update ChatBot.cs * Update McTcpClient.cs * add SendCreativeInventoryAction nbt add SendCreativeInventoryAction nbt * Update Protocol18.cs * Update Protocol16.cs * Update McTcpClient.cs * Update ChatBot.cs * Update Inventory.cs * Update Protocol18PacketTypes.cs * Update PacketIncomingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18PacketTypes.cs Fix * Update Protocol18PacketTypes.cs Fix * Update IMinecraftComHandler.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McTcpClient.cs + OnEntityEquipment * Update Protocol18.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update Protocol18.cs * Update McTcpClient.cs * Update ChatBot.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update Protocol18.cs * Create Useblock.cs * Update MinecraftClient.csproj * Update McTcpClient.cs
2020-06-20 17:57:07 +05:00
}
Implement OnMapData, OnTitle, UpdateSign, OnEntityEquipment, Useblock (#1071) * + Fix null PlayerInventory + Fix null PlayerInventory * Update Protocol18.cs * Update McTcpClient.cs + Fix https://github.com/ORelio/Minecraft-Console-Client/issues/1022 * Update Protocol18.cs + MapData * Update PacketIncomingType.cs + MapData * Update Protocol18PacketTypes.cs * Update IMinecraftComHandler.cs + OnMapData * Update McTcpClient.cs + OnMapData * Update ChatBot.cs + OnMapData * Update Protocol18.cs * Update Protocol18PacketTypes.cs + Fix * Update PacketIncomingType.cs + Title * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnTitle * Update McTcpClient.cs * Update ChatBot.cs + OnTitle * Update Protocol18.cs Fix * Update IMinecraftComHandler.cs * Update McTcpClient.cs * add ClearInventories() * add ClearInventories() * Update McTcpClient.cs + OnTitle * Preparing to Add BlockAction * Update PacketOutgoingType.cs * Update PacketOutgoingType.cs * Update Protocol18.cs + SendUpdateSign * Update Protocol16.cs + SendUpdateSign * Update IMinecraftCom.cs + SendUpdateSign * Update McTcpClient.cs + UpdateSign * Update ChatBot.cs + UpdateSign * Update McTcpClient.cs Update PlaceBlock * Update ChatBot.cs * Update McTcpClient.cs * add SendCreativeInventoryAction nbt add SendCreativeInventoryAction nbt * Update Protocol18.cs * Update Protocol16.cs * Update McTcpClient.cs * Update ChatBot.cs * Update Inventory.cs * Update Protocol18PacketTypes.cs * Update PacketIncomingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18PacketTypes.cs Fix * Update Protocol18PacketTypes.cs Fix * Update IMinecraftComHandler.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McTcpClient.cs + OnEntityEquipment * Update Protocol18.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update Protocol18.cs * Update McTcpClient.cs * Update ChatBot.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update Protocol18.cs * Create Useblock.cs * Update MinecraftClient.csproj * Update McTcpClient.cs
2020-06-20 17:57:07 +05:00
/// <summary>
/// Received some Title from the server
/// <param name="action"> 0 = set title, 1 = set subtitle, 3 = set action bar, 4 = set times and display, 4 = hide, 5 = reset</param>
/// <param name="titletext"> title text</param>
/// <param name="subtitletext"> suntitle text</param>
/// <param name="actionbartext"> action bar text</param>
/// <param name="fadein"> Fade In</param>
/// <param name="stay"> Stay</param>
/// <param name="fadeout"> Fade Out</param>
/// <param name="json"> json text</param>
public void OnTitle(int action, string titletext, string subtitletext, string actionbartext, int fadein, int stay, int fadeout, string json)
{
DispatchBotEvent(bot => bot.OnTitle(action, titletext, subtitletext, actionbartext, fadein, stay, fadeout, json));
Implement OnMapData, OnTitle, UpdateSign, OnEntityEquipment, Useblock (#1071) * + Fix null PlayerInventory + Fix null PlayerInventory * Update Protocol18.cs * Update McTcpClient.cs + Fix https://github.com/ORelio/Minecraft-Console-Client/issues/1022 * Update Protocol18.cs + MapData * Update PacketIncomingType.cs + MapData * Update Protocol18PacketTypes.cs * Update IMinecraftComHandler.cs + OnMapData * Update McTcpClient.cs + OnMapData * Update ChatBot.cs + OnMapData * Update Protocol18.cs * Update Protocol18PacketTypes.cs + Fix * Update PacketIncomingType.cs + Title * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnTitle * Update McTcpClient.cs * Update ChatBot.cs + OnTitle * Update Protocol18.cs Fix * Update IMinecraftComHandler.cs * Update McTcpClient.cs * add ClearInventories() * add ClearInventories() * Update McTcpClient.cs + OnTitle * Preparing to Add BlockAction * Update PacketOutgoingType.cs * Update PacketOutgoingType.cs * Update Protocol18.cs + SendUpdateSign * Update Protocol16.cs + SendUpdateSign * Update IMinecraftCom.cs + SendUpdateSign * Update McTcpClient.cs + UpdateSign * Update ChatBot.cs + UpdateSign * Update McTcpClient.cs Update PlaceBlock * Update ChatBot.cs * Update McTcpClient.cs * add SendCreativeInventoryAction nbt add SendCreativeInventoryAction nbt * Update Protocol18.cs * Update Protocol16.cs * Update McTcpClient.cs * Update ChatBot.cs * Update Inventory.cs * Update Protocol18PacketTypes.cs * Update PacketIncomingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18PacketTypes.cs Fix * Update Protocol18PacketTypes.cs Fix * Update IMinecraftComHandler.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McTcpClient.cs + OnEntityEquipment * Update Protocol18.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update Protocol18.cs * Update McTcpClient.cs * Update ChatBot.cs * Update ChatBot.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update McTcpClient.cs * Update Protocol18.cs * Create Useblock.cs * Update MinecraftClient.csproj * Update McTcpClient.cs
2020-06-20 17:57:07 +05:00
}
ChatBot API: OnScoreboardObjective, OnEntityEffect, OnUpdateScore, EntityInteract, Hand list (#1097) * Create Effect.cs * Rename Effect.cs to Effects.cs * Update MinecraftClient.csproj * Update Effects.cs * Update Effects.cs * add EntityEffect * Update McClient.cs * Update Protocol18.cs + EntityEffect * Update IMinecraftComHandler.cs * Update Protocol18PacketTypes.cs + EntityEffect * Update ChatBot.cs + OnEntityEquipment * Update PacketIncomingType.cs + ScoreboardObjective * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnScoreboardObjective * Update McClient.cs + OnScoreboardObjective * Update ChatBot.cs + OnScoreboardObjective event * Update Protocol18.cs: fix scoreboard * Update McClient.cs * Update ChatBot.cs * Update PacketIncomingType.cs * Update ChatBot.cs + OnUpdateScore * Update McClient.cs + OnUpdateScore * Update IMinecraftComHandler.cs + OnUpdateScore * Update Protocol18.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs + fix micro lags * Update Protocol18.cs * Update Protocol18.cs * Update Protocol18.cs * Update Protocol16.cs * Update Protocol18.cs * Update McClient.cs * Update IMinecraftCom.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs + GetEntities() * Create Hand.cs * Update MinecraftClient.csproj * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs: fix * Update AutoAttack.cs: Fix * Update McClient.cs: compile fix * Update ChatBot.cs * Update AutoAttack.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McClient.cs * Update McClient.cs: remove check distance * Update EntityActionType.cs: more actions * Create CommandBlockMode.cs * Create CommandBlockFlags.cs * Update IMinecraftCom.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update Protocol16.cs * Update PacketOutgoingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs
2020-07-04 13:45:51 +05:00
/// <summary>
/// Called when coreboardObjective
/// </summary>
/// <param name="objectivename">objective name</param>
/// <param name="mode">0 to create the scoreboard. 1 to remove the scoreboard. 2 to update the display text.</param>
/// <param name="objectivevalue">Only if mode is 0 or 2. The text to be displayed for the score</param>
/// <param name="type">Only if mode is 0 or 2. 0 = "integer", 1 = "hearts".</param>
public void OnScoreboardObjective(string objectivename, byte mode, string objectivevalue, int type)
{
string json = objectivevalue;
objectivevalue = ChatParser.ParseText(objectivevalue);
DispatchBotEvent(bot => bot.OnScoreboardObjective(objectivename, mode, objectivevalue, type, json));
}
ChatBot API: OnScoreboardObjective, OnEntityEffect, OnUpdateScore, EntityInteract, Hand list (#1097) * Create Effect.cs * Rename Effect.cs to Effects.cs * Update MinecraftClient.csproj * Update Effects.cs * Update Effects.cs * add EntityEffect * Update McClient.cs * Update Protocol18.cs + EntityEffect * Update IMinecraftComHandler.cs * Update Protocol18PacketTypes.cs + EntityEffect * Update ChatBot.cs + OnEntityEquipment * Update PacketIncomingType.cs + ScoreboardObjective * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnScoreboardObjective * Update McClient.cs + OnScoreboardObjective * Update ChatBot.cs + OnScoreboardObjective event * Update Protocol18.cs: fix scoreboard * Update McClient.cs * Update ChatBot.cs * Update PacketIncomingType.cs * Update ChatBot.cs + OnUpdateScore * Update McClient.cs + OnUpdateScore * Update IMinecraftComHandler.cs + OnUpdateScore * Update Protocol18.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs + fix micro lags * Update Protocol18.cs * Update Protocol18.cs * Update Protocol18.cs * Update Protocol16.cs * Update Protocol18.cs * Update McClient.cs * Update IMinecraftCom.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs + GetEntities() * Create Hand.cs * Update MinecraftClient.csproj * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs: fix * Update AutoAttack.cs: Fix * Update McClient.cs: compile fix * Update ChatBot.cs * Update AutoAttack.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McClient.cs * Update McClient.cs: remove check distance * Update EntityActionType.cs: more actions * Create CommandBlockMode.cs * Create CommandBlockFlags.cs * Update IMinecraftCom.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update Protocol16.cs * Update PacketOutgoingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs
2020-07-04 13:45:51 +05:00
/// <summary>
/// Called when DisplayScoreboard
/// </summary>
/// <param name="entityname">The entity whose score this is. For players, this is their username; for other entities, it is their UUID.</param>
/// <param name="action">0 to create/update an item. 1 to remove an item.</param>
/// <param name="objectivename">The name of the objective the score belongs to</param>
/// <param name="value">he score to be displayed next to the entry. Only sent when Action does not equal 1.</param>
public void OnUpdateScore(string entityname, int action, string objectivename, int value)
ChatBot API: OnScoreboardObjective, OnEntityEffect, OnUpdateScore, EntityInteract, Hand list (#1097) * Create Effect.cs * Rename Effect.cs to Effects.cs * Update MinecraftClient.csproj * Update Effects.cs * Update Effects.cs * add EntityEffect * Update McClient.cs * Update Protocol18.cs + EntityEffect * Update IMinecraftComHandler.cs * Update Protocol18PacketTypes.cs + EntityEffect * Update ChatBot.cs + OnEntityEquipment * Update PacketIncomingType.cs + ScoreboardObjective * Update Protocol18PacketTypes.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs + OnScoreboardObjective * Update McClient.cs + OnScoreboardObjective * Update ChatBot.cs + OnScoreboardObjective event * Update Protocol18.cs: fix scoreboard * Update McClient.cs * Update ChatBot.cs * Update PacketIncomingType.cs * Update ChatBot.cs + OnUpdateScore * Update McClient.cs + OnUpdateScore * Update IMinecraftComHandler.cs + OnUpdateScore * Update Protocol18.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs + fix micro lags * Update Protocol18.cs * Update Protocol18.cs * Update Protocol18.cs * Update Protocol16.cs * Update Protocol18.cs * Update McClient.cs * Update IMinecraftCom.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs + GetEntities() * Create Hand.cs * Update MinecraftClient.csproj * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs * Update ChatBot.cs: fix * Update AutoAttack.cs: Fix * Update McClient.cs: compile fix * Update ChatBot.cs * Update AutoAttack.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update ChatBot.cs * Update McClient.cs * Update McClient.cs: remove check distance * Update EntityActionType.cs: more actions * Create CommandBlockMode.cs * Create CommandBlockFlags.cs * Update IMinecraftCom.cs * Update McClient.cs * Update ChatBot.cs * Update Protocol18.cs * Update Protocol16.cs * Update PacketOutgoingType.cs * Update Protocol18PacketTypes.cs * Update Protocol18.cs
2020-07-04 13:45:51 +05:00
{
DispatchBotEvent(bot => bot.OnUpdateScore(entityname, action, objectivename, value));
}
/// <summary>
/// Called when the health of an entity changed
/// </summary>
/// <param name="entityID">Entity ID</param>
/// <param name="health">The health of the entity</param>
public void OnEntityHealth(int entityID, float health)
{
if (entities.ContainsKey(entityID))
{
entities[entityID].Health = health;
Add Entity.Item, Entity.CustomName, OnEntityMetadata event (#1222) * Add New Event * new Event * Add OnEntityMetadaTa * Update ChatBot.cs * Update Protocol18.cs * Update Entity.cs * EntityCMD Update * Update IMinecraftComHandler.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs * Update McClient.cs * Update Entity.cs * Create EntityPose.cs * Update MinecraftClient.csproj * Update McClient.cs * Update EntityPose.cs * Update Entity.cs * Update McClient.cs * Remove debug line * Update Entitycmd.cs * Update Entity.cs * Update McClient.cs * Update Entity.cs * Update McClient.cs * Update McClient.cs * Update Entity.cs * Update McClient.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update McClient.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entity.cs * Update McClient.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Crash Fix on Item * Crashes Fix * Update McClient.cs * Crashes fix * Update McClient.cs * Update Entity.cs * Update Entity.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update Protocol18.cs * Update ChatBot.cs * Update IMinecraftComHandler.cs * Update Protocol18.cs * Update McClient.cs * Fix unaddressed issues Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-08-20 21:36:50 +05:00
DispatchBotEvent(bot => bot.OnEntityHealth(entities[entityID], health));
}
}
/// <summary>
/// Called when the metadata of an entity changed
/// </summary>
/// <param name="entityID">Entity ID</param>
/// <param name="metadata">The metadata of the entity</param>
public void OnEntityMetadata(int entityID, Dictionary<int, object> metadata)
{
if (entities.ContainsKey(entityID))
{
Entity entity = entities[entityID];
entity.Metadata = metadata;
if (entity.Type.ContainsItem() && metadata.ContainsKey(7) && metadata[7] != null && metadata[7].GetType() == typeof(Item))
Add Entity.Item, Entity.CustomName, OnEntityMetadata event (#1222) * Add New Event * new Event * Add OnEntityMetadaTa * Update ChatBot.cs * Update Protocol18.cs * Update Entity.cs * EntityCMD Update * Update IMinecraftComHandler.cs * Update Protocol18.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs * Update McClient.cs * Update Entity.cs * Create EntityPose.cs * Update MinecraftClient.csproj * Update McClient.cs * Update EntityPose.cs * Update Entity.cs * Update McClient.cs * Remove debug line * Update Entitycmd.cs * Update Entity.cs * Update McClient.cs * Update Entity.cs * Update McClient.cs * Update McClient.cs * Update Entity.cs * Update McClient.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update McClient.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entity.cs * Update McClient.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Update Entitycmd.cs * Crash Fix on Item * Crashes Fix * Update McClient.cs * Crashes fix * Update McClient.cs * Update Entity.cs * Update Entity.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update McClient.cs * Update ChatBot.cs * Update IMinecraftComHandler.cs * Update McClient.cs * Update Protocol18.cs * Update ChatBot.cs * Update IMinecraftComHandler.cs * Update Protocol18.cs * Update McClient.cs * Fix unaddressed issues Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-08-20 21:36:50 +05:00
{
Item item = (Item)metadata[7];
if (item == null)
entity.Item = new Item(ItemType.Air, 0, null);
else entity.Item = item;
}
if (metadata.ContainsKey(6) && metadata[6] != null && metadata[6].GetType() == typeof(Int32))
{
entity.Pose = (EntityPose)metadata[6];
}
if (metadata.ContainsKey(2) && metadata[2] != null && metadata[2].GetType() == typeof(string))
{
entity.CustomNameJson = metadata[2].ToString();
entity.CustomName = ChatParser.ParseText(metadata[2].ToString());
}
if (metadata.ContainsKey(3) && metadata[3] != null && metadata[3].GetType() == typeof(bool))
{
entity.IsCustomNameVisible = bool.Parse(metadata[3].ToString());
}
DispatchBotEvent(bot => bot.OnEntityMetadata(entity, metadata));
}
}
/// <summary>
/// Called when tradeList is recieved after interacting with villager
/// </summary>
/// <param name="windowID">Window ID</param>
/// <param name="trades">List of trades.</param>
/// <param name="villagerInfo">Contains Level, Experience, IsRegularVillager and CanRestock .</param>
public void OnTradeList(int windowID, List<VillagerTrade> trades, VillagerInfo villagerInfo)
{
DispatchBotEvent(bot => bot.OnTradeList(windowID, trades, villagerInfo));
}
/// <summary>
/// Will be called every player break block in gamemode 0
/// </summary>
/// <param name="entityId">Player ID</param>
/// <param name="location">Block location</param>
/// <param name="stage">Destroy stage, maximum 255</param>
public void OnBlockBreakAnimation(int entityId, Location location, byte stage)
{
if (entities.ContainsKey(entityId))
{
Entity entity = entities[entityId];
DispatchBotEvent(bot => bot.OnBlockBreakAnimation(entity, location, stage));
}
}
/// <summary>
/// Will be called every animations of the hit and place block
/// </summary>
/// <param name="entityID">Player ID</param>
/// <param name="animation">0 = LMB, 1 = RMB (RMB Corrent not work)</param>
public void OnEntityAnimation(int entityID, byte animation)
{
if (entities.ContainsKey(entityID))
{
Entity entity = entities[entityID];
DispatchBotEvent(bot => bot.OnEntityAnimation(entity, animation));
}
}
/// <summary>
/// Will be called when a Synchronization sequence is recevied, this sequence need to be sent when breaking or placing blocks
/// </summary>
/// <param name="sequenceId">Sequence ID</param>
public void OnBlockChangeAck(int sequenceId)
{
this.sequenceId = sequenceId;
}
/// <summary>
/// This method is called when the protocol handler receives server data
/// </summary>
/// <param name="hasMotd">Indicates if the server has a motd message</param>
/// <param name="motd">Server MOTD message</param>
/// <param name="hasIcon">Indicates if the server has a an icon</param>
/// <param name="iconBase64">Server icon in Base 64 format</param>
/// <param name="previewsChat">Indicates if the server previews chat</param>
public void OnServerDataRecived(bool hasMotd, string motd, bool hasIcon, string iconBase64, bool previewsChat)
{
this.isSupportPreviewsChat = previewsChat;
}
/// <summary>
/// This method is called when the protocol handler receives "Set Display Chat Preview" packet
/// </summary>
/// <param name="previewsChat">Indicates if the server previews chat</param>
public void OnChatPreviewSettingUpdate(bool previewsChat)
{
this.isSupportPreviewsChat = previewsChat;
}
/// <summary>
/// This method is called when the protocol handler receives "Login Success" packet
/// </summary>
/// <param name="uuid">The player's UUID received from the server</param>
/// <param name="userName">The player's username received from the server</param>
/// <param name="playerProperty">Tuple<Name, Value, Signature(empty if there is no signature)></param>
public void OnLoginSuccess(Guid uuid, string userName, Tuple<string, string, string>[]? playerProperty)
{
//string UUID = uuid.ToString().Replace("-", String.Empty);
//Log.Info("now UUID = " + this.uuid);
//Log.Info("new UUID = " + UUID);
////handler.SetUserUUID(UUID);
}
#endregion
}
}