ChatBot API: OnScoreboardObjective, OnEntityEffect, OnUpdateScore, EntityInteract, Hand list (#1097)

* Create Effect.cs
* Rename Effect.cs to Effects.cs
* Update MinecraftClient.csproj
* Update Effects.cs
* Update Effects.cs
* add EntityEffect
* Update McClient.cs
* Update Protocol18.cs + EntityEffect
* Update IMinecraftComHandler.cs
* Update Protocol18PacketTypes.cs + EntityEffect
* Update ChatBot.cs + OnEntityEquipment
* Update PacketIncomingType.cs + ScoreboardObjective
* Update Protocol18PacketTypes.cs
* Update Protocol18.cs
* Update IMinecraftComHandler.cs + OnScoreboardObjective
* Update McClient.cs + OnScoreboardObjective
* Update ChatBot.cs + OnScoreboardObjective event
* Update Protocol18.cs: fix scoreboard
* Update McClient.cs
* Update ChatBot.cs
* Update PacketIncomingType.cs
* Update ChatBot.cs + OnUpdateScore
* Update McClient.cs + OnUpdateScore
* Update IMinecraftComHandler.cs + OnUpdateScore
* Update Protocol18.cs
* Update Protocol18PacketTypes.cs
* Update Protocol18.cs + fix micro lags
* Update Protocol18.cs
* Update Protocol18.cs
* Update Protocol18.cs
* Update Protocol16.cs
* Update Protocol18.cs
* Update McClient.cs
* Update IMinecraftCom.cs
* Update McClient.cs
* Update McClient.cs
* Update McClient.cs
* Update ChatBot.cs + GetEntities()
* Create Hand.cs
* Update MinecraftClient.csproj
* Update McClient.cs
* Update ChatBot.cs
* Update Protocol18.cs
* Update ChatBot.cs
* Update ChatBot.cs
* Update ChatBot.cs
* Update ChatBot.cs
* Update ChatBot.cs: fix
* Update AutoAttack.cs: Fix
* Update McClient.cs: compile fix
* Update ChatBot.cs
* Update AutoAttack.cs
* Update ChatBot.cs
* Update Protocol18.cs
* Update IMinecraftComHandler.cs
* Update McClient.cs
* Update ChatBot.cs
* Update Protocol18.cs
* Update IMinecraftComHandler.cs
* Update ChatBot.cs
* Update McClient.cs
* Update McClient.cs: remove check distance
* Update EntityActionType.cs: more actions
* Create CommandBlockMode.cs
* Create CommandBlockFlags.cs
* Update IMinecraftCom.cs
* Update McClient.cs
* Update ChatBot.cs
* Update Protocol18.cs
* Update Protocol16.cs
* Update PacketOutgoingType.cs
* Update Protocol18PacketTypes.cs
* Update Protocol18.cs
This commit is contained in:
Рома Данилов 2020-07-04 13:45:51 +05:00 committed by GitHub
parent 572191dcd2
commit fb50b0d5cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 469 additions and 78 deletions

View file

@ -251,6 +251,34 @@ namespace MinecraftClient
/// <param name="item"> Item)</param>
public virtual void OnEntityEquipment(Entity entity, int slot, Item item) { }
/// <summary>
/// Called when the Entity use effects
/// </summary>
/// <param name="entityid">entity ID</param>
/// <param name="effect">effect id</param>
/// <param name="amplifier">effect amplifier</param>
/// <param name="duration">effect duration</param>
/// <param name="flags">effect flags</param>
public virtual void OnEntityEffect(Entity entity, Effects effect, int amplifier, int duration, byte flags) { }
/// <summary>
/// Called when coreboardObjective
/// </summary>
/// <param name="objectivename">objective name</param>
/// <param name="mode">0 to create the scoreboard. 1 to remove the scoreboard. 2 to update the display text.</param>
/// <param name="objectivevalue">Only if mode is 0 or 2. The text to be displayed for the score</param>
/// <param name="type">Only if mode is 0 or 2. 0 = "integer", 1 = "hearts".</param>
public virtual void OnScoreboardObjective(string objectivename, byte mode, string objectivevalue, int type, string json) { }
/// <summary>
/// Called when DisplayScoreboard
/// </summary>
/// <param name="entityname">The entity whose score this is. For players, this is their username; for other entities, it is their UUID.</param>
/// <param name="action">0 to create/update an item. 1 to remove an item.</param>
/// <param name="objectivename">The name of the objective the score belongs to</param>
/// <param name="value">he score to be displayed next to the entry. Only sent when Action does not equal 1.</param>
public virtual void OnUpdateScore(string entityname, byte action, string objectivename, int value) { }
/* =================================================================== */
/* ToolBox - Methods below might be useful while creating your bot. */
/* You should not need to interact with other classes of the program. */
@ -772,6 +800,15 @@ namespace MinecraftClient
return null;
}
/// <summary>
/// Get all Entityes
/// </summary>
/// <returns>All Entities</returns>
protected Dictionary<int, Entity> GetEntities()
{
return Handler.GetEntities();
}
/// <summary>
/// Get the current location of the player
/// </summary>
@ -960,10 +997,11 @@ namespace MinecraftClient
/// </summary>
/// <param name="EntityID"></param>
/// <param name="type">0: interact, 1: attack, 2: interact at</param>
/// <param name="hand">Hand.MainHand or Hand.OffHand</param>
/// <returns>TRUE in case of success</returns>
protected bool InteractEntity(int EntityID, int type)
protected bool InteractEntity(int EntityID, int type, Hand hand = Hand.MainHand)
{
return Handler.InteractEntity(EntityID, type);
return Handler.InteractEntity(EntityID, type, hand);
}
/// <summary>
@ -983,11 +1021,11 @@ namespace MinecraftClient
/// <summary>
/// Plays animation (Player arm swing)
/// </summary>
/// <param name="animation">0 for left arm, 1 for right arm</param>
/// <returns>TRUE in case of success</returns>
protected bool SendAnimation(int animation)
/// <param name="hand">Hand.MainHand or Hand.OffHand</param>
/// <returns>TRUE if animation successfully done</returns>
public bool SendAnimation(Hand hand = Hand.MainHand)
{
return Handler.DoAnimation(animation);
return Handler.DoAnimation((int)hand);
}
/// <summary>
@ -1009,13 +1047,15 @@ namespace MinecraftClient
}
/// <summary>
/// Place block
/// Place the block at hand in the Minecraft world
/// </summary>
/// <param name="location">Block location</param>
/// <returns></returns>
protected bool SendPlaceBlock(Location location, Direction blockFace)
/// <param name="location">Location to place block to</param>
/// <param name="blockFace">Block face (e.g. Direction.Down when clicking on the block below to place this block)</param>
/// <param name="hand">Hand.MainHand or Hand.OffHand</param>
/// <returns>TRUE if successfully placed</returns>
public bool SendPlaceBlock(Location location, Direction blockFace, Hand hand = Hand.MainHand)
{
return Handler.PlaceBlock(location, blockFace);
return Handler.PlaceBlock(location, blockFace, hand);
}
/// <summary>
@ -1090,6 +1130,18 @@ namespace MinecraftClient
return Handler.UpdateSign(location, line1, line2, line3, line4);
}
/// <summary>
/// Update command block
/// </summary>
/// <param name="location">command block location</param>
/// <param name="command">command</param>
/// <param name="mode">command block mode</param>
/// <param name="flags">command block flags</param>
protected bool UpdateCommandBlock(Location location, string command, CommandBlockMode mode, CommandBlockFlags flags)
{
return Handler.UpdateCommandBlock(location, command, mode, flags);
}
/// <summary>
/// Register a command in command prompt
/// </summary>
@ -1101,7 +1153,6 @@ namespace MinecraftClient
{
return Handler.RegisterCommand(CMDName, CMDDesc, Run);
}
}
/// <summary>
/// Command runner definition.
@ -1140,3 +1191,4 @@ namespace MinecraftClient
}
}
}
}

View file

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

View file

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MinecraftClient.Inventory
{
/// <summary>
/// Represents a Minecraft effects
/// </summary>
public enum Effects
{
Speed = 1,
Slowness = 2,
Haste = 3,
MiningFatigue = 4,
Strength = 5,
InstantHealth = 6,
InstantDamage = 7,
JumpBoost = 8,
Nausea = 9,
Regeneration = 10,
Resistance = 11,
FireResistance = 12,
WaterBreathing = 13,
Invisibility = 14,
Blindness = 15,
NightVision = 16,
Hunger = 17,
Weakness = 18,
Poison = 19,
Wither = 20,
HealthBoost = 21,
Absorption = 22,
Saturation = 23,
Glowing = 24,
Levitation = 25,
Luck = 26,
BadLuck = 27,
SlowFalling = 28,
ConduitPower = 29,
DolphinsGrace = 30,
BadOmen = 31,
HerooftheVillage = 32,
}
}

View file

@ -0,0 +1,11 @@
namespace MinecraftClient.Inventory
{
/// <summary>
/// Represents a Minecraft hand
/// </summary>
public enum Hand
{
MainHand = 0,
OffHand = 1,
}
}

View file

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MinecraftClient.Mapping
{
/// <summary>
/// Represents a unit movement in the world
/// </summary>
/// <see href="http://minecraft.gamepedia.com/Coordinates"/>
public enum CommandBlockFlags
{
TrackOutput = 0x01,
IsConditional = 0x02,
Automatic = 0x04,
}
}

