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
This commit is contained in:
Рома Данилов 2020-06-20 17:57:07 +05:00 committed by GitHub
parent eddf7ad063
commit b52435f0ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 419 additions and 36 deletions

View file

@ -43,12 +43,16 @@ namespace MinecraftClient.Protocol.Handlers
EntityPositionAndRotation,
EntityProperties,
EntityTeleport,
EntityEquipment,
EntityVelocity,
TimeUpdate,
UpdateHealth,
SetExperience,
HeldItemChange,
Explosion,
MapData,
Title,
/// <summary>
/// Represents a packet not implemented in MCC.
/// </summary>

View file

@ -34,5 +34,6 @@ namespace MinecraftClient.Protocol.Handlers
CreativeInventoryAction,
Animation,
PlayerDigging,
UpdateSign,
}
}

View file

@ -652,7 +652,12 @@ namespace MinecraftClient.Protocol.Handlers
}
catch (SocketException) { return false; }
}
public bool SendUpdateSign(Location location, string line1, string line2, string line3, string line4)
{
return false; //Currently not implemented
}
public bool SendBrandInfo(string brandInfo)
{
return false; //Only supported since MC 1.7
@ -698,7 +703,7 @@ namespace MinecraftClient.Protocol.Handlers
return false; //Currently not implemented
}
public bool SendCreativeInventoryAction(int slot, ItemType item, int count)
public bool SendCreativeInventoryAction(int slot, ItemType item, int count, Dictionary<string, object> NBT)
{
return false; //Currently not implemented
}

View file

@ -316,6 +316,75 @@ namespace MinecraftClient.Protocol.Handlers
}
}
break;
case PacketIncomingType.MapData:
int mapid = dataTypes.ReadNextVarInt(packetData);
byte scale = dataTypes.ReadNextByte(packetData);
bool trackingposition = dataTypes.ReadNextBool(packetData);
bool locked = false;
if (protocolversion >= MC114Version)
{
locked = dataTypes.ReadNextBool(packetData);
}
int iconcount = dataTypes.ReadNextVarInt(packetData);
handler.OnMapData(mapid, scale, trackingposition, locked, iconcount);
break;
case PacketIncomingType.Title:
if (protocolversion >= MC18Version)
{
int action2 = dataTypes.ReadNextVarInt(packetData);
string titletext = String.Empty;
string subtitletext = String.Empty;
string actionbartext = String.Empty;
string json = String.Empty;
int fadein = -1;
int stay = -1;
int fadeout = -1;
if (protocolversion >= MC110Version)
{
if (action2 == 0)
{
json = titletext;
titletext = ChatParser.ParseText(dataTypes.ReadNextString(packetData));
}
else if (action2 == 1)
{
json = subtitletext;
subtitletext = ChatParser.ParseText(dataTypes.ReadNextString(packetData));
}
else if (action2 == 2)
{
json = actionbartext;
actionbartext = ChatParser.ParseText(dataTypes.ReadNextString(packetData));
}
else if (action2 == 3)
{
fadein = dataTypes.ReadNextInt(packetData);
stay = dataTypes.ReadNextInt(packetData);
fadeout = dataTypes.ReadNextInt(packetData);
}
}
else
{
if (action2 == 0)
{
json = titletext;
titletext = ChatParser.ParseText(dataTypes.ReadNextString(packetData));
}
else if (action2 == 1)
{
json = subtitletext;
subtitletext = ChatParser.ParseText(dataTypes.ReadNextString(packetData));
}
else if (action2 == 2)
{
fadein = dataTypes.ReadNextInt(packetData);
stay = dataTypes.ReadNextInt(packetData);
fadeout = dataTypes.ReadNextInt(packetData);
}
}
handler.OnTitle(action2, titletext, subtitletext, actionbartext, fadein, stay, fadeout, json);
}
break;
case PacketIncomingType.MultiBlockChange:
if (handler.GetTerrainEnabled())
{
@ -589,6 +658,15 @@ namespace MinecraftClient.Protocol.Handlers
handler.OnSpawnEntity(entity);
}
break;
case PacketIncomingType.EntityEquipment:
if (handler.GetEntityHandlingEnabled())
{
int entityid = dataTypes.ReadNextVarInt(packetData);
int slot2 = dataTypes.ReadNextVarInt(packetData);
Item item = dataTypes.ReadNextItemSlot(packetData);
handler.OnEntityEquipment(entityid, slot2, item);
}
break;
case PacketIncomingType.SpawnLivingEntity:
if (handler.GetEntityHandlingEnabled())
{
@ -1424,13 +1502,13 @@ namespace MinecraftClient.Protocol.Handlers
catch (ObjectDisposedException) { return false; }
}
public bool SendCreativeInventoryAction(int slot, ItemType itemType, int count)
public bool SendCreativeInventoryAction(int slot, ItemType itemType, int count, Dictionary<string, object> NBT)
{
try
{
List<byte> packet = new List<byte>();
packet.AddRange(dataTypes.GetShort((short)slot));
packet.AddRange(dataTypes.GetItemSlot(new Item((int)itemType, count, null)));
packet.AddRange(dataTypes.GetItemSlot(new Item((int)itemType, count, NBT)));
SendPacket(PacketOutgoingType.CreativeInventoryAction, packet);
return true;
}
@ -1489,5 +1567,22 @@ namespace MinecraftClient.Protocol.Handlers
catch (System.IO.IOException) { return false; }
catch (ObjectDisposedException) { return false; }
}
public bool SendUpdateSign(Location sign, string line1, string line2, string line3, string line4)
{
try
{
List<byte> packet = new List<byte>();
packet.AddRange(dataTypes.GetLocation(sign));
packet.AddRange(dataTypes.GetString(line1));
packet.AddRange(dataTypes.GetString(line2));
packet.AddRange(dataTypes.GetString(line3));
packet.AddRange(dataTypes.GetString(line4));
SendPacket(PacketOutgoingType.UpdateSign, packet);
return true;
}
catch (SocketException) { return false; }
catch (System.IO.IOException) { return false; }
catch (ObjectDisposedException) { return false; }
}
}
}

