Skip to content

Commit 4d28f85

Browse files
committed
More setback changes
1 parent 0d22e34 commit 4d28f85

File tree

6 files changed

+38
-8
lines changed

6 files changed

+38
-8
lines changed

common/src/main/java/ac/grim/grimac/events/packets/PacketPlayerRespawn.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public void onPacketSend(PacketSendEvent event) {
212212
player.clientVelocity = new Vector3dm();
213213
if (!GrimAPI.INSTANCE.getSpectateManager().isSpectating(player.uuid)) {
214214
player.gamemode = respawn.getGameMode();
215-
}
215+
}
216216
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_17)) {
217217
player.compensatedWorld.setDimension(respawn.getDimensionType(), event.getUser());
218218
}

common/src/main/java/ac/grim/grimac/manager/SetbackTeleportUtil.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import lombok.AllArgsConstructor;
4141
import lombok.Getter;
4242
import lombok.Setter;
43+
import org.jetbrains.annotations.Nullable;
4344

4445
import java.util.Collections;
4546
import java.util.HashSet;
@@ -217,7 +218,7 @@ private void blockMovementsUntilResync(boolean simulateNextTickPosition, boolean
217218
blockOffsets = true;
218219
}
219220

220-
SetBackData data = new SetBackData(new TeleportData(position, new Vector3d(), RelativeFlag.YAW.or(RelativeFlag.PITCH), player.lastTransactionSent.get(), 0), player.yaw, player.pitch, clientVel, player.inVehicle(), false);
221+
SetBackData data = new SetBackData(new TeleportData(position, null, RelativeFlag.YAW.or(RelativeFlag.PITCH), player.lastTransactionSent.get(), 0), player.yaw, player.pitch, clientVel, player.inVehicle(), false);
221222
sendSetback(data);
222223
}
223224

@@ -269,7 +270,8 @@ private void sendSetback(SetBackData data) {
269270
data.getTeleportData().setTransaction(player.lastTransactionSent.get());
270271

271272
// Use provided transaction ID to make sure it can never desync, although there's no reason to do this
272-
addSentTeleport(new Location(null, position.getX(), y, position.getZ(), player.yaw % 360, player.pitch % 360), new Vector3d(), data.getTeleportData().getTransaction(), new RelativeFlag(0b11000), false, teleportId);
273+
addSentTeleport(new Location(null, position.getX(), y, position.getZ(), player.yaw % 360, player.pitch % 360),
274+
null, data.getTeleportData().getTransaction(), RelativeFlag.YAW.or(RelativeFlag.PITCH), false, teleportId);
273275
// This must be done after setting the sent teleport, otherwise we lose velocity data
274276
requiredSetBack = data;
275277
// Send after tracking to fix race condition
@@ -405,7 +407,12 @@ public boolean insideUnloadedChunk() {
405407
!player.getSetbackTeleportUtil().hasAcceptedSpawnTeleport);
406408
}
407409

