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>
This commit is contained in:
Рома Данилов 2020-05-29 23:18:34 +05:00 committed by GitHub
parent b2e6953075
commit cf9bc4c3d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 249 additions and 23 deletions

View file

@ -84,6 +84,7 @@ namespace MinecraftClient
"using System.Threading;", "using System.Threading;",
"using MinecraftClient;", "using MinecraftClient;",
"using MinecraftClient.Mapping;", "using MinecraftClient.Mapping;",
"using MinecraftClient.Inventory;",
String.Join("\n", libs), String.Join("\n", libs),
"namespace ScriptLoader {", "namespace ScriptLoader {",
"public class Script {", "public class Script {",

View file

@ -6,6 +6,7 @@ using System.IO;
using System.Threading; using System.Threading;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using MinecraftClient.Inventory; using MinecraftClient.Inventory;
using MinecraftClient.Mapping;
namespace MinecraftClient namespace MinecraftClient
{ {
@ -156,7 +157,13 @@ namespace MinecraftClient
/// <param name="entity">Entity with updated location</param> /// <param name="entity">Entity with updated location</param>
public virtual void OnEntityMove(Mapping.Entity entity) { } public virtual void OnEntityMove(Mapping.Entity entity) { }
public virtual void OnInternalCommand(string commandName,string commandParams, string Result) { } /// <summary>
/// Called after an internal MCC command has been performed
/// </summary>
/// <param name="commandName">MCC Command Name</param>
/// <param name="commandParams">MCC Command Parameters</param>
/// <param name="Result">MCC command result</param>
public virtual void OnInternalCommand(string commandName, string commandParams, string Result) { }
/// <summary> /// <summary>
/// Called when an entity spawned nearby /// Called when an entity spawned nearby
@ -183,6 +190,29 @@ namespace MinecraftClient
/// <param name="food">New food level</param> /// <param name="food">New food level</param>
public virtual void OnHealthUpdate(float health, int food) { } public virtual void OnHealthUpdate(float health, int food) { }
/// <summary>
/// Called when an explosion occurs on the server
/// </summary>
/// <param name="explode">Explosion location</param>
/// <param name="recordcount">Amount of blocks blown up</param>
public virtual void OnExplosion(Location explode, float strength, int recordcount) { }
/// <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 virtual void OnSetExperience(float Experiencebar, int Level, int TotalExperience) { }
/// <summary>
/// Called when the Game Mode has been updated for a player
/// </summary>
/// <param name="playername">Player Name</param>
/// <param name="uuid">Player UUID</param>
/// <param name="gamemode">New Game Mode (0: Survival, 1: Creative, 2: Adventure, 3: Spectator).</param>
public virtual void OnGamemodeUpdate(string playername, Guid uuid, int gamemode) { }
/* =================================================================== */ /* =================================================================== */
/* ToolBox - Methods below might be useful while creating your bot. */ /* ToolBox - Methods below might be useful while creating your bot. */
/* You should not need to interact with other classes of the program. */ /* You should not need to interact with other classes of the program. */
@ -667,6 +697,7 @@ namespace MinecraftClient
{ {
return SendEntityAction(on ? Protocol.EntityActionType.StartSneaking : Protocol.EntityActionType.StopSneaking); return SendEntityAction(on ? Protocol.EntityActionType.StartSneaking : Protocol.EntityActionType.StopSneaking);
} }
/// <summary> /// <summary>
/// Send Entity Action /// Send Entity Action
/// </summary> /// </summary>
@ -674,6 +705,18 @@ namespace MinecraftClient
{ {
return Handler.sendEntityAction(entityAction); return Handler.sendEntityAction(entityAction);
} }
/// <summary>
/// Dig block - WORK IN PROGRESS - MAY NOT WORK
/// </summary>
/// <param name="status"></param>
/// <param name="location"></param>
/// <param name="face"></param>
protected void DigBlock(int status, Location location, byte face)
{
Handler.DigBlock(status, location, face);
}
/// <summary> /// <summary>
/// SetSlot /// SetSlot
/// </summary> /// </summary>
@ -871,7 +914,7 @@ namespace MinecraftClient
/// </summary> /// </summary>
/// <param name="EntityID"></param> /// <param name="EntityID"></param>
/// <param name="type">0: interact, 1: attack, 2: interact at</param> /// <param name="type">0: interact, 1: attack, 2: interact at</param>
/// <returns></returns> /// <returns>TRUE in case of success</returns>
protected bool InteractEntity(int EntityID, int type) protected bool InteractEntity(int EntityID, int type)
{ {
return Handler.InteractEntity(EntityID, type); return Handler.InteractEntity(EntityID, type);
@ -881,6 +924,7 @@ namespace MinecraftClient
/// Give Creative Mode items into regular/survival Player Inventory /// Give Creative Mode items into regular/survival Player Inventory
/// </summary> /// </summary>
/// <remarks>(obviously) requires to be in creative mode</remarks> /// <remarks>(obviously) requires to be in creative mode</remarks>
/// </summary>
/// <param name="slot">Destination inventory slot</param> /// <param name="slot">Destination inventory slot</param>
/// <param name="itemType">Item type</param> /// <param name="itemType">Item type</param>
/// <param name="count">Item count</param> /// <param name="count">Item count</param>
@ -894,7 +938,7 @@ namespace MinecraftClient
/// Plays animation (Player arm swing) /// Plays animation (Player arm swing)
/// </summary> /// </summary>
/// <param name="animation">0 for left arm, 1 for right arm</param> /// <param name="animation">0 for left arm, 1 for right arm</param>
/// <returns>TRUE if animation successfully done</returns> /// <returns>TRUE in case of success</returns>
protected bool SendAnimation(int animation) protected bool SendAnimation(int animation)
{ {
return Handler.DoAnimation(animation); return Handler.DoAnimation(animation);
@ -903,7 +947,7 @@ namespace MinecraftClient
/// <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>
/// <returns></returns> /// <returns>TRUE if successful</returns>
protected bool UseItemInHand() protected bool UseItemInHand()
{ {
return Handler.UseItemOnHand(); return Handler.UseItemOnHand();
@ -912,12 +956,22 @@ namespace MinecraftClient
/// <summary> /// <summary>
/// Check inventory handling enable status /// Check inventory handling enable status
/// </summary> /// </summary>
/// <returns></returns> /// <returns>TRUE if inventory handling is enabled</returns>
public bool GetInventoryEnabled() public bool GetInventoryEnabled()
{ {
return Handler.GetInventoryEnabled(); return Handler.GetInventoryEnabled();
} }
/// <summary>
/// Place block
/// </summary>
/// <param name="location">Block location</param>
/// <returns></returns>
protected bool SendPlaceBlock(Location location)
{
return Handler.PlaceBlock(location);
}
/// <summary> /// <summary>
/// Get the player's inventory. Do not write to it, will not have any effect server-side. /// Get the player's inventory. Do not write to it, will not have any effect server-side.
/// </summary> /// </summary>
@ -937,6 +991,18 @@ namespace MinecraftClient
return Handler.GetInventories(); return Handler.GetInventories();
} }
/// <summary>
/// Perform inventory action
/// </summary>
/// <param name="inventoryId">Inventory ID</param>
/// <param name="slot">Slot ID</param>
/// <param name="actionType">Action Type</param>
/// <returns>TRUE in case of success</returns>
protected bool WindowAction(int inventoryId, int slot, WindowActionType actionType)
{
return Handler.DoWindowAction(inventoryId, slot, actionType);
}
/// <summary> /// <summary>
/// Change player selected hotbar slot /// Change player selected hotbar slot
/// </summary> /// </summary>

View file

@ -46,8 +46,8 @@ namespace MinecraftClient.ChatBots
bool shouldAttack = handleEntity(entity.Value); bool shouldAttack = handleEntity(entity.Value);
if (shouldAttack) if (shouldAttack)
{ {
// hit the entity! SendAnimation(0); // Hit Animation
InteractEntity(entity.Key, 1); InteractEntity(entity.Key, 1); // hit the entity!
} }
} }
} }

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -12,7 +12,7 @@ namespace MinecraftClient.Commands
public override string Run(McTcpClient handler, string command, Dictionary<string, object> localVars) public override string Run(McTcpClient handler, string command, Dictionary<string, object> localVars)
{ {
return "Health: " + handler.GetHealth() + ", Saturation: " + handler.GetSaturation(); return "Health: " + handler.GetHealth() + ", Saturation: " + handler.GetSaturation() + ", Level: " + handler.GetLevel() + ", TotalExperience: " + handler.GetTotalExperience();
} }
} }
} }

