mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Added Entity Action handling, and A TSneak command that will Toggle Sneak.
This commit is contained in:
parent
9dae40153c
commit
384c804e54
10 changed files with 176 additions and 5 deletions
66
MinecraftClient/ChatBots/AutoLook.cs
Normal file
66
MinecraftClient/ChatBots/AutoLook.cs
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
31
MinecraftClient/Commands/Sneak.cs
Normal file
31
MinecraftClient/Commands/Sneak.cs
Normal 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";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -170,6 +170,8 @@ namespace MinecraftClient
|
|||
if (Settings.AutoAttack_Enabled) { BotLoad(new ChatBots.AutoAttack()); }
|
||||
if (Settings.AutoFishing_Enabled) { BotLoad(new ChatBots.AutoFishing()); }
|
||||
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
|
||||
//BotLoad(new ChatBots.YourBot());
|
||||
}
|
||||
|
|
@ -1356,6 +1358,7 @@ namespace MinecraftClient
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when an entity moved over 8 block.
|
||||
/// </summary>
|
||||
|
|
@ -1469,6 +1472,14 @@ namespace MinecraftClient
|
|||
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>
|
||||
/// Use the item currently in the player's hand
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@
|
|||
<Compile Include="ChatBots\AutoAttack.cs" />
|
||||
<Compile Include="ChatBots\AutoEat.cs" />
|
||||
<Compile Include="ChatBots\AutoFishing.cs" />
|
||||
<Compile Include="ChatBots\AutoLook.cs" />
|
||||
<Compile Include="ChatBots\AutoRespond.cs" />
|
||||
<Compile Include="ChatBots\AutoRelog.cs" />
|
||||
<Compile Include="ChatBots\ChatLog.cs" />
|
||||
|
|
@ -103,6 +104,7 @@
|
|||
<Compile Include="Commands\Send.cs" />
|
||||
<Compile Include="Commands\Set.cs" />
|
||||
<Compile Include="Commands\Health.cs" />
|
||||
<Compile Include="Commands\Sneak.cs" />
|
||||
<Compile Include="Commands\UseItem.cs" />
|
||||
<Compile Include="Inventory\Container.cs" />
|
||||
<Compile Include="Inventory\ContainerType.cs" />
|
||||
|
|
@ -119,6 +121,7 @@
|
|||
<Compile Include="Mapping\Entity.cs" />
|
||||
<Compile Include="Mapping\EntityType.cs" />
|
||||
<Compile Include="Mapping\MaterialExtensions.cs" />
|
||||
<Compile Include="Protocol\Action.cs" />
|
||||
<Compile Include="Protocol\Handlers\DataTypes.cs" />
|
||||
<Compile Include="Protocol\Handlers\PacketIncomingType.cs" />
|
||||
<Compile Include="Protocol\Handlers\PacketOutgoingType.cs" />
|
||||
|
|
|
|||
16
MinecraftClient/Protocol/Action.cs
Normal file
16
MinecraftClient/Protocol/Action.cs
Normal 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
|
||||
}
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
ClientSettings,
|
||||
PluginMessage,
|
||||
TabComplete,
|
||||
EntityAction,
|
||||
PlayerPosition,
|
||||
PlayerPositionAndLook,
|
||||
TeleportConfirm,
|
||||
|
|
|
|||
|
|
@ -239,6 +239,10 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
}
|
||||
else return "";
|
||||
}
|
||||
public bool SendEntityAction(int PlayerEntityID, int ActionID)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private byte[] readNextByteArray()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -966,6 +966,22 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
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>
|
||||
/// Send a respawn packet to the server
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -86,6 +86,14 @@ namespace MinecraftClient.Protocol
|
|||
/// <returns>True if message was successfully sent</returns>
|
||||
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>
|
||||
/// Send a held item change packet to the server.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -162,12 +162,15 @@ namespace MinecraftClient
|
|||
public static bool AutoEat_Enabled = false;
|
||||
public static int AutoEat_hungerThreshold = 6;
|
||||
|
||||
//Auto Looking
|
||||
public static bool AutoLook_Enabled = false;
|
||||
|
||||
//Custom app variables and Minecraft accounts
|
||||
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, 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>
|
||||
/// Load settings from the give INI file
|
||||
|
|
@ -211,6 +214,7 @@ namespace MinecraftClient
|
|||
case "autoattack": pMode = ParseMode.AutoAttack; break;
|
||||
case "autofishing": pMode = ParseMode.AutoFishing; break;
|
||||
case "autoeat": pMode = ParseMode.AutoEat; break;
|
||||
case "autolook": pMode = ParseMode.AutoLook; break;
|
||||
default: pMode = ParseMode.Default; break;
|
||||
}
|
||||
}
|
||||
|
|
@ -466,6 +470,12 @@ namespace MinecraftClient
|
|||
case "matchesfile": AutoRespond_Matches = argValue; break;
|
||||
}
|
||||
break;
|
||||
case ParseMode.AutoLook:
|
||||
switch (argName.ToLower())
|
||||
{
|
||||
case "enabled": AutoLook_Enabled = str2bool(argValue); break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ParseMode.AutoAttack:
|
||||
switch (argName.ToLower())
|
||||
|
|
@ -689,12 +699,17 @@ namespace MinecraftClient
|
|||
+ "\r\n"
|
||||
+ "[AutoFishing]\r\n"
|
||||
+ "# Entity Handling NEED to be enabled first\r\n"
|
||||
+ "enabled=false"
|
||||
+ "enabled=false\r\n"
|
||||
+ "\r\n"
|
||||
+ "[AutoEat]\r\n"
|
||||
+ "# Inventory Handling NEED to be enabled first\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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue