Skip to content

Commit

Permalink
patch keepsprint
Browse files Browse the repository at this point in the history
  • Loading branch information
ManInMyVan committed Jan 24, 2025
1 parent 31394f4 commit 7d928d5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerFlying;

public class PacketPlayerAttack extends PacketListenerAbstract {

Expand Down Expand Up @@ -58,14 +57,13 @@ public void onPacketReceive(PacketReceiveEvent event) {
// 1.8 players who are packet sprinting WILL get slowed
// 1.9+ players who are packet sprinting might not, based on attack cooldown
// Players with knockback enchantments always get slowed
if ((player.isSprinting && !hasNegativeKB && isLegacyPlayer) || hasKnockbackSword) {
player.minPlayerAttackSlow += 1;
player.maxPlayerAttackSlow += 1;
if ((player.lastSprinting && !hasNegativeKB && isLegacyPlayer) || hasKnockbackSword) {
player.minPlayerAttackSlow++;
player.maxPlayerAttackSlow++;

// Players cannot slow themselves twice in one tick without a knockback sword
if (!hasKnockbackSword) {
player.minPlayerAttackSlow = 0;
player.maxPlayerAttackSlow = 1;
player.maxPlayerAttackSlow = player.minPlayerAttackSlow = 1;
}
} else if (!isLegacyPlayer && player.isSprinting) {
// 1.9+ players who have attack speed cannot slow themselves twice in one tick because their attack cooldown gets reset on swing.
Expand All @@ -76,17 +74,10 @@ public void onPacketReceive(PacketReceiveEvent event) {
}

// 1.9+ player who might have been slowed, but we can't be sure
player.maxPlayerAttackSlow += 1;
player.maxPlayerAttackSlow++;
}
}
}
}

if (WrapperPlayClientPlayerFlying.isFlying(event.getPacketType())) {
GrimPlayer player = GrimAPI.INSTANCE.getPlayerDataManager().getPlayer(event.getUser());
if (player == null) return;

player.minPlayerAttackSlow = 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,17 @@ private void addNonEffectiveAI(GrimPlayer player, Set<VectorData> data) {
private void addAttackSlowToPossibilities(GrimPlayer player, Set<VectorData> velocities) {
for (int x = 1; x <= Math.min(player.maxPlayerAttackSlow, 5); x++) {
for (VectorData data : new HashSet<>(velocities)) {
velocities.add(data.returnNewModified(data.vector.clone().multiply(new Vector(0.6, 1, 0.6)), VectorData.VectorType.AttackSlow));
if (player.minPlayerAttackSlow > 0) {
data.vector.setX(data.vector.getX() * 0.6);
data.vector.setZ(data.vector.getZ() * 0.6);
data.addVectorType(VectorData.VectorType.AttackSlow);
} else {
velocities.add(data.returnNewModified(data.vector.clone().multiply(new Vector(0.6, 1, 0.6)), VectorData.VectorType.AttackSlow));
}
}

if (player.minPlayerAttackSlow > 0) {
player.minPlayerAttackSlow--;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ac/grim/grimac/utils/data/VectorData.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public int hashCode() {
return Objects.hash(vectorType, lastVector, preUncertainty, vector, isKnockback, firstBreadKb, isExplosion, firstBreadExplosion, isTrident, isZeroPointZeroThree, isSwimHop, isFlipSneaking, isFlipItem, isJump, isAttackSlow);
}

private void addVectorType(VectorType type) {
public void addVectorType(VectorType type) {
switch (type) {
case Knockback:
isKnockback = true;
Expand Down

0 comments on commit 7d928d5

Please sign in to comment.