Added Entity Action handling, and A TSneak command that will Toggle Sneak.

This commit is contained in:
CarbonNeuron 2020-05-01 08:28:22 -05:00
parent 9dae40153c
commit 384c804e54
10 changed files with 176 additions and 5 deletions

View file

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MinecraftClient.Mapping;
namespace MinecraftClient.ChatBots
{
public class AutoLook : ChatBot
{
private Entity _entityToLookAt;
public override void Initialize()
{
if (GetEntityHandlingEnabled() && GetTerrainEnabled()) return;
LogToConsole("Entity Handling or Terrain Handling is not enabled in the config file!");
LogToConsole("This bot will be unloaded.");
UnloadBot();
}
public override void OnEntityDespawn(Entity entity)
{
if (entity == _entityToLookAt)
{
_entityToLookAt = null;
}
}
public override void OnEntitySpawn(Entity entity)
{
HandleEntity(entity);
}
public override void OnEntityMove(Entity entity)
{
var tempBool = HandleEntity(entity);
LogDebugToConsole(tempBool);
if (!tempBool) return;
LookAtLocation(entity.Location);
}
/// <summary>
/// Handles an entity, and tracks it if it is closer then the one we are currently tracking
/// </summary>
/// <returns>True if found</returns>
private bool HandleEntity(Entity entity)
{
if (entity.Type != EntityType.Player)
{
return false;
}
if (_entityToLookAt == null)
{
_entityToLookAt = entity;
return true;
}
if (GetCurrentLocation().Distance(entity.Location) < GetCurrentLocation().Distance(_entityToLookAt.Location))
{
_entityToLookAt = entity;
return true;
}
if (entity.ID != _entityToLookAt.ID) return false;
_entityToLookAt = entity; //Handle looking at the same entity
return true;
}
}
}

View file

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MinecraftClient.Commands
{
public class Sneak : Command
{
private bool sneaking = false;
public override string CMDName { get { return "TSneak"; } }
public override string CMDDesc { get { return "Sneak: Toggles sneaking"; } }
public override string Run(McTcpClient handler, string command, Dictionary<string, object> localVars)
{
if (sneaking)
{
var result = handler.sendEntityAction(Protocol.ActionType.StopSneaking);
sneaking = false;
return result ? "Success" : "Fail";
}
else
{
var result = handler.sendEntityAction(Protocol.ActionType.StartSneaking);
sneaking = true;
return result ? "Success" : "Fail";
}
}
}
}

View file

@ -170,6 +170,8 @@ namespace MinecraftClient
if (Settings.AutoAttack_Enabled) { BotLoad(new ChatBots.AutoAttack()); } if (Settings.AutoAttack_Enabled) { BotLoad(new ChatBots.AutoAttack()); }
if (Settings.AutoFishing_Enabled) { BotLoad(new ChatBots.AutoFishing()); } if (Settings.AutoFishing_Enabled) { BotLoad(new ChatBots.AutoFishing()); }
if (Settings.AutoEat_Enabled) { BotLoad(new ChatBots.AutoEat(Settings.AutoEat_hungerThreshold)); } if (Settings.AutoEat_Enabled) { BotLoad(new ChatBots.AutoEat(Settings.AutoEat_hungerThreshold)); }
if (Settings.AutoLook_Enabled) { BotLoad(new ChatBots.AutoLook()); }
//Add your ChatBot here by uncommenting and adapting //Add your ChatBot here by uncommenting and adapting
//BotLoad(new ChatBots.YourBot()); //BotLoad(new ChatBots.YourBot());
} }
@ -1356,6 +1358,7 @@ namespace MinecraftClient
} }
} }
/// <summary> /// <summary>
/// Called when an entity moved over 8 block. /// Called when an entity moved over 8 block.
/// </summary> /// </summary>
@ -1469,6 +1472,14 @@ namespace MinecraftClient
playerEntityID = EntityID; playerEntityID = EntityID;
} }
/// <summary>
/// Send the Entity Action packet with the Specified ID
/// </summary>
/// <returns>TRUE if the item was successfully used</returns>
public bool sendEntityAction(ActionType action)
{
return handler.SendEntityAction(playerEntityID, (int) action);
}
/// <summary> /// <summary>
/// Use the item currently in the player's hand /// Use the item currently in the player's hand
/// </summary> /// </summary>

View file

