Comments for BoundingBox

This commit is contained in:
themode 2020-10-05 03:59:47 +02:00
parent f79a024dc1
commit 5b26031a92
2 changed files with 95 additions and 8 deletions

View File

@ -13,6 +13,14 @@ public class BoundingBox {
private final Entity entity;
private float x, y, z;
/**
* Create a {@link BoundingBox} linked to an {@link Entity} and with a specific size
*
* @param entity the linked entity
* @param x the width size
* @param y the height size
* @param z the depth size
*/
public BoundingBox(Entity entity, float x, float y, float z) {
this.entity = entity;
this.x = x;
@ -21,10 +29,10 @@ public class BoundingBox {
}
/**
* Used to know if two BoundingBox intersect with each other
* Used to know if two {@link BoundingBox} intersect with each other
*
* @param boundingBox the bounding box to check
* @return true if the two BoundingBox intersect with each other, false otherwise
* @param boundingBox the {@link BoundingBox} to check
* @return true if the two {@link BoundingBox} intersect with each other, false otherwise
*/
public boolean intersect(BoundingBox boundingBox) {
return (getMinX() <= boundingBox.getMaxX() && getMaxX() >= boundingBox.getMinX()) &&
@ -33,7 +41,7 @@ public class BoundingBox {
}
/**
* Used to know if this bounding box intersects with the bounding box of an entity
* Used to know if this {@link BoundingBox} intersects with the bounding box of an entity
*
* @param entity the entity to check the bounding box
* @return true if this bounding box intersects with the entity, false otherwise
@ -43,7 +51,7 @@ public class BoundingBox {
}
/**
* Used to know if the bounding box intersects with a block (can be air)
* Used to know if the bounding box intersects at a {@link BlockPosition}
*
* @param blockPosition the position to check
* @return true if the bounding box intersects with the position, false otherwise
@ -87,19 +95,19 @@ public class BoundingBox {
}
/**
* Create a new bounding box linked to the same entity with expanded size
* Create a new {@link BoundingBox} linked to the same {@link Entity} with expanded size
*
* @param x the X offset
* @param y the Y offset
* @param z the Z offset
* @return a new bounding box expanded
* @return a new {@link BoundingBox} expanded
*/
public BoundingBox expand(float x, float y, float z) {
return new BoundingBox(entity, this.x + x, this.y + y, this.z + z);
}
/**
* Create a new bounding box linked to the same entity with contracted size
* Create a new {@link BoundingBox} linked to the same {@link Entity} with contracted size
*
* @param x the X offset
* @param y the Y offset
@ -110,42 +118,92 @@ public class BoundingBox {
return new BoundingBox(entity, this.x - x, this.y - y, this.z - z);
}
/**
* Get the width of the {@link BoundingBox}
*
* @return the width
*/
public float getWidth() {
return x;
}
/**
* Get the height of the {@link BoundingBox}
*
* @return the height
*/
public float getHeight() {
return y;
}
/**
* Get the depth of the {@link BoundingBox}
*
* @return the depth
*/
public float getDepth() {
return z;
}
/**
* Get the min X based on {@link #getWidth()} and the {@link Entity} position
*
* @return the min X
*/
public float getMinX() {
return entity.getPosition().getX() - (x / 2);
}
/**
* Get the max X based on {@link #getWidth()} and the {@link Entity} position
*
* @return the max X
*/
public float getMaxX() {
return entity.getPosition().getX() + (x / 2);
}
/**
* Get the min Y based on the {@link Entity} position
*
* @return the min Y
*/
public float getMinY() {
return entity.getPosition().getY();
}
/**
* Get the max Y based on {@link #getHeight()} and the {@link Entity} position
*
* @return the max Y
*/
public float getMaxY() {
return entity.getPosition().getY() + y;
}
/**
* Get the min Z based on {@link #getDepth()} and the {@link Entity} position
*
* @return the min Z
*/
public float getMinZ() {
return entity.getPosition().getZ() - (z / 2);
}
/**
* Get the max Z based on {@link #getDepth()} and the {@link Entity} position
*
* @return the max Z
*/
public float getMaxZ() {
return entity.getPosition().getZ() + (z / 2);
}
/**
* Get an array of {@link Vector} representing the points at the bottom of the {@link BoundingBox}
*
* @return the points at the bottom of the {@link BoundingBox}
*/
public Vector[] getBottomFace() {
return new Vector[]{
new Vector(getMinX(), getMinY(), getMinZ()),
@ -155,6 +213,11 @@ public class BoundingBox {
};
}
/**
* Get an array of {@link Vector} representing the points at the top of the {@link BoundingBox}
*
* @return the points at the top of the {@link BoundingBox}
*/
public Vector[] getTopFace() {
return new Vector[]{
new Vector(getMinX(), getMaxY(), getMinZ()),
@ -164,6 +227,11 @@ public class BoundingBox {
};
}
/**
* Get an array of {@link Vector} representing the points on the left face of the {@link BoundingBox}
*
* @return the points on the left face of the {@link BoundingBox}
*/
public Vector[] getLeftFace() {
return new Vector[]{
new Vector(getMinX(), getMinY(), getMinZ()),
@ -173,6 +241,11 @@ public class BoundingBox {
};
}
/**
* Get an array of {@link Vector} representing the points on the right face of the {@link BoundingBox}
*
* @return the points on the right face of the {@link BoundingBox}
*/
public Vector[] getRightFace() {
return new Vector[]{
new Vector(getMaxX(), getMinY(), getMinZ()),
@ -182,6 +255,11 @@ public class BoundingBox {
};
}
/**
* Get an array of {@link Vector} representing the points at the front of the {@link BoundingBox}
*
* @return the points at the front of the {@link BoundingBox}
*/
public Vector[] getFrontFace() {
return new Vector[]{
new Vector(getMinX(), getMinY(), getMinZ()),
@ -191,6 +269,11 @@ public class BoundingBox {
};
}
/**
* Get an array of {@link Vector} representing the points at the back of the {@link BoundingBox}
*
* @return the points at the back of the {@link BoundingBox}
*/
public Vector[] getBackFace() {
return new Vector[]{
new Vector(getMinX(), getMinY(), getMaxZ()),

View File

@ -1792,6 +1792,10 @@ public class Player extends LivingEntity implements CommandSender {
return vehicleInformation;
}
/**
* Send to the player a {@link PlayerAbilitiesPacket} with all the updated fields
* (walkingSpeed sets to 0.1)
*/
protected void refreshAbilities() {
PlayerAbilitiesPacket playerAbilitiesPacket = new PlayerAbilitiesPacket();
playerAbilitiesPacket.invulnerable = invulnerable;