View file

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MinecraftClient.Mapping
{
/// <summary>
/// Represents a unit movement in the world
/// </summary>
/// <see href="http://minecraft.gamepedia.com/Coordinates"/>
public enum CommandBlockMode
{
Sequence = 0,
Auto = 1,
Redstone = 2,
}
}

View file

@ -760,6 +760,15 @@ namespace MinecraftClient
return inventories;
}
/// <summary>
/// Get all Entityes
/// </summary>
/// <returns>All Entities</returns>
public Dictionary<int, Entity> GetEntities()
{
return entities;
}
/// <summary>
/// Get client player's inventory items
/// </summary>
@ -825,7 +834,7 @@ namespace MinecraftClient
{
lock (locationLock)
{
if (allowSmallTeleport && location.DistanceSquared(this.location) <= 32)
if (allowSmallTeleport)
{
// Allow small teleport within a range of 8 blocks. 1-step path to the desired location without checking anything
UpdateLocation(location, location); // Update yaw and pitch to look at next step
@ -1037,11 +1046,23 @@ namespace MinecraftClient
/// </summary>
/// <param name="EntityID"></param>
/// <param name="type">0: interact, 1: attack, 2: interact at</param>
/// <param name="hand">Hand.MainHand or Hand.OffHand</param>
/// <returns>TRUE if interaction succeeded</returns>
public bool InteractEntity(int EntityID, int type)
public bool InteractEntity(int EntityID, int type, Hand hand = Hand.MainHand)
{
if (entities.ContainsKey(EntityID))
{
if (type == 0)
{
return handler.SendInteractEntity(EntityID, type, (int)hand);
}
else
{
return handler.SendInteractEntity(EntityID, type);
}
}
else { return false; }
}
/// <summary>
/// Place the block at hand in the Minecraft world
@ -1049,9 +1070,9 @@ namespace MinecraftClient
/// <param name="location">Location to place block to</param>
/// <param name="blockFace">Block face (e.g. Direction.Down when clicking on the block below to place this block)</param>
/// <returns>TRUE if successfully placed</returns>
public bool PlaceBlock(Location location, Direction blockFace)
public bool PlaceBlock(Location location, Direction blockFace, Hand hand = Hand.MainHand)
{
return handler.SendPlayerBlockPlacement(0, location, blockFace);
return handler.SendPlayerBlockPlacement((int)hand, location, blockFace);
}
/// <summary>
@ -1105,6 +1126,17 @@ namespace MinecraftClient
return handler.SendUpdateSign(location, line1, line2, line3, line4);
}
/// <summary>
/// Update command block
/// </summary>
/// <param name="location">command block location</param>
/// <param name="command">command</param>
/// <param name="mode">command block mode</param>
/// <param name="flags">command block flags</param>
public bool UpdateCommandBlock(Location location, string command, CommandBlockMode mode, CommandBlockFlags flags)
{
return handler.UpdateCommandBlock(location, command, mode, flags);
}
#endregion
#region Event handlers: An event occurs on the Server
@ -1479,6 +1511,15 @@ namespace MinecraftClient
DispatchBotEvent(bot => bot.OnEntitySpawn(entity));
}
/// <summary>
/// Called when an entity effects
/// </summary>
public void OnEntityEffect(int entityid, Effects effect, int amplifier, int duration, byte flags)
{
if (entities.ContainsKey(entityid))
DispatchBotEvent(bot => bot.OnEntityEffect(entities[entityid], effect, amplifier, duration, flags));
}
/// <summary>
/// Called when a player spawns or enters the client's render distance
/// </summary>
@ -1725,6 +1766,31 @@ namespace MinecraftClient
DispatchBotEvent(bot => bot.OnTitle(action, titletext, subtitletext, actionbartext, fadein, stay, fadeout, json));
}
/// <summary>
/// Called when coreboardObjective
/// </summary>
/// <param name="objectivename">objective name</param>
/// <param name="mode">0 to create the scoreboard. 1 to remove the scoreboard. 2 to update the display text.</param>
/// <param name="objectivevalue">Only if mode is 0 or 2. The text to be displayed for the score</param>
/// <param name="type">Only if mode is 0 or 2. 0 = "integer", 1 = "hearts".</param>
public void OnScoreboardObjective(string objectivename, byte mode, string objectivevalue, int type)
{
string json = objectivevalue;
objectivevalue = ChatParser.ParseText(objectivevalue);
DispatchBotEvent(bot => bot.OnScoreboardObjective(objectivename, mode, objectivevalue, type, json));
}
/// <summary>
/// Called when DisplayScoreboard
/// </summary>
/// <param name="entityname">The entity whose score this is. For players, this is their username; for other entities, it is their UUID.</param>
/// <param name="action">0 to create/update an item. 1 to remove an item.</param>
/// <param name="objectivename">The name of the objective the score belongs to</param>
/// <param name="value">he score to be displayed next to the entry. Only sent when Action does not equal 1.</param>
public void OnUpdateScore(string entityname, byte action, string objectivename, int value)
{
DispatchBotEvent(bot => bot.OnUpdateScore(entityname, action, objectivename, value));
}
#endregion
}
}

