From e41a18a7bdd02890ff919936d343afdb3017b746 Mon Sep 17 00:00:00 2001
From: c0repwn3r <core@coredoes.dev>
Date: Sat, 3 Dec 2022 20:44:24 -0500
Subject: [PATCH] rewrite jetpack

---
 .../coredoes/clientmod/modules/Jetpack.java   | 95 ++++++++++++++-----
 .../coredoes/clientmod/modules/NoFall.java    |  2 +-
 2 files changed, 70 insertions(+), 27 deletions(-)

diff --git a/src/main/java/dev/coredoes/clientmod/modules/Jetpack.java b/src/main/java/dev/coredoes/clientmod/modules/Jetpack.java
index 0a534a6..a25ab45 100644
--- a/src/main/java/dev/coredoes/clientmod/modules/Jetpack.java
+++ b/src/main/java/dev/coredoes/clientmod/modules/Jetpack.java
@@ -26,7 +26,7 @@ public class Jetpack implements Module {
 
     protected int vanillaBypassTickCounter;
     protected int vanillaBypassTickResetCounter = 0;
-    protected final int vanillaBypassResetTimeout = 7;
+    protected final int vanillaBypassResetTimeout = 5;
 
     private static KeyBinding toggleBinding;
 
@@ -51,11 +51,14 @@ public class Jetpack implements Module {
         Module.super.endTick(client);
 
         while (toggleBinding.wasPressed()) {
-            client.player.sendMessage(Text.of(String.format("[%s] Toggled!", this.getId())));
             this.isEnabled = !this.isEnabled;
+            client.player.sendMessage(Text.of(String.format("[%s] %s %s", this.getId(), (this.isEnabled) ? "Enabled" : "Disabled", this.getId())));
         }
     }
 
+    private double acceleration = 0;
+    protected double max = 10;
+
     @Override
     public void startTick(MinecraftClient client) {
         Module.super.startTick(client);
@@ -63,37 +66,56 @@ public class Jetpack implements Module {
         if (!isEnabled) return;
 
         if (client.player != null) {
-            if (vanillaBypassTickCounter > 75 && isVanillaBypassEnabled) {
-                Vec3d velocity = client.player.getVelocity();
-                this.prevVelocity = velocity.getY();
-                client.player.setVelocity(new Vec3d(velocity.getX(), -1, velocity.getZ()));
-                vanillaBypassTickCounter = -vanillaBypassResetTimeout;
-            }
-            if (vanillaBypassTickCounter == 0) {
-                vanillaBypassTickCounter++;
-                Vec3d velocity = client.player.getVelocity();
-                client.player.setVelocity(new Vec3d(velocity.getX(), this.prevVelocity, velocity.getZ()));
-            }
-            if (vanillaBypassTickCounter < 0 && isVanillaBypassEnabled) {
-                vanillaBypassTickCounter++;
+            boolean isJumping = client.options.jumpKey.isPressed();
+            boolean isSneaking = client.options.sneakKey.isPressed();
+
+            boolean isMovingForward = client.options.forwardKey.isPressed();
+            boolean isMovingLeft = client.options.leftKey.isPressed();
+            boolean isMovingRight = client.options.rightKey.isPressed();
+            boolean isMovingBack = client.options.backKey.isPressed();
+
+            if (vanillaBypassTickCounter > 75 && isVanillaBypassEnabled) { vanillaBypassTickCounter = -vanillaBypassResetTimeout; }
+            vanillaBypassTickCounter++;
+
+            Vec3d velocity = client.player.getVelocity();
+
+            if (vanillaBypassTickCounter < 0) {
+                client.player.setVelocity(new Vec3d(velocity.getX(), -0.04, velocity.getZ()));
                 return;
             }
 
-            if (client.player.input.jumping && !client.player.isOnGround()) {
-                vanillaBypassTickResetCounter = 0;
-                vanillaBypassTickCounter++;
-                Vec3d velocity = client.player.getVelocity();
+            Vec3d newVel = new Vec3d(0, 0, 0);
 
-                client.player.setVelocity(new Vec3d(velocity.getX(), velocity.getY() + upwardsVel, velocity.getZ()));
-            } else {
-                vanillaBypassTickResetCounter++;
-                if (vanillaBypassTickResetCounter > vanillaBypassResetTimeout) {
-                    vanillaBypassTickCounter = 0;
-                    vanillaBypassTickResetCounter = 0;
+            if (isJumping) {
+                newVel = new Vec3d(newVel.getX(), this.upwardsVel, newVel.getZ());
+                if (isMovingForward) {
+                    newVel = client.player.getRotationVector().multiply(acceleration);
                 }
+                if (isMovingLeft) {
+                    newVel = client.player.getRotationVector().multiply(acceleration).rotateY(3.1415927F/2);
+                    newVel = new Vec3d(newVel.getX(), 0, newVel.getZ());
+                }
+                if (isMovingRight) {
+                    newVel = client.player.getRotationVector().multiply(acceleration).rotateY(-3.1415927F/2);
+                    newVel = new Vec3d(newVel.getX(), 0, newVel.getZ());
+                }
+                if (isMovingBack) {
+                    newVel = client.player.getRotationVector().negate().multiply(acceleration);
+                }
+            } else if (isSneaking) {
+                newVel = new Vec3d(newVel.getX(), -0.5, newVel.getZ());
             }
-        }
 
+            if (isMovingForward || isMovingLeft || isMovingRight || isMovingBack) {
+                if (acceleration < max) {
+                    acceleration += 0.1;
+                }
+            } else if (acceleration > 0.2) {
+                acceleration -= 0.2;
+            }
+
+            client.player.setVelocity(newVel);
+        }
 
     }
 
@@ -159,6 +181,27 @@ public class Jetpack implements Module {
                 this.upwardsVelBtn.setMessage(Text.of("UpVel: " + df.format((this.parentModule.upwardsVel))));
             }));
 
+            this.addDrawableChild(new ButtonWidget(5, 80, 20, 20, Text.of("++"), (button) -> {
+                this.parentModule.max += 1;
+                this.upwardsVelBtn.setMessage(Text.of("MaxSpd: " + df.format((this.parentModule.max))));
+            }));
+            this.addDrawableChild(new ButtonWidget(30, 80, 20, 20, Text.of("+"), (button) -> {
+                this.parentModule.max += 0.1;
+                this.upwardsVelBtn.setMessage(Text.of("MaxSpd: " + df.format((this.parentModule.max))));
+            }));
+
+            this.upwardsVelBtn = new ButtonWidget(55, 80, 70, 20, Text.of("MaxSpd: " + df.format((this.parentModule.max))), (button) -> {});
+            this.addDrawableChild(this.upwardsVelBtn);
+
+            this.addDrawableChild(new ButtonWidget(130, 80, 20, 20, Text.of("-"), (button) -> {
+                this.parentModule.max -= 0.1;
+                this.upwardsVelBtn.setMessage(Text.of("MaxSpd: " + df.format((this.parentModule.max))));
+            }));
+            this.addDrawableChild(new ButtonWidget(155, 80, 20, 20, Text.of("--"), (button) -> {
+                this.parentModule.max -= 1;
+                this.upwardsVelBtn.setMessage(Text.of("MaxSpd: " + df.format((this.parentModule.max))));
+            }));
+
             this.addDrawableChild(new ButtonWidget(5, this.height - 25, 40, 20, ScreenTexts.BACK, (button) -> {
                 this.client.setScreen(this.parent);
             }));
diff --git a/src/main/java/dev/coredoes/clientmod/modules/NoFall.java b/src/main/java/dev/coredoes/clientmod/modules/NoFall.java
index 3607311..38695b9 100644
--- a/src/main/java/dev/coredoes/clientmod/modules/NoFall.java
+++ b/src/main/java/dev/coredoes/clientmod/modules/NoFall.java
@@ -37,8 +37,8 @@ public class NoFall implements Module {
         Module.super.endTick(client);
 
         while (toggleBinding.wasPressed()) {
-            client.player.sendMessage(Text.of(String.format("[%s] Toggled!", this.getId())));
             this.isEnabled = !this.isEnabled;
+            client.player.sendMessage(Text.of(String.format("[%s] %s %s", this.getId(), (this.isEnabled) ? "Enabled" : "Disabled", this.getId())));
         }
     }