Skip to content

Commit

Permalink
Allow precise setting of all the height-related properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed May 7, 2017
1 parent bff58b8 commit c0b0a2f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 14 deletions.
Expand Up @@ -86,7 +86,8 @@ public boolean isOnIce() {
}

/**
* Sets the player location object.
* Sets the player location object. See
* {@link #set(Location, Player, double)}.
*
* @param location
* the location
Expand All @@ -98,7 +99,8 @@ public void set(final Location location, final Player player) {
}

/**
* Sets the player location object. Does not set or reset blockCache.
* Sets the player location object. Does not account for special conditions like
* gliding with elytra with special casing, instead the maximum of accessible heights is used (eyeHeight, nms height/length). Does not set or reset blockCache.
*
* @param location
* the location
Expand All @@ -107,13 +109,29 @@ public void set(final Location location, final Player player) {
* @param yOnGround
* the y on ground
*/
public void set(final Location location, final Player player, final double yOnGround)
{
public void set(final Location location, final Player player, final double yOnGround) {
super.set(location, player, yOnGround);
// Entity reference.
this.player = player;
}

/**
* Like set, but for the height properties only the given height is used, no
* special cases.
*
* @param location
* @param player
* @param height
* @param yOnGround
*/
public void setByGivenHeight(final Location location, final Player player, final double height,
final double yOnGround) {
super.doSetExactHeight(location, player, true, getMCAccess().getWidth(player),
height, height, height, yOnGround);
// Entity reference.
this.player = player;
}

/**
* Not supported.
*
Expand Down
Expand Up @@ -32,6 +32,11 @@
*/
public class RichEntityLocation extends RichBoundsLocation {

/*
* TODO: HumanEntity default with + height (1.11.2): elytra 0.6/0.6,
* sleeping 0.2/0.2, sneaking 0.6/1.65, normal 0.6/1.8
*/

/** The mc access. */
// Final members //
private final IHandle<MCAccess> mcAccess;
Expand All @@ -40,7 +45,11 @@ public class RichEntityLocation extends RichBoundsLocation {
// Simple members //

/** Full bounding box width. */
private double width; // TODO: This is the entity width, happens to usually be the bounding box width +-. Move to entity / replace.
/*
* TODO: This is the entity width, happens to usually be the bounding box
* width +-. Move to entity / replace.
*/
private double width;

/** Some entity collision height. */
private double height; // TODO: Move to entity / replace.
Expand Down Expand Up @@ -154,7 +163,8 @@ public IHandle<MCAccess> getMCAccessHandle() {
* @return true, if successful
*/
public boolean standsOnEntity(final double yOnGround, final double xzMargin, final double yMargin) {
return blockCache.standsOnEntity(entity, minX - xzMargin, minY - yOnGround - yMargin, minZ - xzMargin, maxX + xzMargin, minY + yMargin, maxZ + xzMargin);
return blockCache.standsOnEntity(entity, minX - xzMargin, minY - yOnGround - yMargin, minZ - xzMargin,
maxX + xzMargin, minY + yMargin, maxZ + xzMargin);
}

/**
Expand All @@ -171,7 +181,8 @@ public boolean isOnGround() {
// Check if standing on an entity.
// TODO: Get rid of needing an entity for checking this (!). Move to RichBoundsLocation.
final double d1 = 0.25;
if (blockCache.standsOnEntity(entity, minX - d1, minY - yOnGround - d1, minZ - d1, maxX + d1, minY + 0.25 + d1, maxZ + d1)) {
if (blockCache.standsOnEntity(entity, minX - d1, minY - yOnGround - d1, minZ - d1,
maxX + d1, minY + 0.25 + d1, maxZ + d1)) {
res = onGround = standsOnEntity = true;
}
}
Expand Down Expand Up @@ -264,7 +275,8 @@ public boolean isHeadObstructed(double marginAboveEyeHeight, boolean stepCorrect
}
}
}
return BlockProperties.collides(blockCache, minX , maxY, minZ, maxX, maxY + marginAboveEyeHeight, maxZ, BlockProperties.F_GROUND | BlockProperties.F_SOLID);
return BlockProperties.collides(blockCache, minX , maxY, minZ, maxX, maxY + marginAboveEyeHeight, maxZ,
BlockProperties.F_GROUND | BlockProperties.F_SOLID);
}

/**
Expand All @@ -278,7 +290,8 @@ public boolean isHeadObstructed() {
}

/**
* Convenience constructor for using mcAccess.getHeight for fullHeight.
* Convenience constructor for using the maximum of mcAccess.getHeight() and
* eye height for fullHeight.
*
* @param location
* the location
Expand All @@ -293,7 +306,7 @@ public void set(final Location location, final Entity entity, final double yOnGr
}

/**
* Sets the.
*
*
* @param location
* the location
Expand All @@ -311,7 +324,7 @@ public void set(final Location location, final Entity entity, double fullHeight,
}

/**
* Sets the.
*
*
* @param location
* the location
Expand All @@ -325,14 +338,16 @@ public void set(final Location location, final Entity entity, double fullHeight,
* @param yOnGround
* the y on ground
*/
public void set(final Location location, final Entity entity, final double fullWidth, double fullHeight, final double yOnGround) {
public void set(final Location location, final Entity entity, final double fullWidth, double fullHeight,
final double yOnGround) {
doSet(location, entity, fullWidth, fullHeight, yOnGround);
}

/**
* Do set.<br>
* For the bounding box height, the maximum of given fullHeight, eyeHeight
* with sneaking ignored and entity height is used.
* with sneaking ignored and entity height is used. Sets isLiving and
* eyeHeight.
*
* @param location
* the location
Expand All @@ -345,7 +360,10 @@ public void set(final Location location, final Entity entity, final double fullW
* @param yOnGround
* the y on ground
*/
protected void doSet(final Location location, final Entity entity, final double fullWidth, double fullHeight, final double yOnGround) {
protected void doSet(final Location location, final Entity entity, final double fullWidth, double fullHeight,
final double yOnGround) {
final double eyeHeight;
final boolean isLiving;
if (entity instanceof LivingEntity) {
isLiving = true;
final LivingEntity living = (LivingEntity) entity;
Expand All @@ -356,7 +374,27 @@ protected void doSet(final Location location, final Entity entity, final double
isLiving = false;
eyeHeight = fullHeight;
}
doSetExactHeight(location, entity, isLiving, fullWidth, eyeHeight, fullHeight, fullHeight, yOnGround);
}

/**
*
* @param location
* @param entity
* @param isLiving
* @param fullWidth
* @param eyeHeight
* @param height
* Set as height (as in entity.height).
* @param fullHeight
* Bounding box height.
* @param yOnGround
*/
protected void doSetExactHeight(final Location location, final Entity entity, final boolean isLiving,
final double fullWidth, final double eyeHeight, final double height, final double fullHeight,
final double yOnGround) {
this.entity = entity;
this.isLiving = isLiving;
final MCAccess mcAccess = this.mcAccess.getHandle();
this.width = mcAccess.getWidth(entity);
this.height = mcAccess.getHeight(entity);
Expand Down

0 comments on commit c0b0a2f

Please sign in to comment.