View file

@ -63,6 +63,8 @@ namespace MinecraftClient
// player health and hunger // player health and hunger
private float playerHealth; private float playerHealth;
private int playerFoodSaturation; private int playerFoodSaturation;
private int playerLevel;
private int playerTotalExperience;
private byte CurrentSlot = 0; private byte CurrentSlot = 0;
// Entity handling // Entity handling
@ -83,6 +85,8 @@ namespace MinecraftClient
public Double GetServerTPS() { return serverTPS; } public Double GetServerTPS() { return serverTPS; }
public float GetHealth() { return playerHealth; } public float GetHealth() { return playerHealth; }
public int GetSaturation() { return playerFoodSaturation; } public int GetSaturation() { return playerFoodSaturation; }
public int GetLevel() { return playerLevel; }
public int GetTotalExperience() { return playerTotalExperience; }
public byte GetCurrentSlot() { return CurrentSlot; } public byte GetCurrentSlot() { return CurrentSlot; }
// get bots list for unloading them by commands // get bots list for unloading them by commands
@ -1261,6 +1265,23 @@ namespace MinecraftClient
OnSpawnEntity(playerEntity); OnSpawnEntity(playerEntity);
} }
/// <summary>
/// Called when the Game Mode has been updated for a player
/// </summary>
/// <param name="playername">Player Name</param>
/// <param name="uuid">Player UUID</param>
/// <param name="gamemode">New Game Mode (0: Survival, 1: Creative, 2: Adventure, 3: Spectator).</param>
public void OnGamemodeUpdate(Guid uuid, int gamemode)
{
string playerName = null;
if (onlinePlayers.ContainsKey(uuid))
{
playerName = onlinePlayers[uuid];
foreach (ChatBot bot in bots.ToArray())
bot.OnGamemodeUpdate(playerName, uuid, gamemode);
}
}
/// <summary> /// <summary>
/// Called when entities dead/despawn. /// Called when entities dead/despawn.
/// </summary> /// </summary>
@ -1529,7 +1550,22 @@ namespace MinecraftClient
//WORK IN PROGRESS. MAY NOT WORK YET //WORK IN PROGRESS. MAY NOT WORK YET
if (Settings.DebugMessages) if (Settings.DebugMessages)
ConsoleIO.WriteLogLine(location.ToString()); ConsoleIO.WriteLogLine(location.ToString());
return handler.SendPlayerBlockPlacement(0, location, 1, 0.5f, 0.5f, 0.5f, false); Location placelocation = new Location(location.X, location.Y - 1, location.Z);
return handler.SendPlayerBlockPlacement(0, placelocation, 1, 0.5f, 0.5f, 0.5f, false);
}
/// <summary>
/// Dig block - WORK IN PROGRESS - MAY NOT WORK YET
/// </summary>
/// <param name="status"></param>
/// <param name="location"></param>
/// <param name="face"></param>
public bool DigBlock(int status, Location location, byte Face)
{
if (Settings.DebugMessages)
ConsoleIO.WriteLogLine(location.ToString());
Location placelocation = new Location(location.X, location.Y, location.Z);
return handler.SendPlayerDigging(status, placelocation, 1);
} }
/// <summary> /// <summary>
@ -1549,7 +1585,7 @@ namespace MinecraftClient
return false; return false;
} }
} }
/// <summary> /// <summary>
/// Called when client player's health changed, e.g. getting attack /// Called when client player's health changed, e.g. getting attack
/// </summary> /// </summary>
@ -1574,6 +1610,38 @@ namespace MinecraftClient
bot.OnHealthUpdate(health, food); bot.OnHealthUpdate(health, food);
} }
/// <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;
foreach (ChatBot bot in bots.ToArray())
bot.OnSetExperience(Experiencebar, Level, TotalExperience);
}
/// <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)
{
foreach (ChatBot bot in bots.ToArray())
bot.OnExplosion(explode, strength, ExplosionRecordCount);
}
/// <summary>
/// Called when Experience bar is updated
/// </summary>
/// <param name="Experiencebar">Experience bar level</param>
/// <param name="Level">Player Level</param>
/// <param name="TotalExperience">Total experience</param>
public void OnHeldItemChange(byte slot) public void OnHeldItemChange(byte slot)
{ {
foreach (ChatBot bot in bots.ToArray()) foreach (ChatBot bot in bots.ToArray())

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -45,7 +45,9 @@ namespace MinecraftClient.Protocol.Handlers
EntityTeleport, EntityTeleport,
TimeUpdate, TimeUpdate,
UpdateHealth, UpdateHealth,
SetExperience,
HeldItemChange, HeldItemChange,
Explosion,
/// <summary> /// <summary>
/// Represents a packet not implemented in MCC. /// Represents a packet not implemented in MCC.

View file

@ -33,5 +33,6 @@ namespace MinecraftClient.Protocol.Handlers
PlayerBlockPlacement, PlayerBlockPlacement,
CreativeInventoryAction, CreativeInventoryAction,
Animation, Animation,
PlayerDigging,
} }
} }

