Add code documentation, move and rename a few methods

This commit is contained in:
ORelio 2020-03-28 00:48:41 +01:00
parent 90c6e776e1
commit 195e162c7d
10 changed files with 286 additions and 96 deletions

View file

@ -5,97 +5,117 @@ using System.Text;
namespace MinecraftClient.Mapping
{
/// <summary>
/// Represents an entity evolving into a Minecraft world
/// </summary>
public class Entity
{
/// <summary>
/// ID of the entity on the Minecraft server
/// </summary>
public int ID;
public int TypeID;
/// <summary>
/// Entity type determined by Minecraft Console Client
/// </summary>
public EntityType Type;
public string Name;
/// <summary>
/// Entity type ID (more precise than Type, but may change between Minecraft versions)
/// </summary>
public int TypeID;
/// <summary>
/// Entity location in the Minecraft world
/// </summary>
public Location Location;
/// <summary>
/// Create a new entity based on Entity ID and location
/// </summary>
/// <param name="ID">Entity ID</param>
/// <param name="location">Entity location</param>
public Entity(int ID, Location location)
{
this.ID = ID;
this.Location = location;
}
/// <summary>
/// Create a new entity based on Entity ID, Entity Type and location
/// </summary>
/// <param name="ID">Entity ID</param>
/// <param name="TypeID">Entity Type ID</param>
/// <param name="location">Entity location</param>
public Entity(int ID, int TypeID, Location location)
{
this.ID = ID;
this.TypeID = TypeID;
this.Name = GetMobName(TypeID);
this.Location = location;
}
/// <summary>
/// Create a new entity based on Entity ID, Entity Type and location
/// </summary>
/// <param name="ID">Entity ID</param>
/// <param name="TypeID">Entity Type ID</param>
/// <param name="type">Entity Type Enum</param>
/// <param name="location">Entity location</param>
public Entity(int ID, int TypeID, EntityType type, Location location)
{
this.ID = ID;
this.TypeID = TypeID;
this.Type = type;
this.Name = GetMobName(TypeID);
this.Location = location;
}
/// <summary>
/// Create a new entity based on Entity ID, Entity Type and location
/// </summary>
/// <param name="ID">Entity ID</param>
/// <param name="type">Entity Type Enum</param>
/// <param name="location">Entity location</param>
public Entity(int ID, EntityType type, Location location)
{
this.ID = ID;
this.Type = type;
this.Location = location;
}
public Entity(int ID, int TypeID, string Name, Location location)
{
this.ID = ID;
this.TypeID = TypeID;
this.Name = Name;
this.Location = location;
}
/// <summary>
/// Calculate the distance between two coordinate
/// Return TRUE if the Entity is an hostile mob
/// </summary>
/// <param name="l1"></param>
/// <param name="l2"></param>
/// <returns></returns>
public static double CalculateDistance(Location l1, Location l2)
/// <remarks>New mobs added in newer Minecraft versions might be absent from the list</remarks>
/// <returns>TRUE if hostile</returns>
public bool IsHostile()
{
return Math.Sqrt(Math.Pow(l2.X - l1.X, 2) + Math.Pow(l2.Y - l1.Y, 2) + Math.Pow(l2.Z - l1.Z, 2));
}
/// <summary>
/// Get the mob name by entity type ID.
/// </summary>
/// <param name="EntityType"></param>
/// <returns></returns>
public static string GetMobName(int EntityType)
{
// only mobs in this list will be auto attacked
switch (EntityType)
switch (TypeID)
{
case 5: return "Blaze";
case 12: return "Creeper";
case 16: return "Drowned";
case 23: return "Evoker";
case 29: return "Ghast";
case 31: return "Guardian";
case 33: return "Husk";
case 41: return "Magma Cube";
case 57: return "Zombie Pigman";
case 63: return "Shulker";
case 65: return "Silverfish";
case 66: return "Skeleton";
case 68: return "Slime";
case 75: return "Stray";
case 84: return "Vex";
case 87: return "Vindicator";
case 88: return "Pillager";
case 90: return "Witch";
case 92: return "Wither Skeleton";
case 95: return "Zombie";
case 97: return "Zombie Villager";
case 98: return "Phantom";
case 99: return "Ravager";
default: return "";
case 5: return true; // Blaze;
case 12: return true; // Creeper
case 16: return true; // Drowned
case 23: return true; // Evoker
case 29: return true; // Ghast
case 31: return true; // Guardian
case 33: return true; // Husk
case 41: return true; // Magma Cube
case 57: return true; // Zombie Pigman
case 63: return true; // Shulker
case 65: return true; // Silverfish
case 66: return true; // Skeleton
case 68: return true; // Slime
case 75: return true; // Stray
case 84: return true; // Vex
case 87: return true; // Vindicator
case 88: return true; // Pillager
case 90: return true; // Witch
case 92: return true; // Wither Skeleton
case 95: return true; // Zombie
case 97: return true; // Zombie Villager
case 98: return true; // Phantom
case 99: return true; // Ravager
default: return false;
}
}
public string GetMobName()
{
return GetMobName(TypeID);
}
}
}