@ -78,6 +78,7 @@
<Compile Include="ChatBots\AutoAttack.cs" /> <Compile Include="ChatBots\AutoAttack.cs" />
<Compile Include="ChatBots\AutoEat.cs" /> <Compile Include="ChatBots\AutoEat.cs" />
<Compile Include="ChatBots\AutoFishing.cs" /> <Compile Include="ChatBots\AutoFishing.cs" />
<Compile Include="ChatBots\AutoLook.cs" />
<Compile Include="ChatBots\AutoRespond.cs" /> <Compile Include="ChatBots\AutoRespond.cs" />
<Compile Include="ChatBots\AutoRelog.cs" /> <Compile Include="ChatBots\AutoRelog.cs" />
<Compile Include="ChatBots\ChatLog.cs" /> <Compile Include="ChatBots\ChatLog.cs" />
@ -103,6 +104,7 @@
<Compile Include="Commands\Send.cs" /> <Compile Include="Commands\Send.cs" />
<Compile Include="Commands\Set.cs" /> <Compile Include="Commands\Set.cs" />
<Compile Include="Commands\Health.cs" /> <Compile Include="Commands\Health.cs" />
<Compile Include="Commands\Sneak.cs" />
<Compile Include="Commands\UseItem.cs" /> <Compile Include="Commands\UseItem.cs" />
<Compile Include="Inventory\Container.cs" /> <Compile Include="Inventory\Container.cs" />
<Compile Include="Inventory\ContainerType.cs" /> <Compile Include="Inventory\ContainerType.cs" />
@ -119,6 +121,7 @@
<Compile Include="Mapping\Entity.cs" /> <Compile Include="Mapping\Entity.cs" />
<Compile Include="Mapping\EntityType.cs" /> <Compile Include="Mapping\EntityType.cs" />
<Compile Include="Mapping\MaterialExtensions.cs" /> <Compile Include="Mapping\MaterialExtensions.cs" />
<Compile Include="Protocol\Action.cs" />
<Compile Include="Protocol\Handlers\DataTypes.cs" /> <Compile Include="Protocol\Handlers\DataTypes.cs" />
<Compile Include="Protocol\Handlers\PacketIncomingType.cs" /> <Compile Include="Protocol\Handlers\PacketIncomingType.cs" />
<Compile Include="Protocol\Handlers\PacketOutgoingType.cs" /> <Compile Include="Protocol\Handlers\PacketOutgoingType.cs" />

View file

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MinecraftClient.Protocol
{
public enum ActionType
{
StartSneaking,
StopSneaking,
LeaveBed,
StartSprinting,
StopSprinting
}
}

View file

@ -17,6 +17,7 @@ namespace MinecraftClient.Protocol.Handlers
ClientSettings, ClientSettings,
PluginMessage, PluginMessage,
TabComplete, TabComplete,
EntityAction,
PlayerPosition, PlayerPosition,
PlayerPositionAndLook, PlayerPositionAndLook,
TeleportConfirm, TeleportConfirm,
@ -27,4 +28,4 @@ namespace MinecraftClient.Protocol.Handlers
CloseWindow, CloseWindow,
PlayerBlockPlacement PlayerBlockPlacement
} }
} }

View file

@ -239,6 +239,10 @@ namespace MinecraftClient.Protocol.Handlers
} }
else return ""; else return "";
} }
public bool SendEntityAction(int PlayerEntityID, int ActionID)
{
return true;
}
private byte[] readNextByteArray() private byte[] readNextByteArray()
{ {

View file

@ -965,6 +965,22 @@ namespace MinecraftClient.Protocol.Handlers
catch (System.IO.IOException) { return false; } catch (System.IO.IOException) { return false; }
catch (ObjectDisposedException) { return false; } catch (ObjectDisposedException) { return false; }
} }
public bool SendEntityAction(int PlayerEntityID, int ActionID)
{
try
{
List<byte> fields = new List<byte>();
fields.AddRange(dataTypes.GetVarInt(PlayerEntityID));
fields.AddRange(dataTypes.GetVarInt(ActionID));
fields.AddRange(dataTypes.GetVarInt(0));
SendPacket(PacketOutgoingType.EntityAction, fields);
return true;
}
catch (SocketException) { return false; }
catch (System.IO.IOException) { return false; }
catch (ObjectDisposedException) { return false; }
}
/// <summary> /// <summary>
/// Send a respawn packet to the server /// Send a respawn packet to the server

View file

