More events (#1660)

* + OnBlockBreakAnimation

* + OnBlockBreakAnimation

* + OnEntityAnimation

* Add checks

* + OnBlockChange

* + OnMultiBlockChange

* Fix

* Fix

* Fix

* add summary

* Fix

* fix other summary
This commit is contained in:
Рома Данилов 2021-07-04 11:26:41 +05:00 committed by GitHub
parent c0f128f632
commit 48577bf034
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 97 additions and 19 deletions

View file

@ -115,6 +115,21 @@ namespace MinecraftClient
/// </summary>
public virtual void Update() { }
/// <summary>
/// Will be called every player break block in gamemode 0
/// </summary>
/// <param name="entity">Player</param>
/// <param name="location">Block location</param>
/// <param name="stage">Destroy stage, maximum 255</param>
public virtual void OnBlockBreakAnimation(Entity entity, Location location, byte stage) { }
/// <summary>
/// Will be called every animations of the hit and place block
/// </summary>
/// <param name="entity">Player</param>
/// <param name="animation">0 = LMB, 1 = RMB (RMB Corrent not work)</param>
public virtual void OnEntityAnimation(Entity entity, byte animation) { }
/// <summary>
/// Any text sent by the server will be sent here by MinecraftCom
/// </summary>
@ -211,6 +226,7 @@ namespace MinecraftClient
/// Called when an explosion occurs on the server
/// </summary>
/// <param name="explode">Explosion location</param>
/// <param name="strength">Explosion strength</param>
/// <param name="recordcount">Amount of blocks blown up</param>
public virtual void OnExplosion(Location explode, float strength, int recordcount) { }
@ -288,7 +304,7 @@ namespace MinecraftClient
/// <summary>
/// Called when an entity has effect applied
/// </summary>
/// <param name="entityid">entity ID</param>
/// <param name="entity">entity</param>
/// <param name="effect">effect id</param>
/// <param name="amplifier">effect amplifier</param>
/// <param name="duration">effect duration</param>
@ -367,7 +383,6 @@ namespace MinecraftClient
/// </summary>
/// <param name="entity">Entity</param>
/// <param name="metadata">The metadata of the entity</param>
/// <param name="protocolversion">Ptotocol version</param>
public virtual void OnEntityMetadata(Entity entity, Dictionary<int, object> metadata) { }
/// <summary>

View file

@ -2502,6 +2502,34 @@ namespace MinecraftClient
DispatchBotEvent(bot => bot.OnTradeList(windowID, trades, villagerInfo));
}
/// <summary>
/// Will be called every player break block in gamemode 0
/// </summary>
/// <param name="entityId">Player ID</param>
/// <param name="location">Block location</param>
/// <param name="stage">Destroy stage, maximum 255</param>
public void OnBlockBreakAnimation(int entityId, Location location, byte stage)
{
if (entities.ContainsKey(entityId))
{
Entity entity = entities[entityId];
DispatchBotEvent(bot => bot.OnBlockBreakAnimation(entity, location, stage));
}
}
/// <summary>
/// Will be called every animations of the hit and place block
/// </summary>
/// <param name="entityID">Player ID</param>
/// <param name="animation">0 = LMB, 1 = RMB (RMB Corrent not work)</param>
public void OnEntityAnimation(int entityID, byte animation)
{
if (entities.ContainsKey(entityID))
{
Entity entity = entities[entityID];
DispatchBotEvent(bot => bot.OnEntityAnimation(entity, animation));
}
}
#endregion
}
}

View file

@ -628,7 +628,10 @@ namespace MinecraftClient.Protocol.Handlers
byte blockMeta = dataTypes.ReadNextByte(packetData);
handler.GetWorld().SetBlock(new Location(blockX, blockY, blockZ), new Block(blockId, blockMeta));
}
else handler.GetWorld().SetBlock(dataTypes.ReadNextLocation(packetData), new Block((ushort)dataTypes.ReadNextVarInt(packetData)));
else
{
handler.GetWorld().SetBlock(dataTypes.ReadNextLocation(packetData), new Block((ushort)dataTypes.ReadNextVarInt(packetData)));
}
}
break;
case PacketTypesIn.MapChunkBulk:
@ -1112,6 +1115,23 @@ namespace MinecraftClient.Protocol.Handlers
value = dataTypes.ReadNextVarInt(packetData);
handler.OnUpdateScore(entityname, action3, objectivename2, value);
break;
case PacketTypesIn.BlockBreakAnimation:
if (handler.GetEntityHandlingEnabled() && handler.GetTerrainEnabled())
{
int playerId = dataTypes.ReadNextVarInt(packetData);
Location blockLocation = dataTypes.ReadNextLocation(packetData);
byte stage = dataTypes.ReadNextByte(packetData);
handler.OnBlockBreakAnimation(playerId, blockLocation, stage);
}
break;
case PacketTypesIn.EntityAnimation:
if (handler.GetEntityHandlingEnabled())
{
int playerId2 = dataTypes.ReadNextVarInt(packetData);
byte animation = dataTypes.ReadNextByte(packetData);
handler.OnEntityAnimation(playerId2, animation);
}
break;
default:
return false; //Ignored packet
}

View file

@ -84,6 +84,21 @@ namespace MinecraftClient.Protocol
/// <param name="isJson">TRUE if the text is JSON-Encoded</param>
void OnTextReceived(string text, bool isJson);
/// <summary>
/// Will be called every animations of the hit and place block
/// </summary>
/// <param name="entityID">Player ID</param>
/// <param name="animation">0 = LMB, 1 = RMB (RMB Corrent not work)</param>
void OnEntityAnimation(int entityID, byte animation);
/// <summary>
/// Will be called every player break block in gamemode 0
/// </summary>
/// <param name="entityId">Player ID</param>
/// <param name="location">Block location</param>
/// <param name="stage">Destroy stage, maximum 255</param>
void OnBlockBreakAnimation(int entityID, Location location, byte stage);
/// <summary>
/// This method is called when the protocol handler receives a title
/// </summary>