| 1 | package com.jellypudding.offlineclient.modules.movement;
|
| 2 |
|
| 3 | import com.jellypudding.offlineclient.event.Subscribe;
|
| 4 | import com.jellypudding.offlineclient.event.events.KnockbackEvent;
|
| 5 | import com.jellypudding.offlineclient.event.events.PacketReceiveEvent;
|
| 6 | import com.jellypudding.offlineclient.module.Category;
|
| 7 | import com.jellypudding.offlineclient.module.Module;
|
| 8 | import com.jellypudding.offlineclient.setting.BoolSetting;
|
| 9 | import com.jellypudding.offlineclient.setting.NumberSetting;
|
| 10 | import net.minecraft.network.protocol.game.ClientboundExplodePacket;
|
| 11 | import net.minecraft.world.phys.Vec3;
|
| 12 |
|
| 13 | import java.util.Optional;
|
| 14 |
|
| 15 | public final class NoKnockback extends Module {
|
| 16 |
|
| 17 | private final NumberSetting horizontal = new NumberSetting("Horizontal",
|
| 18 | "How much horizontal knockback to take. Over a hundred throws you further and under nought reverses it.", 0, -100, 200, 1, "%").min(-100).max(200);
|
| 19 | private final NumberSetting vertical = new NumberSetting("Vertical",
|
| 20 | "How much vertical knockback to take. Over a hundred throws you further and under nought reverses it.", 0, -100, 200, 1, "%").min(-100).max(200);
|
| 21 | private final BoolSetting separateExplosions = new BoolSetting("Separate explosions",
|
| 22 | "Give explosions their own pair of sliders.", false);
|
| 23 | private final NumberSetting explosionHorizontal = new NumberSetting("Explosion horizontal",
|
| 24 | "How much sideways push to take from explosions.", 100, -100, 200, 1, "%").min(-100).max(200)
|
| 25 | .under(separateExplosions);
|
| 26 | private final NumberSetting explosionVertical = new NumberSetting("Explosion vertical",
|
| 27 | "How much upward push to take from explosions.", 100, -100, 200, 1, "%").min(-100).max(200)
|
| 28 | .under(separateExplosions);
|
| 29 | private final BoolSetting fishingRods = new BoolSetting("Fishing rods",
|
| 30 | "A rod hooked into you cannot reel you in.", true);
|
| 31 | private final BoolSetting blockPush = new BoolSetting("Block push",
|
| 32 | "Standing inside a block no longer shoves you out.", false);
|
| 33 |
|
| 34 | public NoKnockback() {
|
| 35 | super("NoKnockback", "Reduces or removes the knockback you take.", Category.MOVEMENT);
|
| 36 | addSettings(horizontal, vertical, separateExplosions, explosionHorizontal,
|
| 37 | explosionVertical, fishingRods, blockPush);
|
| 38 | searchTags("velocity", "knockback", "antikb");
|
| 39 | }
|
| 40 |
|
| 41 | @Override
|
| 42 | public String getSuffix() {
|
| 43 | return horizontal.getInt() + "/" + vertical.getInt();
|
| 44 | }
|
| 45 |
|
| 46 | public boolean blocksFishingRods() {
|
| 47 | return isEnabled() && fishingRods.isOn();
|
| 48 | }
|
| 49 |
|
| 50 | public boolean blocksBlockPush() {
|
| 51 | return isEnabled() && blockPush.isOn();
|
| 52 | }
|
| 53 |
|
| 54 | @Subscribe
|
| 55 | private void onKnockback(KnockbackEvent event) {
|
| 56 | if (!inGame()) {
|
| 57 | return;
|
| 58 | }
|
| 59 | Vec3 current = mc.player.getDeltaMovement();
|
| 60 | double h = horizontal.getValue() / 100.0;
|
| 61 | double v = vertical.getValue() / 100.0;
|
| 62 | event.setX(current.x + (event.getX() - current.x) * h);
|
| 63 | event.setY(current.y + (event.getY() - current.y) * v);
|
| 64 | event.setZ(current.z + (event.getZ() - current.z) * h);
|
| 65 | }
|
| 66 |
|
| 67 | // Explosions push the player through their own packet instead of the usual knockback path.
|
| 68 | @Subscribe
|
| 69 | private void onPacketReceive(PacketReceiveEvent event) {
|
| 70 | if (!(event.getPacket() instanceof ClientboundExplodePacket packet)
|
| 71 | || packet.playerKnockback().isEmpty()) {
|
| 72 | return;
|
| 73 | }
|
| 74 | double h = (separateExplosions.isOn() ? explosionHorizontal : horizontal).getValue() / 100.0;
|
| 75 | double v = (separateExplosions.isOn() ? explosionVertical : vertical).getValue() / 100.0;
|
| 76 | if (h == 1 && v == 1) {
|
| 77 | return;
|
| 78 | }
|
| 79 | Vec3 push = packet.playerKnockback().get();
|
| 80 | // Scaling the packet keeps the particles and the sound.
|
| 81 | event.setPacket(new ClientboundExplodePacket(
|
| 82 | packet.center(), packet.radius(), packet.blockCount(),
|
| 83 | Optional.of(new Vec3(push.x * h, push.y * v, push.z * h)),
|
| 84 | packet.explosionParticle(), packet.explosionSound(), packet.blockParticles()));
|
| 85 | }
|
| 86 | }
|
| 87 |
|