Skip to content

Commit

Permalink
Use movementThreshold() instead of 0.03 where appropiate
Browse files Browse the repository at this point in the history
  • Loading branch information
Axionize committed Nov 24, 2024
1 parent 5f7d296 commit 2518b23
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ private void check(PositionUpdate update) {
player.packetStateData.lastRiptide = currentTime;
}

SimpleCollisionBox steppingOnBB = GetBoundingBox.getCollisionBoxForPlayer(player, player.x, player.y, player.z).expand(0.03).offset(0, -1, 0);
SimpleCollisionBox steppingOnBB = GetBoundingBox.getCollisionBoxForPlayer(player, player.x, player.y, player.z).expand(player.getMovementThreshold()).offset(0, -1, 0);
Collisions.hasMaterial(player, steppingOnBB, (pair) -> {
WrappedBlockState data = pair.first();
if (data.getType() == StateTypes.SLIME_BLOCK && player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_8)) {
Expand Down Expand Up @@ -411,8 +411,8 @@ private void check(PositionUpdate update) {
player.uncertaintyHandler.lastUnderwaterFlyingHack.reset();
}

boolean couldBeStuckSpeed = Collisions.checkStuckSpeed(player, 0.03);
boolean couldLeaveStuckSpeed = player.isPointThree() && Collisions.checkStuckSpeed(player, -0.03);
boolean couldBeStuckSpeed = Collisions.checkStuckSpeed(player, player.getMovementThreshold());
boolean couldLeaveStuckSpeed = player.isPointThree() && Collisions.checkStuckSpeed(player, -player.getMovementThreshold());
player.uncertaintyHandler.claimingLeftStuckSpeed = !player.compensatedEntities.getSelf().inVehicle() && player.stuckSpeedMultiplier.getX() < 1 && !couldLeaveStuckSpeed;

if (couldBeStuckSpeed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,14 @@ public void updateSwimming() {


private void moveTowardsClosestSpace(double xPosition, double zPosition) {
player.boundingBox = player.boundingBox.expand(0.03, 0, 0.03); // 0.03... thanks mojang!
double movementThreshold = player.getMovementThreshold();
player.boundingBox = player.boundingBox.expand(movementThreshold, 0, movementThreshold); // 0.03... thanks mojang!
if (player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_14)) {
moveTowardsClosestSpaceModern(xPosition, zPosition);
} else {
moveTowardsClosestSpaceLegacy(xPosition, zPosition);
}
player.boundingBox = player.boundingBox.expand(-0.03, 0, -0.03);
player.boundingBox = player.boundingBox.expand(-movementThreshold, 0, -movementThreshold);
}

// Mojang is incompetent and this will push the player out a lot when using elytras
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,13 @@ public void handleChangeBlock(int x, int y, int z, WrappedBlockState state) {

// Calculate head hitters. Take a shortcut by checking if the player doesn't intersect with this block, but does
// when the player vertically moves upwards by 0.03! This is equivalent to the move method, but MUCH faster.
SimpleCollisionBox slightlyExpanded = normalBox.copy().expand(0.03, 0, 0.03);
if (!slightlyExpanded.isIntersected(data) && slightlyExpanded.offset(0, 0.03, 0).isIntersected(data)) {
double movementThreshold = player.getMovementThreshold();
SimpleCollisionBox slightlyExpanded = normalBox.copy().expand(movementThreshold, 0, movementThreshold);
if (!slightlyExpanded.isIntersected(data) && slightlyExpanded.offset(0, movementThreshold, 0).isIntersected(data)) {
headHitter = true;
}

SimpleCollisionBox pointThreeBox = GetBoundingBox.getBoundingBoxFromPosAndSize(player, player.x, player.y - 0.03, player.z, 0.66f, 1.86f);
SimpleCollisionBox pointThreeBox = GetBoundingBox.getBoundingBoxFromPosAndSize(player, player.x, player.y - movementThreshold, player.z, 0.66f, 1.86f);
if ((Materials.isWater(player.getClientVersion(), state) || stateType == StateTypes.LAVA) &&
pointThreeBox.isIntersected(new SimpleCollisionBox(x, y, z))) {

Expand Down Expand Up @@ -212,7 +213,8 @@ public void updatePlayerGravity() {
}

public void endOfTickTick() {
SimpleCollisionBox pointThreeBox = GetBoundingBox.getBoundingBoxFromPosAndSize(player, player.x, player.y - 0.03, player.z, 0.66f, 1.86f);
double movementThreshold = player.getMovementThreshold();
SimpleCollisionBox pointThreeBox = GetBoundingBox.getBoundingBoxFromPosAndSize(player, player.x, player.y - movementThreshold, player.z, 0.66f, 1.86f);

// Determine the head hitter using the current Y position
SimpleCollisionBox oldBB = player.boundingBox;
Expand All @@ -222,7 +224,7 @@ public void endOfTickTick() {
for (float sizes : (player.skippedTickInActualMovement ? new float[]{0.6f, 1.5f, 1.8f} : new float[]{player.pose.height})) {
// Try to limit collisions to be as small as possible, for maximum performance
player.boundingBox = GetBoundingBox.getBoundingBoxFromPosAndSize(player, player.x, player.y + (sizes - 0.01f), player.z, 0.6f, 0.01f);
headHitter = headHitter || Collisions.collide(player, 0, 0.03, 0).getY() != 0.03;
headHitter = headHitter || Collisions.collide(player, 0, movementThreshold, 0).getY() != movementThreshold;
}

player.boundingBox = oldBB;
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/ac/grim/grimac/utils/nmsutil/Collisions.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ public static boolean slowCouldPointThreeHitGround(GrimPlayer player, double x,
SimpleCollisionBox oldBB = player.boundingBox;
player.boundingBox = GetBoundingBox.getBoundingBoxFromPosAndSize(player, x, y, z, 0.6f, 0.06f);

double posXZ = Collisions.collide(player, 0.03, -0.03, 0.03).getY();
double negXNegZ = Collisions.collide(player, -0.03, -0.03, -0.03).getY();
double posXNegZ = Collisions.collide(player, 0.03, -0.03, -0.03).getY();
double posZNegX = Collisions.collide(player, -0.03, -0.03, 0.03).getY();
double movementThreshold = player.getMovementThreshold();
double posXZ = Collisions.collide(player, movementThreshold, -movementThreshold, movementThreshold).getY();
double negXNegZ = Collisions.collide(player, -movementThreshold, -movementThreshold, -movementThreshold).getY();
double posXNegZ = Collisions.collide(player, movementThreshold, -movementThreshold, -movementThreshold).getY();
double posZNegX = Collisions.collide(player, -movementThreshold, -movementThreshold, movementThreshold).getY();

player.boundingBox = oldBB;
return negXNegZ != -0.03 || posXNegZ != -0.03 || posXZ != -0.03 || posZNegX != -0.03;
return negXNegZ != -movementThreshold || posXNegZ != -movementThreshold || posXZ != -movementThreshold || posZNegX != -movementThreshold;
}

// Call this when there isn't uncertainty on the Y axis
Expand Down

0 comments on commit 2518b23

Please sign in to comment.