| 1 | package thunder.hack.utility.player;
|
| 2 |
|
| 3 | import thunder.hack.core.Managers;
|
| 4 | import thunder.hack.events.impl.EventMove;
|
| 5 | import thunder.hack.features.modules.Module;
|
| 6 | import thunder.hack.injection.accesors.IInput;
|
| 7 |
|
| 8 | import static thunder.hack.features.modules.Module.mc;
|
| 9 |
|
| 10 | import net.minecraft.util.Mth;
|
| 11 | import net.minecraft.world.effect.MobEffects;
|
| 12 | import net.minecraft.world.phys.Vec2;
|
| 13 |
|
| 14 | public final class MovementUtility {
|
| 15 | public static boolean isMoving() {
|
| 16 | return mc.player != null && mc.level != null && mc.player.input != null && (mc.player.input.getMoveVector().y != 0.0 || mc.player.input.getMoveVector().x != 0.0);
|
| 17 | }
|
| 18 |
|
| 19 | public static void setMovementInput(float x, float y) {
|
| 20 | if (mc.player == null || mc.player.input == null) return;
|
| 21 | ((IInput) mc.player.input).setMovementVector(new Vec2(x, y));
|
| 22 | }
|
| 23 |
|
| 24 | public static void clearMovementInput() {
|
| 25 | setMovementInput(0f, 0f);
|
| 26 | }
|
| 27 |
|
| 28 | public static void setMovementInputX(float x) {
|
| 29 | if (mc.player == null || mc.player.input == null) return;
|
| 30 | Vec2 movement = mc.player.input.getMoveVector();
|
| 31 | setMovementInput(x, movement.y);
|
| 32 | }
|
| 33 |
|
| 34 | public static void setMovementInputY(float y) {
|
| 35 | if (mc.player == null || mc.player.input == null) return;
|
| 36 | Vec2 movement = mc.player.input.getMoveVector();
|
| 37 | setMovementInput(movement.x, y);
|
| 38 | }
|
| 39 |
|
| 40 | public static void scaleMovementInput(float xScale, float yScale) {
|
| 41 | if (mc.player == null || mc.player.input == null) return;
|
| 42 | Vec2 movement = mc.player.input.getMoveVector();
|
| 43 | setMovementInput(movement.x * xScale, movement.y * yScale);
|
| 44 | }
|
| 45 |
|
| 46 | public static double getSpeed() {
|
| 47 | return Math.hypot(mc.player.getDeltaMovement().x, mc.player.getDeltaMovement().z);
|
| 48 | }
|
| 49 |
|
| 50 | public static double[] forward(final double d) {
|
| 51 | float f = mc.player.input.getMoveVector().y;
|
| 52 | float f2 = mc.player.input.getMoveVector().x;
|
| 53 | float f3 = mc.player.getYRot();
|
| 54 | if (f != 0.0f) {
|
| 55 | if (f2 > 0.0f) {
|
| 56 | f3 += ((f > 0.0f) ? -45 : 45);
|
| 57 | } else if (f2 < 0.0f) {
|
| 58 | f3 += ((f > 0.0f) ? 45 : -45);
|
| 59 | }
|
| 60 | f2 = 0.0f;
|
| 61 | if (f > 0.0f) {
|
| 62 | f = 1.0f;
|
| 63 | } else if (f < 0.0f) {
|
| 64 | f = -1.0f;
|
| 65 | }
|
| 66 | }
|
| 67 | final double d2 = Math.sin(Math.toRadians(f3 + 90.0f));
|
| 68 | final double d3 = Math.cos(Math.toRadians(f3 + 90.0f));
|
| 69 | final double d4 = f * d * d3 + f2 * d * d2;
|
| 70 | final double d5 = f * d * d2 - f2 * d * d3;
|
| 71 | return new double[]{d4, d5};
|
| 72 | }
|
| 73 |
|
| 74 | public static void setMotion(double speed) {
|
| 75 | double forward = mc.player.input.getMoveVector().y;
|
| 76 | double strafe = mc.player.input.getMoveVector().x;
|
| 77 | float yaw = mc.player.getYRot();
|
| 78 | if (forward == 0 && strafe == 0) {
|
| 79 | mc.player.setDeltaMovement(0, mc.player.getDeltaMovement().y, 0);
|
| 80 | } else {
|
| 81 | if (forward != 0) {
|
| 82 | if (strafe > 0) {
|
| 83 | yaw += (float) (forward > 0 ? -45 : 45);
|
| 84 | } else if (strafe < 0) {
|
| 85 | yaw += (float) (forward > 0 ? 45 : -45);
|
| 86 | }
|
| 87 | strafe = 0;
|
| 88 | if (forward > 0) {
|
| 89 | forward = 1;
|
| 90 | } else if (forward < 0) {
|
| 91 | forward = -1;
|
| 92 | }
|
| 93 | }
|
| 94 | double sin = Mth.sin((float) Math.toRadians(yaw + 90));
|
| 95 | double cos = Mth.cos((float) Math.toRadians(yaw + 90));
|
| 96 | mc.player.setDeltaMovement(forward * speed * cos + strafe * speed * sin, mc.player.getDeltaMovement().y, forward * speed * sin - strafe * speed * cos);
|
| 97 | }
|
| 98 | }
|
| 99 |
|
| 100 | public static float getMoveDirection() {
|
| 101 | double forward = mc.player.input.getMoveVector().y;
|
| 102 | double strafe = mc.player.input.getMoveVector().x;
|
| 103 |
|
| 104 | if (strafe > 0) {
|
| 105 | strafe = 1;
|
| 106 | } else if (strafe < 0) {
|
| 107 | strafe = -1;
|
| 108 | }
|
| 109 |
|
| 110 | float yaw = mc.player.getYRot();
|
| 111 | if (forward == 0 && strafe == 0) {
|
| 112 | return yaw;
|
| 113 | } else {
|
| 114 | if (forward != 0) {
|
| 115 | if (strafe > 0)
|
| 116 | yaw += forward > 0 ? -45f : -135f;
|
| 117 | else if (strafe < 0)
|
| 118 | yaw += forward > 0 ? 45f : 135f;
|
| 119 | else if (forward < 0) {
|
| 120 | yaw += 180f;
|
| 121 | }
|
| 122 | }
|
| 123 | if (forward == 0) {
|
| 124 | if (strafe > 0)
|
| 125 | yaw -= 90f;
|
| 126 | else if (strafe < 0)
|
| 127 | yaw += 90f;
|
| 128 | }
|
| 129 | }
|
| 130 |
|
| 131 | return yaw;
|
| 132 | }
|
| 133 |
|
| 134 | public static double[] forwardWithoutStrafe(final double d) {
|
| 135 | float f3 = mc.player.getYRot();
|
| 136 | final double d4 = d * Math.cos(Math.toRadians(f3 + 90.0f));
|
| 137 | final double d5 = d * Math.sin(Math.toRadians(f3 + 90.0f));
|
| 138 | return new double[]{d4, d5};
|
| 139 | }
|
| 140 |
|
| 141 | public static double getJumpSpeed() {
|
| 142 | double jumpSpeed = 0.3999999463558197;
|
| 143 | if (mc.player.hasEffect(MobEffects.JUMP_BOOST)) {
|
| 144 | double amplifier = mc.player.getEffect(MobEffects.JUMP_BOOST).getAmplifier();
|
| 145 | jumpSpeed += (amplifier + 1) * 0.1;
|
| 146 | }
|
| 147 | return jumpSpeed;
|
| 148 | }
|
| 149 |
|
| 150 | public static void modifyEventSpeed(EventMove event, double d) {
|
| 151 | double d2 = mc.player.input.getMoveVector().y;
|
| 152 | double d3 = mc.player.input.getMoveVector().x;
|
| 153 | float f = mc.player.getYRot();
|
| 154 | if (d2 == 0.0 && d3 == 0.0) {
|
| 155 | event.setX(0.0);
|
| 156 | event.setZ(0.0);
|
| 157 | } else {
|
| 158 | if (d2 != 0.0) {
|
| 159 | if (d3 > 0.0) {
|
| 160 | f += (float) (d2 > 0.0 ? -45 : 45);
|
| 161 | } else if (d3 < 0.0) {
|
| 162 | f += (float) (d2 > 0.0 ? 45 : -45);
|
| 163 | }
|
| 164 |
|
| 165 | d3 = 0.0;
|
| 166 | if (d2 > 0.0) {
|
| 167 | d2 = 1.0;
|
| 168 | } else if (d2 < 0.0) {
|
| 169 | d2 = -1.0;
|
| 170 | }
|
| 171 | }
|
| 172 | double sin = Math.sin(Math.toRadians(f + 90.0F));
|
| 173 | double cos = Math.cos(Math.toRadians(f + 90.0F));
|
| 174 |
|
| 175 | event.setX(d2 * d * cos + d3 * d * sin);
|
| 176 | event.setZ(d2 * d * sin - d3 * d * cos);
|
| 177 | }
|
| 178 | }
|
| 179 |
|
| 180 | public static double getBaseMoveSpeed() {
|
| 181 | int n;
|
| 182 | double d = 0.2873;
|
| 183 |
|
| 184 | if (Module.fullNullCheck()) return d;
|
| 185 |
|
| 186 | if (mc.player.hasEffect(MobEffects.SPEED)) {
|
| 187 | n = mc.player.getEffect(MobEffects.SPEED).getAmplifier();
|
| 188 | d *= 1.0 + 0.2 * (n + 1);
|
| 189 | }
|
| 190 | if (mc.player.hasEffect(MobEffects.JUMP_BOOST)) {
|
| 191 | n = mc.player.getEffect(MobEffects.JUMP_BOOST).getAmplifier();
|
| 192 | d /= 1.0 + 0.2 * (n + 1);
|
| 193 | }
|
| 194 | if (mc.player.hasEffect(MobEffects.SLOWNESS)) {
|
| 195 | n = mc.player.getEffect(MobEffects.SLOWNESS).getAmplifier();
|
| 196 | d /= 1.0 + (0.2 * (n + 1));
|
| 197 | }
|
| 198 | return d;
|
| 199 | }
|
| 200 |
|
| 201 | public static boolean sprintIsLegit(float yaw) {
|
| 202 | return (Math.abs(Math.abs(Mth.wrapDegrees(yaw)) - Math.abs(Mth.wrapDegrees(Managers.PLAYER.yaw))) < 40);
|
| 203 | }
|
| 204 | }
|
| 205 |
|