new command /animation (#1026)

This commit is contained in:
Рома Данилов 2020-05-26 14:02:09 +05:00 committed by GitHub
parent 23870711a0
commit 87b2d3bf4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 409 additions and 311 deletions

View file

@ -899,6 +899,16 @@ namespace MinecraftClient
return Handler.DoCreativeGive(slot, itemType, count); return Handler.DoCreativeGive(slot, itemType, count);
} }
/// <summary>
/// Plays animation
/// </summary>
/// <param name="animation"> <0|1></param>
/// <returns>TRUE animation done</returns>
protected bool SendAnimation(int animation)
{
return Handler.DoAnimation(animation);
}
/// <summary> /// <summary>
/// Use item currently in the player's hand (active inventory bar slot) /// Use item currently in the player's hand (active inventory bar slot)
/// </summary> /// </summary>

View file

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MinecraftClient.Commands
{
public class Animation : Command
{
public override string CMDName { get { return "animation"; } }
public override string CMDDesc { get { return "animation <<mainhand|offhand>|<0|1>>"; } }
public override string Run(McTcpClient handler, string command, Dictionary<string, object> localVars)
{
if (hasArg(command))
{
string[] args = getArgs(command);
if (args.Length > 0)
{
if (args[0] == "mainhand" || args[0] == "0")
{
handler.DoAnimation(0);
return "Done";
}
else if (args[0] == "offhand" || args[0] == "1")
{
handler.DoAnimation(1);
return "Done";
}
else
{
return CMDDesc;
}
}
else
{
return CMDDesc;
}
}
else return CMDDesc;
}
}
}

View file

@ -1483,6 +1483,16 @@ namespace MinecraftClient
return handler.SendCreativeInventoryAction(slot, itemType, count); return handler.SendCreativeInventoryAction(slot, itemType, count);
} }
/// <summary>
/// Plays animation
/// </summary>
/// <param name="animation"> <0|1></param>
/// <returns>TRUE if item given successfully</returns>
public bool DoAnimation(int animation)
{
return handler.SendAnimation(animation);
}
/// <summary> /// <summary>
/// Close the specified inventory window /// Close the specified inventory window
/// </summary> /// </summary>

View file

@ -89,6 +89,7 @@
<Compile Include="ChatBots\TestBot.cs" /> <Compile Include="ChatBots\TestBot.cs" />
<Compile Include="ChatBot.cs" /> <Compile Include="ChatBot.cs" />
<Compile Include="Command.cs" /> <Compile Include="Command.cs" />
<Compile Include="Commands\Animation.cs" />
<Compile Include="Commands\ChangeSlot.cs" /> <Compile Include="Commands\ChangeSlot.cs" />
<Compile Include="Commands\Connect.cs" /> <Compile Include="Commands\Connect.cs" />
<Compile Include="Commands\Debug.cs" /> <Compile Include="Commands\Debug.cs" />

View file

@ -27,6 +27,7 @@ namespace MinecraftClient.Protocol.Handlers
ClickWindow, ClickWindow,
CloseWindow, CloseWindow,
PlayerBlockPlacement, PlayerBlockPlacement,
CreativeInventoryAction CreativeInventoryAction,
Animation
} }
} }

View file

@ -692,7 +692,10 @@ namespace MinecraftClient.Protocol.Handlers
{ {
return false; //Currently not implemented return false; //Currently not implemented
} }
public bool SendAnimation(int animation)
{
return false; //Currently not implemented
}
public bool SendCreativeInventoryAction(int slot, ItemType item, int count) public bool SendCreativeInventoryAction(int slot, ItemType item, int count)
{ {
return false; //Currently not implemented return false; //Currently not implemented

View file

@ -1391,6 +1391,28 @@ namespace MinecraftClient.Protocol.Handlers
catch (ObjectDisposedException) { return false; } catch (ObjectDisposedException) { return false; }
} }
public bool SendAnimation(int animation)
{
try
{
if (animation == 0 || animation == 1)
{
List<byte> packet = new List<byte>();
packet.AddRange(dataTypes.GetVarInt(animation));
SendPacket(PacketOutgoingType.Animation, packet);
return true;
}
else;
{
return false;
}
}
catch (SocketException) { return false; }
catch (System.IO.IOException) { return false; }
catch (ObjectDisposedException) { return false; }
}
public bool SendCloseWindow(int windowId) public bool SendCloseWindow(int windowId)
{ {
try try

View file

@ -418,6 +418,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.ClickWindow: return 0x09; case PacketOutgoingType.ClickWindow: return 0x09;
case PacketOutgoingType.CloseWindow: return 0x0A; case PacketOutgoingType.CloseWindow: return 0x0A;
case PacketOutgoingType.EntityAction: return 0x1B; case PacketOutgoingType.EntityAction: return 0x1B;
case PacketOutgoingType.Animation: return 0x2A;
} }
} }

View file

@ -159,6 +159,13 @@ namespace MinecraftClient.Protocol
/// <returns>TRUE if item given successfully</returns> /// <returns>TRUE if item given successfully</returns>
bool SendCreativeInventoryAction(int slot, ItemType itemType, int count); bool SendCreativeInventoryAction(int slot, ItemType itemType, int count);
/// <summary>
/// Plays animation
/// </summary>
/// <param name="animation"> <0|1></param>
/// <returns>TRUE if item given successfully</returns>
bool SendAnimation(int animation);
/// <summary> /// <summary>
/// Send a close window packet to the server /// Send a close window packet to the server
/// </summary> /// </summary>