View file

@ -110,6 +110,8 @@
<Compile Include="Commands\UseItem.cs" />
<Compile Include="Inventory\Container.cs" />
<Compile Include="Inventory\ContainerType.cs" />
<Compile Include="Inventory\Effects.cs" />
<Compile Include="Inventory\Hand.cs" />
<Compile Include="Inventory\Item.cs" />
<Compile Include="Inventory\ItemType.cs" />
<Compile Include="Inventory\ItemTypeExtensions.cs" />

View file

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -7,10 +7,14 @@ namespace MinecraftClient.Protocol
{
public enum EntityActionType
{
StartSneaking,
StopSneaking,
LeaveBed,
StartSprinting,
StopSprinting
StartSneaking = 0,
StopSneaking = 1,
LeaveBed = 2,
StartSprinting = 3,
StopSprinting = 4,
StartJumpWithHorse = 5,
StopJumpWithHorse = 6,
OpenHorseInventory = 7,
StartFlyingWithElytra = 8,
}
}

View file

@ -45,6 +45,7 @@ namespace MinecraftClient.Protocol.Handlers
EntityTeleport,
EntityEquipment,
EntityVelocity,
EntityEffect,
TimeUpdate,
UpdateHealth,
SetExperience,
@ -52,6 +53,8 @@ namespace MinecraftClient.Protocol.Handlers
Explosion,
MapData,
Title,
ScoreboardObjective,
UpdateScore,
/// <summary>
/// Represents a packet not implemented in MCC.

View file

@ -35,5 +35,6 @@ namespace MinecraftClient.Protocol.Handlers
Animation,
PlayerDigging,
UpdateSign,
UpdateCommandBlock,
}
}

View file