View file

@ -718,6 +718,11 @@ namespace MinecraftClient.Protocol.Handlers
return false; //Currently not implemented return false; //Currently not implemented
} }
public bool SendPlayerDigging(int status, Location location, byte face)
{
return false; //Currently not implemented
}
/// <summary> /// <summary>
/// Send a plugin channel packet to the server. /// Send a plugin channel packet to the server.
/// </summary> /// </summary>

View file

@ -444,6 +444,9 @@ namespace MinecraftClient.Protocol.Handlers
handler.OnPlayerJoin(uuid, name); handler.OnPlayerJoin(uuid, name);
break; break;
case 0x01: //Update gamemode case 0x01: //Update gamemode
int gamemode = dataTypes.ReadNextVarInt(packetData);
handler.OnGamemodeUpdate(uuid, gamemode);
break;
case 0x02: //Update latency case 0x02: //Update latency
dataTypes.ReadNextVarInt(packetData); dataTypes.ReadNextVarInt(packetData);
break; break;
@ -714,6 +717,18 @@ namespace MinecraftClient.Protocol.Handlers
dataTypes.ReadNextFloat(packetData); // Food Saturation dataTypes.ReadNextFloat(packetData); // Food Saturation
handler.OnUpdateHealth(health, food); handler.OnUpdateHealth(health, food);
break; break;
case PacketIncomingType.SetExperience:
float experiencebar = dataTypes.ReadNextFloat(packetData);
int level = dataTypes.ReadNextVarInt(packetData);
int totalexperience = dataTypes.ReadNextVarInt(packetData);
handler.OnSetExperience(experiencebar, level, totalexperience);
break;
case PacketIncomingType.Explosion:
Location explodelocation = new Location(dataTypes.ReadNextFloat(packetData), dataTypes.ReadNextFloat(packetData), dataTypes.ReadNextFloat(packetData));
float Explosionstrength = dataTypes.ReadNextFloat(packetData);
int ExplosionRecordCount = dataTypes.ReadNextInt(packetData);
handler.OnExplosion(explodelocation, Explosionstrength, ExplosionRecordCount);
break;
case PacketIncomingType.HeldItemChange: case PacketIncomingType.HeldItemChange:
byte slot = dataTypes.ReadNextByte(packetData); byte slot = dataTypes.ReadNextByte(packetData);
handler.OnHeldItemChange(slot); handler.OnHeldItemChange(slot);
@ -1066,7 +1081,7 @@ 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) public bool SendEntityAction(int PlayerEntityID, int ActionID)
{ {
try try
@ -1228,7 +1243,7 @@ namespace MinecraftClient.Protocol.Handlers
catch (System.IO.IOException) { return false; } catch (System.IO.IOException) { return false; }
catch (ObjectDisposedException) { return false; } catch (ObjectDisposedException) { return false; }
} }
/// <summary> /// <summary>
/// Send an Interact Entity Packet to server /// Send an Interact Entity Packet to server
/// </summary> /// </summary>
@ -1278,9 +1293,9 @@ namespace MinecraftClient.Protocol.Handlers
{ {
if (protocolversion < MC19Version) if (protocolversion < MC19Version)
return false; // Packet does not exist prior to MC 1.9 return false; // Packet does not exist prior to MC 1.9
// According to https://wiki.vg/index.php?title=Protocol&oldid=5486#Player_Block_Placement // According to https://wiki.vg/index.php?title=Protocol&oldid=5486#Player_Block_Placement
// MC 1.7 does this using Player Block Placement with special values // MC 1.7 does this using Player Block Placement with special values
// TODO once Player Block Placement is implemented for older versions // TODO once Player Block Placement is implemented for older versions
try try
{ {
List<byte> packet = new List<byte>(); List<byte> packet = new List<byte>();
@ -1292,7 +1307,24 @@ 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 SendPlayerDigging(int status, Location location, byte face)
{
try
{
List<byte> packet = new List<byte>();
packet.AddRange(dataTypes.GetVarInt(status));
packet.AddRange(dataTypes.GetLocation(location));
packet.AddRange(dataTypes.GetVarInt(face));
SendPacket(PacketOutgoingType.PlayerDigging, packet);
return true;
}
catch (SocketException) { return false; }
catch (System.IO.IOException) { return false; }
catch (ObjectDisposedException) { return false; }
}
public bool SendPlayerBlockPlacement(int hand, Location location, int face, float CursorX, float CursorY, float CursorZ, bool insideBlock) public bool SendPlayerBlockPlacement(int hand, Location location, int face, float CursorX, float CursorY, float CursorZ, bool insideBlock)
{ {
if (protocolversion < MC114Version) if (protocolversion < MC114Version)
@ -1350,8 +1382,8 @@ namespace MinecraftClient.Protocol.Handlers
case WindowActionType.LeftClick: button = 0; break; case WindowActionType.LeftClick: button = 0; break;
case WindowActionType.RightClick: button = 1; break; case WindowActionType.RightClick: button = 1; break;
case WindowActionType.MiddleClick: button = 2; mode = 3; break; case WindowActionType.MiddleClick: button = 2; mode = 3; break;
case WindowActionType.DropItem: case WindowActionType.DropItem:
button = 0; button = 0;
mode = 4; mode = 4;
item = new Item(-1, 0, null); item = new Item(-1, 0, null);
Container inventory = handler.GetInventory(windowId); Container inventory = handler.GetInventory(windowId);
@ -1427,7 +1459,7 @@ namespace MinecraftClient.Protocol.Handlers
SendPacket(PacketOutgoingType.Animation, packet); SendPacket(PacketOutgoingType.Animation, packet);
return true; return true;
} }
else; else
{ {
return false; return false;
} }
@ -1436,7 +1468,6 @@ 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 SendCloseWindow(int windowId) public bool SendCloseWindow(int windowId)
{ {
try try

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -59,7 +59,9 @@ namespace MinecraftClient.Protocol.Handlers
case 0x18: return PacketIncomingType.EntityTeleport; case 0x18: return PacketIncomingType.EntityTeleport;
case 0x03: return PacketIncomingType.TimeUpdate; case 0x03: return PacketIncomingType.TimeUpdate;
case 0x06: return PacketIncomingType.UpdateHealth; case 0x06: return PacketIncomingType.UpdateHealth;
case 0x1F: return PacketIncomingType.SetExperience;
case 0x09: return PacketIncomingType.HeldItemChange; case 0x09: return PacketIncomingType.HeldItemChange;
case 0x1C: return PacketIncomingType.Explosion;
} }
} }
else if (protocol <= Protocol18Handler.MC1112Version) // MC 1.9, 1.10 and 1.11 else if (protocol <= Protocol18Handler.MC1112Version) // MC 1.9, 1.10 and 1.11
@ -97,7 +99,9 @@ namespace MinecraftClient.Protocol.Handlers
case 0x49: return PacketIncomingType.EntityTeleport; case 0x49: return PacketIncomingType.EntityTeleport;
case 0x44: return PacketIncomingType.TimeUpdate; case 0x44: return PacketIncomingType.TimeUpdate;
case 0x3E: return PacketIncomingType.UpdateHealth; case 0x3E: return PacketIncomingType.UpdateHealth;
case 0x3D: return PacketIncomingType.SetExperience;
case 0x37: return PacketIncomingType.HeldItemChange; case 0x37: return PacketIncomingType.HeldItemChange;
case 0x27: return PacketIncomingType.Explosion;
} }
} }
else if (protocol <= Protocol18Handler.MC112Version) // MC 1.12.0 else if (protocol <= Protocol18Handler.MC112Version) // MC 1.12.0
@ -135,7 +139,9 @@ namespace MinecraftClient.Protocol.Handlers
case 0x4B: return PacketIncomingType.EntityTeleport; case 0x4B: return PacketIncomingType.EntityTeleport;
case 0x46: return PacketIncomingType.TimeUpdate; case 0x46: return PacketIncomingType.TimeUpdate;
case 0x40: return PacketIncomingType.UpdateHealth; case 0x40: return PacketIncomingType.UpdateHealth;
case 0x3F: return PacketIncomingType.SetExperience;
case 0x39: return PacketIncomingType.HeldItemChange; case 0x39: return PacketIncomingType.HeldItemChange;
case 0x1C: return PacketIncomingType.Explosion;
} }
} }
else if (protocol <= Protocol18Handler.MC1122Version) // MC 1.12.2 else if (protocol <= Protocol18Handler.MC1122Version) // MC 1.12.2
@ -173,7 +179,9 @@ namespace MinecraftClient.Protocol.Handlers
case 0x4C: return PacketIncomingType.EntityTeleport; case 0x4C: return PacketIncomingType.EntityTeleport;
case 0x47: return PacketIncomingType.TimeUpdate; case 0x47: return PacketIncomingType.TimeUpdate;
case 0x41: return PacketIncomingType.UpdateHealth; case 0x41: return PacketIncomingType.UpdateHealth;
case 0x40: return PacketIncomingType.SetExperience;
case 0x3A: return PacketIncomingType.HeldItemChange; case 0x3A: return PacketIncomingType.HeldItemChange;
case 0x1C: return PacketIncomingType.Explosion;
} }
} }
else if (protocol < Protocol18Handler.MC114Version) // MC 1.13 to 1.13.2 else if (protocol < Protocol18Handler.MC114Version) // MC 1.13 to 1.13.2
@ -211,7 +219,9 @@ namespace MinecraftClient.Protocol.Handlers
case 0x50: return PacketIncomingType.EntityTeleport; case 0x50: return PacketIncomingType.EntityTeleport;
case 0x4A: return PacketIncomingType.TimeUpdate; case 0x4A: return PacketIncomingType.TimeUpdate;
case 0x44: return PacketIncomingType.UpdateHealth; case 0x44: return PacketIncomingType.UpdateHealth;
case 0x43: return PacketIncomingType.SetExperience;
case 0x3D: return PacketIncomingType.HeldItemChange; case 0x3D: return PacketIncomingType.HeldItemChange;
case 0x1E: return PacketIncomingType.Explosion;
} }
} }
else if (protocol < Protocol18Handler.MC115Version) // MC 1.14 to 1.14.4 else if (protocol < Protocol18Handler.MC115Version) // MC 1.14 to 1.14.4
@ -249,7 +259,9 @@ namespace MinecraftClient.Protocol.Handlers
case 0x56: return PacketIncomingType.EntityTeleport; case 0x56: return PacketIncomingType.EntityTeleport;
case 0x4E: return PacketIncomingType.TimeUpdate; case 0x4E: return PacketIncomingType.TimeUpdate;
case 0x48: return PacketIncomingType.UpdateHealth; case 0x48: return PacketIncomingType.UpdateHealth;
case 0x47: return PacketIncomingType.SetExperience;
case 0x3F: return PacketIncomingType.HeldItemChange; case 0x3F: return PacketIncomingType.HeldItemChange;
case 0x1C: return PacketIncomingType.Explosion;
} }
} }
else // MC 1.15 else // MC 1.15
@ -287,7 +299,9 @@ namespace MinecraftClient.Protocol.Handlers
case 0x57: return PacketIncomingType.EntityTeleport; case 0x57: return PacketIncomingType.EntityTeleport;
case 0x4F: return PacketIncomingType.TimeUpdate; case 0x4F: return PacketIncomingType.TimeUpdate;
case 0x49: return PacketIncomingType.UpdateHealth; case 0x49: return PacketIncomingType.UpdateHealth;
case 0x48: return PacketIncomingType.SetExperience;
case 0x40: return PacketIncomingType.HeldItemChange; case 0x40: return PacketIncomingType.HeldItemChange;
case 0x1D: return PacketIncomingType.Explosion;
} }
} }
@ -331,6 +345,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.PlayerBlockPlacement: return 0x08; case PacketOutgoingType.PlayerBlockPlacement: return 0x08;
case PacketOutgoingType.CreativeInventoryAction: return 0x10; case PacketOutgoingType.CreativeInventoryAction: return 0x10;
case PacketOutgoingType.Animation: return 0x0A; case PacketOutgoingType.Animation: return 0x0A;
case PacketOutgoingType.PlayerDigging: return 0x07;
} }
} }
else if (protocol <= Protocol18Handler.MC1112Version) // MC 1.9, 1,10 and 1.11 else if (protocol <= Protocol18Handler.MC1112Version) // MC 1.9, 1,10 and 1.11
@ -356,6 +371,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.PlayerBlockPlacement: return 0x1C; case PacketOutgoingType.PlayerBlockPlacement: return 0x1C;
case PacketOutgoingType.CreativeInventoryAction: return 0x18; case PacketOutgoingType.CreativeInventoryAction: return 0x18;
case PacketOutgoingType.Animation: return 0x1A; case PacketOutgoingType.Animation: return 0x1A;
case PacketOutgoingType.PlayerDigging: return 0x13;
} }
} }
else if (protocol <= Protocol18Handler.MC112Version) // MC 1.12 else if (protocol <= Protocol18Handler.MC112Version) // MC 1.12
@ -381,6 +397,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.PlayerBlockPlacement: return 0x1F; case PacketOutgoingType.PlayerBlockPlacement: return 0x1F;
case PacketOutgoingType.CreativeInventoryAction: return 0x1B; case PacketOutgoingType.CreativeInventoryAction: return 0x1B;
case PacketOutgoingType.Animation: return 0x1D; case PacketOutgoingType.Animation: return 0x1D;
case PacketOutgoingType.PlayerDigging: return 0x14;
} }
} }
else if (protocol <= Protocol18Handler.MC1122Version) // 1.12.2 else if (protocol <= Protocol18Handler.MC1122Version) // 1.12.2
@ -406,6 +423,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.PlayerBlockPlacement: return 0x1F; case PacketOutgoingType.PlayerBlockPlacement: return 0x1F;
case PacketOutgoingType.CreativeInventoryAction: return 0x1B; case PacketOutgoingType.CreativeInventoryAction: return 0x1B;
case PacketOutgoingType.Animation: return 0x1D; case PacketOutgoingType.Animation: return 0x1D;
case PacketOutgoingType.PlayerDigging: return 0x14;
} }
} }
else if (protocol < Protocol18Handler.MC114Version) // MC 1.13 to 1.13.2 else if (protocol < Protocol18Handler.MC114Version) // MC 1.13 to 1.13.2
@ -431,6 +449,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.PlayerBlockPlacement: return 0x29; case PacketOutgoingType.PlayerBlockPlacement: return 0x29;
case PacketOutgoingType.CreativeInventoryAction: return 0x24; case PacketOutgoingType.CreativeInventoryAction: return 0x24;
case PacketOutgoingType.Animation: return 0x27; case PacketOutgoingType.Animation: return 0x27;
case PacketOutgoingType.PlayerDigging: return 0x18;
} }
} }
else // MC 1.14 to 1.15 else // MC 1.14 to 1.15
@ -456,6 +475,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.PlayerBlockPlacement: return 0x2C; case PacketOutgoingType.PlayerBlockPlacement: return 0x2C;
case PacketOutgoingType.CreativeInventoryAction: return 0x26; case PacketOutgoingType.CreativeInventoryAction: return 0x26;
case PacketOutgoingType.Animation: return 0x2A; case PacketOutgoingType.Animation: return 0x2A;
case PacketOutgoingType.PlayerDigging: return 0x1A;
} }
} }