408-
public void addSentTeleport(Location position, Vector3d velocity, int transaction, RelativeFlag flags, boolean plugin, int teleportId) {
410+
public void addSentTeleport(Location position, @Nullable Vector3d velocity, int transaction, RelativeFlag flags, boolean plugin, int teleportId) {
411+
// Clients below 1.21.2 do not have this.
412+
if (player.getClientVersion().isOlderThan(ClientVersion.V_1_21_2)) {
413+
velocity = null;
414+
}
415+
409416
TeleportData data = new TeleportData(new Vector3d(position.getX(), position.getY(), position.getZ()), velocity, flags, transaction, teleportId);
410417
pendingTeleports.add(data);
411418

@@ -424,7 +431,7 @@ public void addSentTeleport(Location position, Vector3d velocity, int transactio
424431
safePosition = safePosition.withZ(safePosition.getZ() + lastKnownGoodPosition.pos.getZ());
425432
}
426433

427-
data = new TeleportData(safePosition, velocity, new RelativeFlag(0b11000), transaction, teleportId);
434+
data = new TeleportData(safePosition, velocity, RelativeFlag.YAW.or(RelativeFlag.PITCH), transaction, teleportId);
428435
requiredSetBack = new SetBackData(data, player.yaw, player.pitch, null, false, plugin);
429436

430437
this.lastKnownGoodPosition = new SetbackPosWithVector(safePosition, new Vector3dm());

common/src/main/java/ac/grim/grimac/predictionengine/MovementCheckRunner.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import ac.grim.grimac.utils.anticheat.update.PositionUpdate;
1919
import ac.grim.grimac.utils.anticheat.update.PredictionComplete;
2020
import ac.grim.grimac.utils.collisions.datatypes.SimpleCollisionBox;
21+
import ac.grim.grimac.utils.data.SetBackData;
2122
import ac.grim.grimac.utils.data.VectorData;
2223
import ac.grim.grimac.utils.data.packetentity.PacketEntity;
2324
import ac.grim.grimac.utils.data.packetentity.PacketEntityCamel;
@@ -107,7 +108,15 @@ private void handleTeleport(PositionUpdate update) {
107108
player.lastWasClimbing = 0; // Vertical movement reset
108109
player.canSwimHop = false; // Vertical movement reset
109110
} else {
110-
update.getTeleportData().modifyVector(player, player.clientVelocity);
111+
final SetBackData setback = update.getSetback();
112+
if (setback == null || setback.getVelocity() == null) {
113+
update.getTeleportData().modifyVector(player, player.clientVelocity);
114+
} else {
115+
// Enforce setback velocity?
116+
player.clientVelocity.setX(setback.getVelocity().getX());
117+
player.clientVelocity.setY(setback.getVelocity().getY());
118+
player.clientVelocity.setZ(setback.getVelocity().getZ());
119+
}
111120
}
112121
}
113122

@@ -599,7 +608,10 @@ private void check(PositionUpdate update) {
599608
player.riptideSpinAttackTicks = 20;
600609

601610
player.uncertaintyHandler.lastMovementWasZeroPointZeroThree = !player.inVehicle() && player.skippedTickInActualMovement;
602-
player.uncertaintyHandler.lastMovementWasUnknown003VectorReset = !player.inVehicle() && player.couldSkipTick && player.predictedVelocity.isKnockback();
611+
player.uncertaintyHandler.lastMovementWasUnknown003VectorReset = !player.inVehicle() && player.couldSkipTick
612+
&& player.predictedVelocity.isKnockback()
613+
// Don't let setbacks count
614+
&& !player.predictedVelocity.isSetbackKb(player);
603615
player.couldSkipTick = false;
604616

605617
// Logic is if the player was directly 0.03 and the player could control vertical movement in 0.03

common/src/main/java/ac/grim/grimac/predictionengine/UncertaintyHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public void tickFireworksBox() {
211211
public double getOffsetHorizontal(VectorData data) {
212212
double threshold = player.getMovementThreshold();
213213

214-
boolean newVectorPointThree = player.couldSkipTick && data.isKnockback();
214+
boolean newVectorPointThree = player.couldSkipTick && data.isKnockback() && !data.isSetbackKb(player);
215215
boolean explicit003 = data.isZeroPointZeroThree() || lastMovementWasZeroPointZeroThree;
216216
boolean either003 = newVectorPointThree || explicit003;
217217

common/src/main/java/ac/grim/grimac/utils/data/TeleportData.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
import lombok.Getter;
99
import lombok.Setter;
1010
import org.jetbrains.annotations.NotNull;
11+
import org.jetbrains.annotations.Nullable;
1112

1213
@AllArgsConstructor
1314
@Getter
1415
public class TeleportData {
1516
private final Vector3d location;
17+
@Nullable
1618
private final Vector3d velocity;
1719
private final RelativeFlag flags;
1820
@Setter

common/src/main/java/ac/grim/grimac/utils/data/VectorData.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ac.grim.grimac.utils.data;
22

3+
import ac.grim.grimac.player.GrimPlayer;
34
import ac.grim.grimac.utils.math.Vector3dm;
45
import lombok.Getter;
56
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@@ -55,6 +56,14 @@ public VectorData returnNewModified(Vector3dm newVec, VectorType type) {
5556
return new VectorData(newVec, this, type);
5657
}
5758

59+
public boolean isSetbackKb(GrimPlayer player) {
60+
if (!isKnockback) {
61+
return false;
62+
}
63+
64+
return (firstBreadKb ? player.firstBreadKB : player.likelyKB).isSetback;
65+
}
66+
5867
@Override
5968
public boolean equals(Object o) {
6069
if (this == o) return true;

0 commit comments

Comments
 (0)