@ -688,6 +688,16 @@ namespace MinecraftClient.Protocol.Handlers
return false; //Currently not implemented
}
public bool SendInteractEntity(int EntityID, int type, int hand)
{
return false; //Currently not implemented
}
public bool UpdateCommandBlock(Location location, string command, CommandBlockMode mode, CommandBlockFlags flags)
{
return false; //Currently not implemented
}
public bool SendUseItem(int hand)
{
return false; //Currently not implemented

View file

@ -12,6 +12,9 @@ using MinecraftClient.Mapping.BlockPalettes;
using MinecraftClient.Mapping.EntityPalettes;
using MinecraftClient.Protocol.Handlers.Forge;
using MinecraftClient.Inventory;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Diagnostics;
namespace MinecraftClient.Protocol.Handlers
{
@ -745,6 +748,20 @@ namespace MinecraftClient.Protocol.Handlers
handler.OnSpawnPlayer(EntityID, UUID, EntityLocation, Yaw, Pitch);
}
break;
case PacketIncomingType.EntityEffect:
if (handler.GetEntityHandlingEnabled())
{
int entityid = dataTypes.ReadNextVarInt(packetData);
Inventory.Effects effect = Effects.Speed;
if (Enum.TryParse(dataTypes.ReadNextByte(packetData).ToString(), out effect))
{
int amplifier = dataTypes.ReadNextByte(packetData);
int duration = dataTypes.ReadNextVarInt(packetData);
byte flags = dataTypes.ReadNextByte(packetData);
handler.OnEntityEffect(entityid, effect, amplifier, duration, flags);
}
}
break;
case PacketIncomingType.DestroyEntities:
if (handler.GetEntityHandlingEnabled())
{
@ -867,6 +884,29 @@ namespace MinecraftClient.Protocol.Handlers
byte slot = dataTypes.ReadNextByte(packetData);
handler.OnHeldItemChange(slot);
break;
case PacketIncomingType.ScoreboardObjective:
string objectivename = dataTypes.ReadNextString(packetData);
byte mode = dataTypes.ReadNextByte(packetData);
string objectivevalue = String.Empty;
int type2 = -1;
if (mode == 0 || mode == 2)
{
objectivevalue = dataTypes.ReadNextString(packetData);
type2 = dataTypes.ReadNextVarInt(packetData);
}
handler.OnScoreboardObjective(objectivename, mode, objectivevalue, type2);
break;
case PacketIncomingType.UpdateScore:
string entityname = dataTypes.ReadNextString(packetData);
byte action3 = dataTypes.ReadNextByte(packetData);
string objectivename2 = dataTypes.ReadNextString(packetData);
int value = -1;
if (action3 != 1)
{
value = dataTypes.ReadNextVarInt(packetData);
}
handler.OnUpdateScore(entityname, action3, objectivename2, value);
break;
default:
return false; //Ignored packet
}
@ -1078,6 +1118,7 @@ namespace MinecraftClient.Protocol.Handlers
/// <returns>Completed text</returns>
IEnumerable<string> IAutoComplete.AutoComplete(string BehindCursor)
{
if (String.IsNullOrEmpty(BehindCursor))
return new string[] { };
@ -1117,9 +1158,13 @@ namespace MinecraftClient.Protocol.Handlers
SendPacket(PacketOutgoingType.TabComplete, tabcomplete_packet);
int wait_left = 50; //do not wait more than 5 seconds (50 * 100 ms)
Thread t1 = new Thread(new ThreadStart(delegate
{
while (wait_left > 0 && !autocomplete_received) { System.Threading.Thread.Sleep(100); wait_left--; }
if (autocomplete_result.Count > 0)
ConsoleIO.WriteLineFormatted("§8" + String.Join(" ", autocomplete_result), false);
}));
t1.Start();
return autocomplete_result;
}
@ -1418,6 +1463,21 @@ namespace MinecraftClient.Protocol.Handlers
catch (System.IO.IOException) { return false; }
catch (ObjectDisposedException) { return false; }
}
public bool SendInteractEntity(int EntityID, int type, int hand)
{
try
{
List<byte> fields = new List<byte>();
fields.AddRange(dataTypes.GetVarInt(EntityID));
fields.AddRange(dataTypes.GetVarInt(type));
fields.AddRange(dataTypes.GetVarInt(hand));
SendPacket(PacketOutgoingType.InteractEntity, fields);
return true;
}
catch (SocketException) { return false; }
catch (System.IO.IOException) { return false; }
catch (ObjectDisposedException) { return false; }
}
public bool SendInteractEntity(int EntityID, int type, float X, float Y, float Z)
{
return false;
@ -1645,5 +1705,26 @@ namespace MinecraftClient.Protocol.Handlers
catch (System.IO.IOException) { return false; }
catch (ObjectDisposedException) { return false; }
}
public bool UpdateCommandBlock(Location location, string command, CommandBlockMode mode, CommandBlockFlags flags)
{
if (protocolversion <= MC113Version)
{
try
{
List<byte> packet = new List<byte>();
packet.AddRange(dataTypes.GetLocation(location));
packet.AddRange(dataTypes.GetString(command));
packet.AddRange(dataTypes.GetVarInt((int)mode));
packet.Add((byte)flags);
SendPacket(PacketOutgoingType.UpdateSign, packet);
return true;
}
catch (SocketException) { return false; }
catch (System.IO.IOException) { return false; }
catch (ObjectDisposedException) { return false; }
}
else { return false; }
}
}
}

View file

