mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-11-07 17:36:07 +00:00
New method for getting looking location (#1503)
* New method for getting looking location * improve
This commit is contained in:
parent
240468ad22
commit
90505dbc4c
5 changed files with 98 additions and 12 deletions
|
|
@ -54,6 +54,18 @@ namespace MinecraftClient.Mapping
|
|||
/// </summary>
|
||||
public Location Location;
|
||||
|
||||
/// <summary>
|
||||
/// Entity head yaw
|
||||
/// </summary>
|
||||
/// <remarks>Untested</remarks>
|
||||
public float Yaw = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Entity head pitch
|
||||
/// </summary>
|
||||
/// <remarks>Untested</remarks>
|
||||
public float Pitch = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Health of the entity
|
||||
/// </summary>
|
||||
|
|
@ -94,6 +106,25 @@ namespace MinecraftClient.Mapping
|
|||
this.Equipment = new Dictionary<int, Item>();
|
||||
this.Item = new Item(ItemType.Air, 0, null);
|
||||
}
|
||||
|
||||
/// <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, byte yaw, byte pitch)
|
||||
{
|
||||
this.ID = ID;
|
||||
this.Type = type;
|
||||
this.Location = location;
|
||||
this.Health = 1.0f;
|
||||
this.Equipment = new Dictionary<int, Item>();
|
||||
this.Item = new Item(ItemType.Air, 0, null);
|
||||
this.Yaw = yaw * (1 / 256) * 360; // to angle in 360 degree
|
||||
this.Pitch = pitch * (1 / 256) * 360;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new entity based on Entity ID, Entity Type, location, name and UUID
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -152,5 +152,36 @@ namespace MinecraftClient.Mapping
|
|||
{
|
||||
chunks = new Dictionary<int, Dictionary<int, ChunkColumn>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the location of block of the entity is looking
|
||||
/// </summary>
|
||||
/// <param name="location">Location of the entity</param>
|
||||
/// <param name="yaw">Yaw of the entity</param>
|
||||
/// <param name="pitch">Pitch of the entity</param>
|
||||
/// <returns>Location of the block or empty Location if no block was found</returns>
|
||||
public Location GetLookingBlockLocation(Location location, double yaw, double pitch)
|
||||
{
|
||||
double rotX = (Math.PI / 180) * yaw;
|
||||
double rotY = (Math.PI / 180) * pitch;
|
||||
double x = -Math.Cos(rotY) * Math.Sin(rotX);
|
||||
double y = -Math.Sin(rotY);
|
||||
double z = Math.Cos(rotY) * Math.Cos(rotX);
|
||||
Location vector = new Location(x, y, z);
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
Location newVector = vector * i;
|
||||
Location blockLocation = location.EyesLocation() + new Location(newVector.X, newVector.Y, newVector.Z);
|
||||
blockLocation.X = Math.Floor(blockLocation.X);
|
||||
blockLocation.Y = Math.Floor(blockLocation.Y);
|
||||
blockLocation.Z = Math.Floor(blockLocation.Z);
|
||||
Block b = GetBlock(blockLocation);
|
||||
if (b.Type != Material.Air)
|
||||
{
|
||||
return blockLocation;
|
||||
}
|
||||
}
|
||||
return new Location();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue