summaryrefslogtreecommitdiff
path: root/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/modules/impl/Flight.java
blob: 5c95e1efdb7d69cbc9edbf75315966a35c4729a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package net.justlearning.arslaan3102.arslaansmagichax.modules.impl;

import net.justlearning.arslaan3102.arslaansmagichax.modules.Category;
import net.justlearning.arslaan3102.arslaansmagichax.modules.Module;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;

public class Flight extends Module {
    private int flyingTickCounter = 0;

    public Flight() {
        super("Flight", "Enables creative flight in survival.", GLFW.GLFW_KEY_G, Category.MOVEMENT);
    }

    @Override
    protected void onEnable() {
        if (mc.player == null) return;
        mc.player.sendMessage(Text.literal("[Flight] It is recommended to use this hack in combination with NoFall."), false);
    }

    @Override
    public void tick() {
        if (!this.isEnabled() || mc.player == null) return;

        mc.player.getAbilities().allowFlying = true;
        mc.player.getAbilities().flying = true;

        if (flyingTickCounter >= 20) {
            sendYPacket(-0.0625);
            sendYPacket(0);
            flyingTickCounter = 0;
        }
        flyingTickCounter++;
    }

    @Override
    protected void onDisable() {
        if (mc.player != null) {
            mc.player.getAbilities().allowFlying = false;
            mc.player.getAbilities().flying = false;
        }
    }

    private static void sendYPacket(double height) {
        double x = mc.player.getX();
        double y = mc.player.getY();
        double z = mc.player.getZ();

        PlayerMoveC2SPacket packet = new PlayerMoveC2SPacket.PositionAndOnGround(x, y + height, z, false, mc.player.horizontalCollision);

        mc.player.networkHandler.sendPacket(packet);
    }
}