33import net .fabricmc .fabric .api .client .keybinding .v1 .KeyBindingHelper ;
44import net .minecraft .client .MinecraftClient ;
55import net .minecraft .client .network .ClientPlayNetworkHandler ;
6- import net .minecraft .client .option .GameOptions ;
76import net .minecraft .client .option .KeyBinding ;
7+ import net .minecraft .entity .Entity ;
88import net .minecraft .entity .player .PlayerEntity ;
99import net .minecraft .network .Packet ;
1010import net .minecraft .network .packet .c2s .play .PlayerInteractEntityC2SPacket ;
@@ -28,26 +28,31 @@ public class Keybinds {
2828 public static ClientPlayNetworkHandler networkHandler ;
2929
3030 private static final KeyBinding worldGuardBypassToggle = new KeyBinding ("key.liveoverflowmod.worldguardbypass_toggle" ,
31- GLFW .GLFW_KEY_SEMICOLON , LIVEOVERFLOW_CATEGORY ); // Bypass WorldGuard region protection
31+ GLFW .GLFW_KEY_SEMICOLON , LIVEOVERFLOW_CATEGORY ); // Bypass WorldGuard region protection
3232 private static final KeyBinding reachKeybind = new KeyBinding ("key.liveoverflowmod.reach" ,
3333 GLFW .GLFW_KEY_BACKSLASH , LIVEOVERFLOW_CATEGORY ); // Hit the nearest player from far away
3434 private static final KeyBinding panicKeybind = new KeyBinding ("key.liveoverflowmod.panic" ,
3535 GLFW .GLFW_KEY_COMMA , LIVEOVERFLOW_CATEGORY ); // Fly up as fast as possible
36+ private static final KeyBinding modToggle = new KeyBinding ("key.liveoverflowmod.passive_toggle" ,
37+ GLFW .GLFW_KEY_MINUS , LIVEOVERFLOW_CATEGORY ); // Toggle passive mods on/off
3638
3739 public static LinkedList <Packet <?>> packetQueue = new LinkedList <>();
3840 public static boolean worldGuardBypassEnabled = false ;
41+ public static boolean passiveModsEnabled = true ;
3942 public static boolean needsHitPacket = false ;
43+ public static int flyingTimer = 0 ;
4044 public static int panicTimer = 0 ;
41- public static PlayerEntity targetPlayer ;
45+ public static Entity reachTarget ;
4246 public static Vec3d virtualPosition ;
4347
4448 public static void registerKeybinds () {
4549 KeyBindingHelper .registerKeyBinding (worldGuardBypassToggle );
4650 KeyBindingHelper .registerKeyBinding (reachKeybind );
4751 KeyBindingHelper .registerKeyBinding (panicKeybind );
52+ KeyBindingHelper .registerKeyBinding (modToggle );
4853 }
4954
50- public static PlayerEntity getClosestPlayer () {
55+ public static Entity getClosestPlayer () {
5156 if (mc .player == null || mc .world == null ) {
5257 return null ;
5358 }
@@ -79,9 +84,19 @@ public static <T> void addToMiddle(LinkedList<T> list, T object) {
7984
8085 public static void checkKeybinds (MinecraftClient client ) {
8186 networkHandler = client .getNetworkHandler ();
82- if (client .player != null && client .world != null && networkHandler != null ) {
87+ if (client .player != null && client .world != null && networkHandler != null && client .interactionManager != null ) {
88+ while (modToggle .wasPressed ()) { // Toggle whole mod
89+ passiveModsEnabled = !passiveModsEnabled ;
90+ if (passiveModsEnabled ) {
91+ client .player .sendMessage (Text .of ("§7[LiveOverflowMod] §aEnabled" ), false );
92+ } else {
93+ client .player .sendMessage (Text .of ("§7[LiveOverflowMod] §cDisabled" ), false );
94+ }
95+ }
96+
8397 // Toggle WorldGuard Bypass
8498 while (worldGuardBypassToggle .wasPressed ()) {
99+ flyingTimer = 0 ;
85100 if (worldGuardBypassEnabled ) {
86101 worldGuardBypassEnabled = false ;
87102 client .player .sendMessage (Text .of ("§7[LiveOverflowMod] §rWorldGuard Bypass: §cDisabled" ), false );
@@ -93,65 +108,71 @@ public static void checkKeybinds(MinecraftClient client) {
93108
94109 // WorldGuard bypass
95110 if (worldGuardBypassEnabled ) {
96- client .player .setVelocity (0 , 0 , 0 );
97-
98- Vec3d vec = new Vec3d (0 , 0 , 0 );
99-
100- // Key presses changing position
101- if (client .player .input .jumping ) { // Move up
102- vec = vec .add (new Vec3d (0 , 1 , 0 ));
103- } else if (client .player .input .sneaking ) { // Move down
104- vec = vec .add (new Vec3d (0 , -1 , 0 ));
111+ if (++flyingTimer > 30 ) { // Max 80, to bypass "Flying is not enabled"
112+ networkHandler .sendPacket (new PlayerMoveC2SPacket .PositionAndOnGround (client .player .getX (),
113+ client .player .getY () - 0.04 , client .player .getZ (), client .player .isOnGround ()));
114+ flyingTimer = 0 ; // Reset
105115 } else {
106- // Horizontal movement (not at the same time as vertical)
107- if (client .player .input .pressingForward ) {
108- vec = vec .add (new Vec3d (0 , 0 , 1 ));
109- }
110- if (client .player .input .pressingRight ) {
111- vec = vec .add (new Vec3d (1 , 0 , 0 ));
112- }
113- if (client .player .input .pressingBack ) {
114- vec = vec .add (new Vec3d (0 , 0 , -1 ));
115- }
116- if (client .player .input .pressingLeft ) {
117- vec = vec .add (new Vec3d (-1 , 0 , 0 ));
116+ client .player .setVelocity (0 , 0 , 0 );
117+
118+ Vec3d vec = new Vec3d (0 , 0 , 0 );
119+
120+ // Key presses changing position
121+ if (client .player .input .jumping ) { // Move up
122+ vec = vec .add (new Vec3d (0 , 1 , 0 ));
123+ } else if (client .player .input .sneaking ) { // Move down
124+ vec = vec .add (new Vec3d (0 , -1 , 0 ));
125+ } else {
126+ // Horizontal movement (not at the same time as vertical)
127+ if (client .player .input .pressingForward ) {
128+ vec = vec .add (new Vec3d (0 , 0 , 1 ));
129+ }
130+ if (client .player .input .pressingRight ) {
131+ vec = vec .add (new Vec3d (1 , 0 , 0 ));
132+ }
133+ if (client .player .input .pressingBack ) {
134+ vec = vec .add (new Vec3d (0 , 0 , -1 ));
135+ }
136+ if (client .player .input .pressingLeft ) {
137+ vec = vec .add (new Vec3d (-1 , 0 , 0 ));
138+ }
118139 }
119- }
120140
121- if (vec .length () > 0 ) {
122- vec = vec .normalize (); // Normalize to length 1
141+ if (vec .length () > 0 ) {
142+ vec = vec .normalize (); // Normalize to length 1
123143
124- if (!(vec .x == 0 && vec .z == 0 )) { // Rotate by looking yaw (won't change length)
125- double moveAngle = Math .atan2 (vec .x , vec .z ) + Math .toRadians (client .player .getYaw () + 90 );
126- double x = Math .cos (moveAngle );
127- double z = Math .sin (moveAngle );
128- vec = new Vec3d (x , vec .y , z );
129- }
144+ if (!(vec .x == 0 && vec .z == 0 )) { // Rotate by looking yaw (won't change length)
145+ double moveAngle = Math .atan2 (vec .x , vec .z ) + Math .toRadians (client .player .getYaw () + 90 );
146+ double x = Math .cos (moveAngle );
147+ double z = Math .sin (moveAngle );
148+ vec = new Vec3d (x , vec .y , z );
149+ }
130150
131- vec = vec .multiply (MAX_DELTA ); // Scale to maxDelta
151+ vec = vec .multiply (MAX_DELTA ); // Scale to maxDelta
132152
133- Vec3d newPos = new Vec3d (client .player .getX () + vec .x , client .player .getY () + vec .y , client .player .getZ () + vec .z );
134- // If able to add more without going over a block boundary, add more
135- boolean extra = false ;
136- if (client .options .sprintKey .isPressed ()) { // Trigger by sprinting
137- while (inSameBlock (newPos .add (vec .multiply (1.5 )), new Vec3d (client .player .prevX , client .player .prevY , client .player .prevZ ))) {
138- newPos = newPos .add (vec );
139- extra = true ;
153+ Vec3d newPos = new Vec3d (client .player .getX () + vec .x , client .player .getY () + vec .y , client .player .getZ () + vec .z );
154+ // If able to add more without going over a block boundary, add more
155+ boolean extra = false ;
156+ if (client .options .sprintKey .isPressed ()) { // Trigger by sprinting
157+ while (inSameBlock (newPos .add (vec .multiply (1.5 )), new Vec3d (client .player .prevX , client .player .prevY , client .player .prevZ ))) {
158+ newPos = newPos .add (vec );
159+ extra = true ;
160+ }
140161 }
141- }
142162
143- client .player .setPosition (newPos );
163+ client .player .setPosition (newPos );
144164
145- // Send tiny movement so delta is small enough
146- PlayerMoveC2SPacket .Full smallMovePacket = new PlayerMoveC2SPacket .Full (client .player .getX (), client .player .getY (),
147- client .player .getZ (), client .player .getYaw (), client .player .getPitch (), client .player .isOnGround ());
148- networkHandler .getConnection ().send (smallMovePacket );
165+ // Send tiny movement so delta is small enough
166+ PlayerMoveC2SPacket .Full smallMovePacket = new PlayerMoveC2SPacket .Full (client .player .getX (), client .player .getY (),
167+ client .player .getZ (), client .player .getYaw (), client .player .getPitch (), client .player .isOnGround ());
168+ networkHandler .getConnection ().send (smallMovePacket );
149169
150- // Send far away packet for "moving too quickly!" to reset position
151- if (!extra ) {
152- PlayerMoveC2SPacket .Full farPacket = new PlayerMoveC2SPacket .Full (client .player .getX () + 1337.0 , client .player .getY () + 1337.0 ,
153- client .player .getZ () + 1337.0 , client .player .getYaw (), client .player .getPitch (), client .player .isOnGround ());
154- networkHandler .getConnection ().send (farPacket );
170+ // Send far away packet for "moving too quickly!" to reset position
171+ if (!extra ) {
172+ PlayerMoveC2SPacket .Full farPacket = new PlayerMoveC2SPacket .Full (client .player .getX () + 1337.0 , client .player .getY () + 1337.0 ,
173+ client .player .getZ () + 1337.0 , client .player .getYaw (), client .player .getPitch (), client .player .isOnGround ());
174+ networkHandler .getConnection ().send (farPacket );
175+ }
155176 }
156177 }
157178 }
@@ -161,16 +182,16 @@ public static void checkKeybinds(MinecraftClient client) {
161182 if (packetQueue .size () > 0 ) {
162183 break ; // Already running
163184 }
164- targetPlayer = getClosestPlayer ();
165- if (targetPlayer != null ) {
166- client .player .sendMessage (Text .of ("§7[LiveOverflowMod] §rReach: §a" + targetPlayer .getEntityName ()), false );
185+ reachTarget = getClosestPlayer ();
186+ if (reachTarget != null ) {
187+ client .player .sendMessage (Text .of ("§7[LiveOverflowMod] §rReach: §a" + reachTarget .getEntityName ()), false );
167188 needsHitPacket = true ;
168189 virtualPosition = client .player .getPos ();
169190 // Move close enough to player
170191 for (int i = 0 ; i < 5 ; i ++) { // Max 5 packets per tick
171192 // If player is too far away, move closer
172- if (targetPlayer .squaredDistanceTo (virtualPosition .add (0 , client .player .getStandingEyeHeight (), 0 )) >= MAX_BREAK_SQUARED_DISTANCE ) {
173- Vec3d movementNeeded = targetPlayer .getPos ().subtract (virtualPosition );
193+ if (reachTarget .squaredDistanceTo (virtualPosition .add (0 , client .player .getStandingEyeHeight (), 0 )) >= MAX_BREAK_SQUARED_DISTANCE ) {
194+ Vec3d movementNeeded = reachTarget .getPos ().subtract (virtualPosition );
174195 double length = movementNeeded .lengthSquared ();
175196
176197 LOGGER .info (String .format ("Movement needed: %s (%f)" , movementNeeded , length ));
@@ -191,10 +212,10 @@ public static void checkKeybinds(MinecraftClient client) {
191212 }
192213 }
193214 // Add hit packet and back to original position
194- addToMiddle (packetQueue , PlayerInteractEntityC2SPacket .attack (targetPlayer , client .player .isSneaking ()));
215+ addToMiddle (packetQueue , PlayerInteractEntityC2SPacket .attack (reachTarget , client .player .isSneaking ()));
195216 packetQueue .add (new PlayerMoveC2SPacket .PositionAndOnGround (client .player .getX (), client .player .getY (), client .player .getZ (), true ));
196217 } else {
197- client .player .sendMessage (Text .of ("§7[LiveOverflowMod] §rReach: §cNo players found" ), false );
218+ client .player .sendMessage (Text .of ("§7[LiveOverflowMod] §rReach: §cNo targets found" ), false );
198219 }
199220 }
200221
@@ -228,4 +249,3 @@ public static void checkKeybinds(MinecraftClient client) {
228249 }
229250 }
230251}
231-
0 commit comments