@ -85,7 +85,15 @@ namespace MinecraftClient.Protocol
/// <param name="data">packet Data</param> /// <param name="data">packet Data</param>
/// <returns>True if message was successfully sent</returns> /// <returns>True if message was successfully sent</returns>
bool SendPluginChannelPacket(string channel, byte[] data); bool SendPluginChannelPacket(string channel, byte[] data);
/// <summary>
/// Send Entity Action packet to the server.
/// </summary>
/// <param name="entityID">PlayerID</param>
/// <param name="type">Type of packet to send</param>
/// <returns>True if packet was successfully sent</returns>
bool SendEntityAction(int EntityID, int type);
/// <summary> /// <summary>
/// Send a held item change packet to the server. /// Send a held item change packet to the server.
/// </summary> /// </summary>

View file

@ -161,13 +161,16 @@ namespace MinecraftClient
//Auto Eating //Auto Eating
public static bool AutoEat_Enabled = false; public static bool AutoEat_Enabled = false;
public static int AutoEat_hungerThreshold = 6; public static int AutoEat_hungerThreshold = 6;
//Auto Looking
public static bool AutoLook_Enabled = false;
//Custom app variables and Minecraft accounts //Custom app variables and Minecraft accounts
private static readonly Dictionary<string, object> AppVars = new Dictionary<string, object>(); private static readonly Dictionary<string, object> AppVars = new Dictionary<string, object>();
private static readonly Dictionary<string, KeyValuePair<string, string>> Accounts = new Dictionary<string, KeyValuePair<string, string>>(); private static readonly Dictionary<string, KeyValuePair<string, string>> Accounts = new Dictionary<string, KeyValuePair<string, string>>();
private static readonly Dictionary<string, KeyValuePair<string, ushort>> Servers = new Dictionary<string, KeyValuePair<string, ushort>>(); private static readonly Dictionary<string, KeyValuePair<string, ushort>> Servers = new Dictionary<string, KeyValuePair<string, ushort>>();
private enum ParseMode { Default, Main, AppVars, Proxy, MCSettings, AntiAFK, Hangman, Alerts, ChatLog, AutoRelog, ScriptScheduler, RemoteControl, ChatFormat, AutoRespond, AutoAttack, AutoFishing, AutoEat }; private enum ParseMode { Default, Main, AppVars, Proxy, MCSettings, AntiAFK, Hangman, Alerts, ChatLog, AutoRelog, ScriptScheduler, RemoteControl, ChatFormat, AutoRespond, AutoAttack, AutoFishing, AutoEat, AutoLook };
/// <summary> /// <summary>
/// Load settings from the give INI file /// Load settings from the give INI file
@ -211,6 +214,7 @@ namespace MinecraftClient
case "autoattack": pMode = ParseMode.AutoAttack; break; case "autoattack": pMode = ParseMode.AutoAttack; break;
case "autofishing": pMode = ParseMode.AutoFishing; break; case "autofishing": pMode = ParseMode.AutoFishing; break;
case "autoeat": pMode = ParseMode.AutoEat; break; case "autoeat": pMode = ParseMode.AutoEat; break;
case "autolook": pMode = ParseMode.AutoLook; break;
default: pMode = ParseMode.Default; break; default: pMode = ParseMode.Default; break;
} }
} }
@ -466,6 +470,12 @@ namespace MinecraftClient
case "matchesfile": AutoRespond_Matches = argValue; break; case "matchesfile": AutoRespond_Matches = argValue; break;
} }
break; break;
case ParseMode.AutoLook:
switch (argName.ToLower())
{
case "enabled": AutoLook_Enabled = str2bool(argValue); break;
}
break;
case ParseMode.AutoAttack: case ParseMode.AutoAttack:
switch (argName.ToLower()) switch (argName.ToLower())
@ -689,12 +699,17 @@ namespace MinecraftClient
+ "\r\n" + "\r\n"
+ "[AutoFishing]\r\n" + "[AutoFishing]\r\n"
+ "# Entity Handling NEED to be enabled first\r\n" + "# Entity Handling NEED to be enabled first\r\n"
+ "enabled=false" + "enabled=false\r\n"
+ "\r\n" + "\r\n"
+ "[AutoEat]\r\n" + "[AutoEat]\r\n"
+ "# Inventory Handling NEED to be enabled first\r\n" + "# Inventory Handling NEED to be enabled first\r\n"
+ "enabled=false\r\n" + "enabled=false\r\n"
+ "threshold=6", Encoding.UTF8); + "threshold=6\r\n"
+ "\r\n"
+ "[AutoLook]\r\n"
+ "# Entity Handling AND Terrain Handling NEEDS to be enabled first\r\n"
+ "enabled=false"
+ "\r\n", Encoding.UTF8);
} }
/// <summary> /// <summary>