Skip to content

Commit 7df2f4e

Browse files
committed
Stop NoClip packet spam
1 parent 38f80d2 commit 7df2f4e

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/main/java/dev/dfonline/codeclient/dev/NoClip.java

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
public class NoClip {
1616
public static LineType display = null;
17+
public static Vec3d lastPos = null;
18+
public static float lastYaw = 0;
19+
public static float lastPitch = 0;
20+
public static int timesSinceMoved = 0;
1721

1822
public static boolean isIgnoringWalls() {
1923
return CodeClient.noClipOn() && isInDevSpace();

src/main/java/dev/dfonline/codeclient/mixin/entity/player/MClientPlayerEntity.java

+24-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import static dev.dfonline.codeclient.CodeClient.MC;
2121

2222
@Mixin(ClientPlayerEntity.class)
23-
public class MClientPlayerEntity {
23+
public abstract class MClientPlayerEntity {
2424
@Shadow @Final public ClientPlayNetworkHandler networkHandler;
2525

2626
private boolean lastSneaking = false;
@@ -38,7 +38,29 @@ private void sendMovementPackets(CallbackInfo ci) {
3838
if (NoClip.isIgnoringWalls()) {
3939
ci.cancel();
4040
Vec3d pos = NoClip.handleSeverPosition();
41-
this.networkHandler.sendPacket(new PlayerMoveC2SPacket.Full(pos.x, pos.y, pos.z, player.getYaw(), player.getPitch(), false));
41+
boolean idle = NoClip.timesSinceMoved++ > 40;
42+
if(idle) NoClip.timesSinceMoved = 0;
43+
float yaw = player.getYaw();
44+
float pitch = player.getPitch();
45+
boolean rotation = pitch != NoClip.lastPitch || yaw != NoClip.lastYaw;
46+
boolean position = !pos.equals(NoClip.lastPos) || idle;
47+
if(position || rotation) {
48+
if(position) {
49+
NoClip.timesSinceMoved = 0;
50+
if(rotation) {
51+
this.networkHandler.sendPacket(new PlayerMoveC2SPacket.Full(pos.x, pos.y, pos.z, yaw, pitch, false));
52+
}
53+
else {
54+
this.networkHandler.sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(pos.x, pos.y, pos.z, false));
55+
}
56+
}
57+
else {
58+
this.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(yaw, pitch, false));
59+
}
60+
}
61+
NoClip.lastPos = pos;
62+
NoClip.lastYaw = yaw;
63+
NoClip.lastPitch = pitch;
4264
}
4365
boolean sneaking = player.isSneaking();
4466
if (sneaking != this.lastSneaking) {

0 commit comments

Comments
 (0)