Skip to content

Commit

Permalink
Stop using server-side tracked position; expand from client area instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Axionize committed Jan 20, 2025
1 parent 9aa555f commit 8e6219c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -444,21 +444,9 @@ private void handleMoveEntity(PacketSendEvent event, int entityId, double deltaX
data.setY(data.getY() + deltaY);
data.setZ(data.getZ() + deltaZ);
} else {
// In versions < 1.16.2 when the client receives non-relative teleport for an entity
// And they move less by the thresholds given, the entity does not move client side
if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_16_1)
&& Math.abs(deltaX - data.getX()) < 0.03125D
&& Math.abs(deltaY - data.getY()) < 0.015625D
&& Math.abs(deltaZ - data.getZ()) < 0.03125D
) {
// We don't have to do anything
// yaw and pitch are still updated as they should be
} else {
// player.compensatedEntities.entityMap.updateEntityPosition(player.compensatedEntities.entityMap.get(entityId), new Vector3d(deltaX, deltaY, deltaZ));
data.setX(deltaX);
data.setY(deltaY);
data.setZ(deltaZ);
}
data.setX(deltaX);
data.setY(deltaY);
data.setZ(deltaZ);
}
if (yaw != null) {
data.setXRot(yaw);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,18 @@ public double distance(SimpleCollisionBox box) {
return hxz - (xwidth + zwidth + bxwidth + bzwidth) / 4;
}

public double distanceX(double x) {
return x >= this.minX && x <= this.maxX ? 0.0 : Math.min(Math.abs(x - this.minX), Math.abs(x - this.maxX));
}

public double distanceY(double y) {
return y >= this.minY && y <= this.maxY ? 0.0 : Math.min(Math.abs(y - this.minY), Math.abs(y - this.maxY));
}

public double distanceZ(double z) {
return z >= this.minZ && z <= this.maxZ ? 0.0 : Math.min(Math.abs(z - this.minZ), Math.abs(z - this.maxZ));
}

/**
* Calculates intersection with the given ray between a certain distance
* interval.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ReachInterpolationData {
private int interpolationStepsLowBound = 0;
private int interpolationStepsHighBound = 0;
private int interpolationSteps = 1;
private boolean expandNonRelative = false;

public ReachInterpolationData(GrimPlayer player, SimpleCollisionBox startingLocation, TrackedPosition position, PacketEntity entity) {
final boolean isPointNine = !player.compensatedEntities.getSelf().inVehicle() && player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9);
Expand Down Expand Up @@ -143,6 +144,9 @@ public SimpleCollisionBox getPossibleLocationCombined() {
startingLocation.maxZ + (step * stepMaxZ)));
}

if (expandNonRelative)
minimumInterpLocation.expand(0.03125D, 0.015625D, 0.03125D);

return minimumInterpLocation;
}

Expand Down Expand Up @@ -199,4 +203,8 @@ public String toString() {
", interpolationStepsHighBound=" + interpolationStepsHighBound +
'}';
}

public void expandNonRelative() {
expandNonRelative = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,23 @@ public void onFirstTransaction(boolean relative, boolean hasPos, double relX, do
}
trackedServerPosition.setPos(vec3d);
} else {
// I think we can reduce this but I'm too lazy to minimize interpolations needed so...
SimpleCollisionBox clientArea = newPacketLocation.getPossibleLocationCombined();
// In versions < 1.16.2 when the client receives non-relative teleport for an entity
// And they move less by the thresholds given, the entity does not move client side
if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_16_1)
&& Math.abs(relX - trackedServerPosition.getPos().getX()) < 0.03125D
&& Math.abs(relY - trackedServerPosition.getPos().getY()) < 0.015625D
&& Math.abs(relZ - trackedServerPosition.getPos().getZ()) < 0.03125D
&& clientArea.distanceX(relX) < 0.03125D
&& clientArea.distanceY(relY) < 0.015625D
&& clientArea.distanceZ(relZ) < 0.03125D
) {

} else {
trackedServerPosition.setPos(new Vector3d(relX, relY, relZ));
// ViaVersion desync's here for teleports
// It simply teleports the entity with its position divided by 32... ignoring the offset this causes.
// Thanks a lot ViaVersion! Please don't fix this, or it will be a pain to support.
if (player.getClientVersion().isOlderThan(ClientVersion.V_1_9)) {
trackedServerPosition.setPos(new Vector3d(((int) (relX * 32)) / 32d, ((int) (relY * 32)) / 32d, ((int) (relZ * 32)) / 32d));
}
newPacketLocation.expandNonRelative();
}
trackedServerPosition.setPos(new Vector3d(relX, relY, relZ));
// ViaVersion desync's here for teleports
// It simply teleports the entity with its position divided by 32... ignoring the offset this causes.
// Thanks a lot ViaVersion! Please don't fix this, or it will be a pain to support.
if (player.getClientVersion().isOlderThan(ClientVersion.V_1_9)) {
trackedServerPosition.setPos(new Vector3d(((int) (relX * 32)) / 32d, ((int) (relY * 32)) / 32d, ((int) (relZ * 32)) / 32d));
}
}
}
Expand Down

0 comments on commit 8e6219c

Please sign in to comment.