77import net .minecraft .client .network .PlayerListEntry ;
88
99import java .util .Collection ;
10+ import java .util .concurrent .atomic .AtomicInteger ;
1011
1112public class _2blc implements ModInitializer {
1213 private TCPChatServer tcpServer ;
@@ -15,6 +16,13 @@ public void onInitialize() {
1516 tcpServer = new TCPChatServer (9090 );
1617 new Thread (tcpServer ).start ();
1718
19+ final int ANTI_AFK_INTERVAL_TICKS = 2 * 10 ;
20+ // Number of ticks to simulate forward movement.
21+ final int MOVE_TICKS = 5 ;
22+
23+ // Counter used to simulate holding the forward key.
24+ AtomicInteger antiAfkMoveTicks = new AtomicInteger ();
25+
1826 ClientReceiveMessageEvents .CHAT .register (
1927 ( message , signedMessage , sender , params , receptionTimestamp ) -> {
2028 String chatText = message .getString ();
@@ -59,5 +67,33 @@ public void onInitialize() {
5967 }
6068 }
6169 }).start ();
70+
71+ // Anti-AFK routine:
72+ // Every ANTI_AFK_INTERVAL_TICKS, perform a small action (jump + slight rotate)
73+ // and simulate forward movement for a few ticks to prevent the server from marking
74+ // the client as idle.
75+ ClientTickEvents .END_CLIENT_TICK .register (client -> {
76+ if (client .player != null ) {
77+ if (client .player .age % ANTI_AFK_INTERVAL_TICKS == 0 ) {
78+ client .execute (() -> {
79+ client .player .jump ();
80+ // Rotate the player's view slightly (by 10 degrees).
81+ float newYaw = client .player .getYaw () + 10.0F ;
82+ client .player .setYaw (newYaw );
83+ antiAfkMoveTicks .set (MOVE_TICKS );
84+ System .out .println ("Performed anti-AFK action (jump, rotate, and move forward)." );
85+ });
86+ }
87+
88+ if (antiAfkMoveTicks .get () > 0 ) {
89+ // Mark the forward key as pressed.
90+ client .options .forwardKey .setPressed (true );
91+ antiAfkMoveTicks .getAndDecrement ();
92+ if (antiAfkMoveTicks .get () == 0 ) {
93+ client .options .forwardKey .setPressed (false );
94+ }
95+ }
96+ }
97+ });
6298 }
6399}
0 commit comments