@ -59,6 +59,7 @@ namespace MinecraftClient.Protocol.Handlers
case 0x18: return PacketIncomingType.EntityTeleport;
case 0x12: return PacketIncomingType.EntityVelocity;
case 0x04: return PacketIncomingType.EntityEquipment;
case 0x1E: return PacketIncomingType.EntityEffect;
case 0x03: return PacketIncomingType.TimeUpdate;
case 0x06: return PacketIncomingType.UpdateHealth;
case 0x1F: return PacketIncomingType.SetExperience;
@ -66,6 +67,8 @@ namespace MinecraftClient.Protocol.Handlers
case 0x27: return PacketIncomingType.Explosion;
case 0x34: return PacketIncomingType.MapData;
case 0x45: return PacketIncomingType.Title;
case 0x3B: return PacketIncomingType.ScoreboardObjective;
case 0x3C: return PacketIncomingType.UpdateScore;
}
}
else if (protocol <= Protocol18Handler.MC1112Version) // MC 1.9, 1.10 and 1.11
@ -103,6 +106,7 @@ namespace MinecraftClient.Protocol.Handlers
case 0x49: return PacketIncomingType.EntityTeleport;
case 0x3B: return PacketIncomingType.EntityVelocity;
case 0x3C: return PacketIncomingType.EntityEquipment;
case 0x4B: return PacketIncomingType.EntityEffect;
case 0x44: return PacketIncomingType.TimeUpdate;
case 0x3E: return PacketIncomingType.UpdateHealth;
case 0x3D: return PacketIncomingType.SetExperience;
@ -110,6 +114,8 @@ namespace MinecraftClient.Protocol.Handlers
case 0x1C: return PacketIncomingType.Explosion;
case 0x24: return PacketIncomingType.MapData;
case 0x45: return PacketIncomingType.Title;
case 0x3F: return PacketIncomingType.ScoreboardObjective;
case 0x42: return PacketIncomingType.UpdateScore;
}
}
else if (protocol <= Protocol18Handler.MC112Version) // MC 1.12.0
@ -147,6 +153,7 @@ namespace MinecraftClient.Protocol.Handlers
case 0x4B: return PacketIncomingType.EntityTeleport;
case 0x3D: return PacketIncomingType.EntityVelocity;
case 0x3E: return PacketIncomingType.EntityEquipment;
case 0x4E: return PacketIncomingType.EntityEffect;
case 0x46: return PacketIncomingType.TimeUpdate;
case 0x40: return PacketIncomingType.UpdateHealth;
case 0x3F: return PacketIncomingType.SetExperience;
@ -154,6 +161,8 @@ namespace MinecraftClient.Protocol.Handlers
case 0x1C: return PacketIncomingType.Explosion;
case 0x24: return PacketIncomingType.MapData;
case 0x47: return PacketIncomingType.Title;
case 0x41: return PacketIncomingType.ScoreboardObjective;
case 0x44: return PacketIncomingType.UpdateScore;
}
}
else if (protocol <= Protocol18Handler.MC1122Version) // MC 1.12.2
@ -191,6 +200,7 @@ namespace MinecraftClient.Protocol.Handlers
case 0x4C: return PacketIncomingType.EntityTeleport;
case 0x3E: return PacketIncomingType.EntityVelocity;
case 0x3F: return PacketIncomingType.EntityEquipment;
case 0x4F: return PacketIncomingType.EntityEffect;
case 0x47: return PacketIncomingType.TimeUpdate;
case 0x41: return PacketIncomingType.UpdateHealth;
case 0x40: return PacketIncomingType.SetExperience;
@ -198,6 +208,8 @@ namespace MinecraftClient.Protocol.Handlers
case 0x1C: return PacketIncomingType.Explosion;
case 0x25: return PacketIncomingType.MapData;
case 0x48: return PacketIncomingType.Title;
case 0x42: return PacketIncomingType.ScoreboardObjective;
case 0x45: return PacketIncomingType.UpdateScore;
}
}
else if (protocol < Protocol18Handler.MC114Version) // MC 1.13 to 1.13.2
@ -235,6 +247,7 @@ namespace MinecraftClient.Protocol.Handlers
case 0x50: return PacketIncomingType.EntityTeleport;
case 0x41: return PacketIncomingType.EntityVelocity;
case 0x42: return PacketIncomingType.EntityEquipment;
case 0x53: return PacketIncomingType.EntityEffect;
case 0x4A: return PacketIncomingType.TimeUpdate;
case 0x44: return PacketIncomingType.UpdateHealth;
case 0x43: return PacketIncomingType.SetExperience;
@ -242,6 +255,8 @@ namespace MinecraftClient.Protocol.Handlers
case 0x1E: return PacketIncomingType.Explosion;
case 0x26: return PacketIncomingType.MapData;
case 0x4B: return PacketIncomingType.Title;
case 0x45: return PacketIncomingType.ScoreboardObjective;
case 0x48: return PacketIncomingType.UpdateScore;
}
}
else if (protocol < Protocol18Handler.MC115Version) // MC 1.14 to 1.14.4
@ -279,6 +294,7 @@ namespace MinecraftClient.Protocol.Handlers
case 0x56: return PacketIncomingType.EntityTeleport;
case 0x41: return PacketIncomingType.EntityVelocity;
case 0x42: return PacketIncomingType.EntityEquipment;
case 0x59: return PacketIncomingType.EntityEffect;
case 0x4E: return PacketIncomingType.TimeUpdate;
case 0x48: return PacketIncomingType.UpdateHealth;
case 0x45: return PacketIncomingType.SetExperience;
@ -286,6 +302,8 @@ namespace MinecraftClient.Protocol.Handlers
case 0x1C: return PacketIncomingType.Explosion;
case 0x26: return PacketIncomingType.MapData;
case 0x4F: return PacketIncomingType.Title;
case 0x49: return PacketIncomingType.ScoreboardObjective;
case 0x4C: return PacketIncomingType.UpdateScore;
}
}
else if (protocol <= Protocol18Handler.MC1152Version) // MC 1.15 to 1.15.2
@ -323,6 +341,7 @@ namespace MinecraftClient.Protocol.Handlers
case 0x57: return PacketIncomingType.EntityTeleport;
case 0x46: return PacketIncomingType.EntityVelocity;
case 0x47: return PacketIncomingType.EntityEquipment;
case 0x5A: return PacketIncomingType.EntityEffect;
case 0x4F: return PacketIncomingType.TimeUpdate;
case 0x49: return PacketIncomingType.UpdateHealth;
case 0x48: return PacketIncomingType.SetExperience;
@ -330,6 +349,9 @@ namespace MinecraftClient.Protocol.Handlers
case 0x1D: return PacketIncomingType.Explosion;
case 0x27: return PacketIncomingType.MapData;
case 0x50: return PacketIncomingType.Title;
case 0x4A: return PacketIncomingType.ScoreboardObjective;
case 0x4D: return PacketIncomingType.UpdateScore;
}
} else {
switch (packetID)
@ -365,6 +387,7 @@ namespace MinecraftClient.Protocol.Handlers
case 0x56: return PacketIncomingType.EntityTeleport;
case 0x46: return PacketIncomingType.EntityVelocity;
case 0x47: return PacketIncomingType.EntityEquipment;
case 0x5A: return PacketIncomingType.EntityEffect;
case 0x4E: return PacketIncomingType.TimeUpdate;
case 0x49: return PacketIncomingType.UpdateHealth;
case 0x48: return PacketIncomingType.SetExperience;
@ -372,6 +395,8 @@ namespace MinecraftClient.Protocol.Handlers
case 0x1C: return PacketIncomingType.Explosion;
case 0x26: return PacketIncomingType.MapData;
case 0x4F: return PacketIncomingType.Title;
case 0x4A: return PacketIncomingType.ScoreboardObjective;
case 0x4D: return PacketIncomingType.UpdateScore;
}
}
@ -417,6 +442,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.Animation: return 0x0A;
case PacketOutgoingType.PlayerDigging: return 0x07;
case PacketOutgoingType.UpdateSign: return 0x12;
case PacketOutgoingType.UpdateCommandBlock: return 0x20;
}
}
else if (protocol <= Protocol18Handler.MC1112Version) // MC 1.9, 1,10 and 1.11
@ -444,6 +470,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.Animation: return 0x1A;
case PacketOutgoingType.PlayerDigging: return 0x13;
case PacketOutgoingType.UpdateSign: return 0x19;
case PacketOutgoingType.UpdateCommandBlock: return 0x20;
}
}
else if (protocol <= Protocol18Handler.MC112Version) // MC 1.12
@ -471,6 +498,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.Animation: return 0x1D;
case PacketOutgoingType.PlayerDigging: return 0x14;
case PacketOutgoingType.UpdateSign: return 0x1C;
case PacketOutgoingType.UpdateCommandBlock: return 0x20;
}
}
else if (protocol <= Protocol18Handler.MC1122Version) // 1.12.2
@ -498,6 +526,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.Animation: return 0x1D;
case PacketOutgoingType.PlayerDigging: return 0x14;
case PacketOutgoingType.UpdateSign: return 0x1C;
case PacketOutgoingType.UpdateCommandBlock: return 0x20;
}
}
else if (protocol < Protocol18Handler.MC114Version) // MC 1.13 to 1.13.2
@ -525,6 +554,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.Animation: return 0x27;
case PacketOutgoingType.PlayerDigging: return 0x18;
case PacketOutgoingType.UpdateSign: return 0x26;
case PacketOutgoingType.UpdateCommandBlock: return 0x22;
}
}
else if (protocol <= Protocol18Handler.MC1152Version) //MC 1.14 to 1.15.2
@ -552,6 +582,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.Animation: return 0x2A;
case PacketOutgoingType.PlayerDigging: return 0x1A;
case PacketOutgoingType.UpdateSign: return 0x29;
case PacketOutgoingType.UpdateCommandBlock: return 0x24;
}
}
else
@ -579,6 +610,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.Animation: return 0x2B;
case PacketOutgoingType.PlayerDigging: return 0x1B;
case PacketOutgoingType.UpdateSign: return 0x2A;
case PacketOutgoingType.UpdateCommandBlock: return 0x24;
}
}

