mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Upgrade GetLookingBlock
This commit is contained in:
parent
ba6a954f45
commit
4aa6c1c99f
11 changed files with 213 additions and 74 deletions
|
|
@ -144,7 +144,7 @@ namespace MinecraftClient.Mapping
|
|||
if (chunk != null)
|
||||
return chunk.GetBlock(location);
|
||||
}
|
||||
return new Block(0); //Air
|
||||
return Block.Air;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -218,36 +218,5 @@ namespace MinecraftClient.Mapping
|
|||
chunkCnt = 0;
|
||||
chunkLoadNotCompleted = 0;
|
||||
}
|
||||
|
||||
/// <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