View file

@ -57,11 +57,15 @@ namespace MinecraftClient.Protocol.Handlers
case 0x17: return PacketIncomingType.EntityPositionAndRotation;
case 0x20: return PacketIncomingType.EntityProperties;
case 0x18: return PacketIncomingType.EntityTeleport;
case 0x12: return PacketIncomingType.EntityVelocity;
case 0x04: return PacketIncomingType.EntityEquipment;
case 0x03: return PacketIncomingType.TimeUpdate;
case 0x06: return PacketIncomingType.UpdateHealth;
case 0x1F: return PacketIncomingType.SetExperience;
case 0x09: return PacketIncomingType.HeldItemChange;
case 0x27: return PacketIncomingType.Explosion;
case 0x34: return PacketIncomingType.MapData;
case 0x45: return PacketIncomingType.Title;
}
}
else if (protocol <= Protocol18Handler.MC1112Version) // MC 1.9, 1.10 and 1.11
@ -97,11 +101,15 @@ namespace MinecraftClient.Protocol.Handlers
case 0x26: return PacketIncomingType.EntityPositionAndRotation;
case 0x4A: return PacketIncomingType.EntityProperties;
case 0x49: return PacketIncomingType.EntityTeleport;
case 0x3B: return PacketIncomingType.EntityVelocity;
case 0x3C: return PacketIncomingType.EntityEquipment;
case 0x44: return PacketIncomingType.TimeUpdate;
case 0x3E: return PacketIncomingType.UpdateHealth;
case 0x3D: return PacketIncomingType.SetExperience;
case 0x37: return PacketIncomingType.HeldItemChange;
case 0x1C: return PacketIncomingType.Explosion;
case 0x24: return PacketIncomingType.MapData;
case 0x45: return PacketIncomingType.Title;
}
}
else if (protocol <= Protocol18Handler.MC112Version) // MC 1.12.0
@ -137,11 +145,15 @@ namespace MinecraftClient.Protocol.Handlers
case 0x27: return PacketIncomingType.EntityPositionAndRotation;
case 0x4D: return PacketIncomingType.EntityProperties;
case 0x4B: return PacketIncomingType.EntityTeleport;
case 0x3D: return PacketIncomingType.EntityVelocity;
case 0x3E: return PacketIncomingType.EntityEquipment;
case 0x46: return PacketIncomingType.TimeUpdate;
case 0x40: return PacketIncomingType.UpdateHealth;
case 0x3F: return PacketIncomingType.SetExperience;
case 0x39: return PacketIncomingType.HeldItemChange;
case 0x1C: return PacketIncomingType.Explosion;
case 0x24: return PacketIncomingType.MapData;
case 0x47: return PacketIncomingType.Title;
}
}
else if (protocol <= Protocol18Handler.MC1122Version) // MC 1.12.2
@ -177,11 +189,15 @@ namespace MinecraftClient.Protocol.Handlers
case 0x27: return PacketIncomingType.EntityPositionAndRotation;
case 0x4E: return PacketIncomingType.EntityProperties;
case 0x4C: return PacketIncomingType.EntityTeleport;
case 0x3E: return PacketIncomingType.EntityVelocity;
case 0x3F: return PacketIncomingType.EntityEquipment;
case 0x47: return PacketIncomingType.TimeUpdate;
case 0x41: return PacketIncomingType.UpdateHealth;
case 0x40: return PacketIncomingType.SetExperience;
case 0x3A: return PacketIncomingType.HeldItemChange;
case 0x1C: return PacketIncomingType.Explosion;
case 0x25: return PacketIncomingType.MapData;
case 0x48: return PacketIncomingType.Title;
}
}
else if (protocol < Protocol18Handler.MC114Version) // MC 1.13 to 1.13.2
@ -217,11 +233,15 @@ namespace MinecraftClient.Protocol.Handlers
case 0x29: return PacketIncomingType.EntityPositionAndRotation;
case 0x52: return PacketIncomingType.EntityProperties;
case 0x50: return PacketIncomingType.EntityTeleport;
case 0x41: return PacketIncomingType.EntityVelocity;
case 0x42: return PacketIncomingType.EntityEquipment;
case 0x4A: return PacketIncomingType.TimeUpdate;
case 0x44: return PacketIncomingType.UpdateHealth;
case 0x43: return PacketIncomingType.SetExperience;
case 0x3D: return PacketIncomingType.HeldItemChange;
case 0x1E: return PacketIncomingType.Explosion;
case 0x26: return PacketIncomingType.MapData;
case 0x4B: return PacketIncomingType.Title;
}
}
else if (protocol < Protocol18Handler.MC115Version) // MC 1.14 to 1.14.4
@ -257,11 +277,15 @@ namespace MinecraftClient.Protocol.Handlers
case 0x29: return PacketIncomingType.EntityPositionAndRotation;
case 0x58: return PacketIncomingType.EntityProperties;
case 0x56: return PacketIncomingType.EntityTeleport;
case 0x41: return PacketIncomingType.EntityVelocity;
case 0x42: return PacketIncomingType.EntityEquipment;
case 0x4E: return PacketIncomingType.TimeUpdate;
case 0x48: return PacketIncomingType.UpdateHealth;
case 0x47: return PacketIncomingType.SetExperience;
case 0x45: return PacketIncomingType.SetExperience;
case 0x3F: return PacketIncomingType.HeldItemChange;
case 0x1C: return PacketIncomingType.Explosion;
case 0x26: return PacketIncomingType.MapData;
case 0x4F: return PacketIncomingType.Title;
}
}
else // MC 1.15
@ -297,11 +321,15 @@ namespace MinecraftClient.Protocol.Handlers
case 0x2A: return PacketIncomingType.EntityPositionAndRotation;
case 0x59: return PacketIncomingType.EntityProperties;
case 0x57: return PacketIncomingType.EntityTeleport;
case 0x46: return PacketIncomingType.EntityVelocity;
case 0x47: return PacketIncomingType.EntityEquipment;
case 0x4F: return PacketIncomingType.TimeUpdate;
case 0x49: return PacketIncomingType.UpdateHealth;
case 0x48: return PacketIncomingType.SetExperience;
case 0x40: return PacketIncomingType.HeldItemChange;
case 0x1D: return PacketIncomingType.Explosion;
case 0x27: return PacketIncomingType.MapData;
case 0x50: return PacketIncomingType.Title;
}
}
@ -346,6 +374,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.CreativeInventoryAction: return 0x10;
case PacketOutgoingType.Animation: return 0x0A;
case PacketOutgoingType.PlayerDigging: return 0x07;
case PacketOutgoingType.UpdateSign: return 0x12;
}
}
else if (protocol <= Protocol18Handler.MC1112Version) // MC 1.9, 1,10 and 1.11
@ -372,6 +401,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.CreativeInventoryAction: return 0x18;
case PacketOutgoingType.Animation: return 0x1A;
case PacketOutgoingType.PlayerDigging: return 0x13;
case PacketOutgoingType.UpdateSign: return 0x19;
}
}
else if (protocol <= Protocol18Handler.MC112Version) // MC 1.12
@ -398,6 +428,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.CreativeInventoryAction: return 0x1B;
case PacketOutgoingType.Animation: return 0x1D;
case PacketOutgoingType.PlayerDigging: return 0x14;
case PacketOutgoingType.UpdateSign: return 0x1C;
}
}
else if (protocol <= Protocol18Handler.MC1122Version) // 1.12.2
@ -423,7 +454,8 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.PlayerBlockPlacement: return 0x1F;
case PacketOutgoingType.CreativeInventoryAction: return 0x1B;
case PacketOutgoingType.Animation: return 0x1D;
case PacketOutgoingType.PlayerDigging: return 0x14;
case PacketOutgoingType.PlayerDigging: return 0x14;
case PacketOutgoingType.UpdateSign: return 0x1C;
}
}
else if (protocol < Protocol18Handler.MC114Version) // MC 1.13 to 1.13.2
@ -450,6 +482,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.CreativeInventoryAction: return 0x24;
case PacketOutgoingType.Animation: return 0x27;
case PacketOutgoingType.PlayerDigging: return 0x18;
case PacketOutgoingType.UpdateSign: return 0x26;
}
}
else // MC 1.14 to 1.15
@ -476,6 +509,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.CreativeInventoryAction: return 0x26;
case PacketOutgoingType.Animation: return 0x2A;
case PacketOutgoingType.PlayerDigging: return 0x1A;
case PacketOutgoingType.UpdateSign: return 0x29;
}
}

View file

@ -157,7 +157,7 @@ namespace MinecraftClient.Protocol
/// <param name="itemType">Item type</param>
/// <param name="count">Item count</param>
/// <returns>TRUE if item given successfully</returns>
bool SendCreativeInventoryAction(int slot, ItemType itemType, int count);
bool SendCreativeInventoryAction(int slot, ItemType itemType, int count, Dictionary<string, object> NBT);
/// <summary>
/// Plays animation
@ -194,5 +194,6 @@ namespace MinecraftClient.Protocol
/// <param name="face">Block face: 0 = bottom, 1 = top, etc (see wiki)</param>
/// <returns>True if packet was succcessfully sent</returns>
bool SendPlayerDigging(int status, Location location, byte face);
bool SendUpdateSign(Location location, string line1, string line2, string line3, string line4);
}
}

View file

@ -46,7 +46,12 @@ namespace MinecraftClient.Protocol
/// <param name="text">Text received from the server</param>
/// <param name="isJson">TRUE if the text is JSON-Encoded</param>
void OnTextReceived(string text, bool isJson);
/// <summary>
/// This method is called when the protocol handler receives a title
/// </summary>
void OnTitle(int action, string titletext, string subtitletext, string actionbartext, int fadein, int stay, int fadeout, string json);
/// <summary>
/// Called when receiving a connection keep-alive from the server
/// </summary>
@ -135,7 +140,15 @@ namespace MinecraftClient.Protocol
/// </summary>
/// <param name="entity">Spawned entity</param>
void OnSpawnEntity(Entity entity);
/// <summary>
/// Called when an entity has spawned
/// </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>
void OnEntityEquipment(int entityid, int slot, Item item);
/// <summary>
/// Called when a player spawns or enters the client's render distance
/// </summary>
@ -244,7 +257,17 @@ namespace MinecraftClient.Protocol
/// <remarks>Used for setting player slot after joining game</remarks>
/// <param name="slot"></param>
void OnHeldItemChange(byte slot);
/// <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>
void OnMapData(int mapid, byte scale, bool trackingposition, bool locked, int iconcount);
/// <summary>
/// Called when the Player entity ID has been received from the server
/// </summary>