diff --git a/MinecraftClient/ChatBot.cs b/MinecraftClient/ChatBot.cs index fbb35bf2..538b91c2 100644 --- a/MinecraftClient/ChatBot.cs +++ b/MinecraftClient/ChatBot.cs @@ -168,8 +168,17 @@ namespace MinecraftClient /// Entity wich has just disappeared public virtual void OnEntityDespawn(Mapping.Entity entity) { } + /// + /// Called when the player held item has changed + /// + /// New slot ID public virtual void OnHeldItemChange(byte slot) { } + /// + /// Called when the player health has been updated + /// + /// New player health + /// New food level public virtual void OnHealthUpdate(float health, int food) { } /* =================================================================== */ @@ -685,6 +694,15 @@ namespace MinecraftClient return Handler.MoveTo(location, allowUnsafe); } + /// + /// Look at the specified location + /// + /// Location to look at + protected void LookAtLocation(Mapping.Location location) + { + Handler.UpdateLocation(Handler.GetCurrentLocation(), location); + } + /// /// Get a Y-M-D h:m:s timestamp representing the current system date and time /// diff --git a/MinecraftClient/config/ChatBots/AutoLook.cs b/MinecraftClient/config/ChatBots/AutoLook.cs new file mode 100644 index 00000000..d182edb1 --- /dev/null +++ b/MinecraftClient/config/ChatBots/AutoLook.cs @@ -0,0 +1,64 @@ +//MCCScript 1.0 + +MCC.LoadBot(new AutoLook()); + +//MCCScript Extensions + +public class AutoLook : ChatBot +{ + private Entity _entityToLookAt; + public override void Initialize() + { + if (GetEntityHandlingEnabled() && GetTerrainEnabled()) return; + LogToConsole("Entity Handling or Terrain Handling is not enabled in the config file!"); + LogToConsole("This bot will be unloaded."); + UnloadBot(); + } + + public override void OnEntityDespawn(Entity entity) + { + if (entity == _entityToLookAt) + { + _entityToLookAt = null; + } + } + public override void OnEntitySpawn(Entity entity) + { + HandleEntity(entity); + } + public override void OnEntityMove(Entity entity) + { + var tempBool = HandleEntity(entity); + //LogDebugToConsole(tempBool); + if (!tempBool) return; + LookAtLocation(entity.Location); + } + + /// + /// Handles an entity, and tracks it if it is closer then the one we are currently tracking + /// + /// True if found + private bool HandleEntity(Entity entity) + { + if (entity.Type != EntityType.Player) + { + return false; + } + if (_entityToLookAt == null) + { + _entityToLookAt = entity; + return true; + } + if (GetCurrentLocation().Distance(entity.Location) < GetCurrentLocation().Distance(_entityToLookAt.Location)) + { + _entityToLookAt = entity; + return true; + } + + if (entity.ID != _entityToLookAt.ID) return false; + _entityToLookAt = entity; //Handle looking at the same entity + return true; + + } + +} \ No newline at end of file diff --git a/MinecraftClient/config/Modules/VkMessager.cs b/MinecraftClient/config/ChatBots/VkMessager.cs similarity index 100% rename from MinecraftClient/config/Modules/VkMessager.cs rename to MinecraftClient/config/ChatBots/VkMessager.cs