summaryrefslogtreecommitdiff
path: root/src/main/java/com/arslaancodes/arslaansmagichax/modules/impl/Flight.java
blob: 538f04908f239d4e24a2768982466fb24461786e (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
55
56
57
58
59
60
61
package com.arslaancodes.arslaansmagichax.modules.impl;

import com.arslaancodes.arslaansmagichax.modules.Category;
import com.arslaancodes.arslaansmagichax.modules.Module;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
import org.lwjgl.glfw.GLFW;

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

    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.sendSystemMessage(Component.literal("[Flight] It is recommended to use this hack in combination with NoFall."));
    }

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

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

        if (flyingTickCounter >= 20) {
            if (!sentFirstPacket) {
                sendYPacket(-0.0625);
                sentFirstPacket = true;
            } else {
                sendYPacket(0);
                sentFirstPacket = false;
                flyingTickCounter = 0;
            }
        }
        flyingTickCounter++;
    }


    @Override
    protected void onDisable() {
        if (mc.player != null) {
            mc.player.getAbilities().mayfly = 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();

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

        mc.player.connection.send(packet);
    }
}