View file

@ -132,6 +132,15 @@ namespace MinecraftClient.Protocol
/// <returns>True if packet was successfully sent</returns>
bool SendInteractEntity(int EntityID, int type, float X, float Y, float Z);
/// <summary>
/// Send an entity interaction packet to the server.
/// </summary>
/// <param name="EntityID">Entity ID to interact with</param>
/// <param name="type">Type of interaction (0: interact, 1: attack, 2: interact at)</param>
/// <param name="hand">Only if Type is interact or interact at; 0: main hand, 1: off hand</param>
/// <returns>True if packet was successfully sent</returns>
bool SendInteractEntity(int EntityID, int type, int hand);
/// <summary>
/// Send a use item packet to the server
/// </summary>
@ -202,5 +211,14 @@ namespace MinecraftClient.Protocol
/// <param name="line4">New line 4</param>
/// <returns>True if packet was succcessfully sent</returns>
bool SendUpdateSign(Location location, string line1, string line2, string line3, string line4);
/// <summary>
/// Update command block
/// </summary>
/// <param name="location">command block location</param>
/// <param name="command">command</param>
/// <param name="mode">command block mode</param>
/// <param name="flags">command block flags</param>
bool UpdateCommandBlock(Location location, string command, CommandBlockMode mode, CommandBlockFlags flags);
}
}