View file

@ -185,5 +185,14 @@ namespace MinecraftClient.Protocol
/// <param name="insideBlock">TRUE if inside block</param> /// <param name="insideBlock">TRUE if inside block</param>
/// <returns>True if packet was successfully sent</returns> /// <returns>True if packet was successfully sent</returns>
bool SendPlayerBlockPlacement(int hand, Location location, int face, float CursorX, float CursorY, float CursorZ, bool insideBlock); bool SendPlayerBlockPlacement(int hand, Location location, int face, float CursorX, float CursorY, float CursorZ, bool insideBlock);
/// <summary>
/// Send player blog digging packet to the server
/// </summary>
/// <param name="status">0 to start diffing, 1 to cancel, 2 to finish ( https://wiki.vg/Protocol#Player_Digging )</param>
/// <param name="location">Location</param>
/// <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);
} }
} }

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -208,6 +208,29 @@ namespace MinecraftClient.Protocol
/// <param name="food"></param> /// <param name="food"></param>
void OnUpdateHealth(float health, int food); void OnUpdateHealth(float health, int food);
/// <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>
void OnExplosion(Location location, float strength, int affectedBlocks);
/// <summary>
/// Called when a player's game mode has changed
/// </summary>
/// <param name="uuid">Affected player's UUID</param>
/// <param name="gamemode">New game mode</param>
void OnGamemodeUpdate(Guid uuid, int gamemode);
/// <summary>
/// Called when Experience bar is updated
/// </summary>
/// <param name="Experiencebar">Experience bar level</param>
/// <param name="Level">Player Level</param>
/// <param name="TotalExperience">Total experience</param>
void OnSetExperience(float Experiencebar, int Level, int TotalExperience);
/// <summary> /// <summary>
/// Called when client need to change slot. /// Called when client need to change slot.
/// </summary> /// </summary>