View file

@ -273,5 +273,33 @@ namespace MinecraftClient.Protocol
/// </summary>
/// <param name="EntityID">Player entity ID</param>
void OnReceivePlayerEntityID(int EntityID);
/// <summary>
/// Called when the Entity use effects
/// </summary>
/// <param name="entityid">entity ID</param>
/// <param name="effect">effect id</param>
/// <param name="amplifier">effect amplifier</param>
/// <param name="duration">effect duration</param>
/// <param name="flags">effect flags</param>
void OnEntityEffect(int entityid, Effects effect, int amplifier, int duration, byte flags);
/// <summary>
/// Called when coreboardObjective
/// </summary>
/// <param name="objectivename">objective name</param>
/// <param name="mode">0 to create the scoreboard. 1 to remove the scoreboard. 2 to update the display text.</param>
/// <param name="objectivevalue">Only if mode is 0 or 2. The text to be displayed for the score</param>
/// <param name="type">Only if mode is 0 or 2. 0 = "integer", 1 = "hearts".</param>
void OnScoreboardObjective(string objectivename, byte mode, string objectivevalue, int type);
/// <summary>
/// Called when DisplayScoreboard
/// </summary>
/// <param name="entityname">The entity whose score this is. For players, this is their username; for other entities, it is their UUID.</param>
/// <param name="action">0 to create/update an item. 1 to remove an item.</param>
/// <param name="objectivename">The name of the objective the score belongs to</param>
/// <param name="value">he score to be displayed next to the entry. Only sent when Action does not equal 1.</param>
void OnUpdateScore(string entityname, byte action, string objectivename, int value);
}
}