MiddleClickExtra module

MiddleClickExtra: Minecraft 26.3 cheat module, full source for every implementation (1 client: OfflineClient).

1 implementationPLAYER

Clients with this module

Full module source: 1 implementation

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

OfflineClientPLAYERsrc/main/java/com/jellypudding/offlineclient/modules/player/MiddleClickExtra.javaJava · 200 lines · 7.6 KB

Does something useful on a middle click.

SettingsModeNotifySend messageMessageQuick swapSwap backWarn when missingSkip in creative
MiddleClickExtra.javaJava · Minecraft 26.2 · 200 lines · 7.6 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.player;
2
3
import com.jellypudding.offlineclient.OfflineClient;
4
import com.jellypudding.offlineclient.event.Subscribe;
5
import com.jellypudding.offlineclient.event.events.TickEvent;
6
import com.jellypudding.offlineclient.friend.FriendManager;
7
import com.jellypudding.offlineclient.module.Category;
8
import com.jellypudding.offlineclient.module.Module;
9
import com.jellypudding.offlineclient.setting.BoolSetting;
10
import com.jellypudding.offlineclient.setting.EnumSetting;
11
import com.jellypudding.offlineclient.setting.TextSetting;
12
import com.jellypudding.offlineclient.util.ChatUtil;
13
import com.jellypudding.offlineclient.util.InputUtil;
14
import com.jellypudding.offlineclient.util.InventoryUtil;
15
import com.jellypudding.offlineclient.util.InventoryUtil.HotbarLoan;
16
import com.jellypudding.offlineclient.util.UseHold;
17
import net.minecraft.world.InteractionHand;
18
import net.minecraft.world.entity.player.Player;
19
import net.minecraft.world.item.BowItem;
20
import net.minecraft.world.item.Item;
21
import net.minecraft.world.item.Items;
22
import net.minecraft.world.level.GameType;
23
24
import java.util.Locale;
25
26
public final class MiddleClickExtra extends Module {
27
28
    // The item a mode reaches for. Held modes keep the use key down until the use ends.
29
    public enum Mode {
30
        ADD_FRIEND(null, false),
31
        PEARL(Items.ENDER_PEARL, false),
32
        EXPERIENCE(Items.EXPERIENCE_BOTTLE, false),
33
        ROCKET(Items.FIREWORK_ROCKET, false),
34
        WIND_CHARGE(Items.WIND_CHARGE, false),
35
        BOW(Items.BOW, true),
36
        GOLDEN_APPLE(Items.GOLDEN_APPLE, true),
37
        ENCHANTED_APPLE(Items.ENCHANTED_GOLDEN_APPLE, true),
38
        CHORUS_FRUIT(Items.CHORUS_FRUIT, true);
39
40
        private final Item item;
41
        private final boolean held;
42
43
        Mode(Item item, boolean held) {
44
            this.item = item;
45
            this.held = held;
46
        }
47
    }
48
49
    private static final String NAME_TOKEN = "%player";
50
51
    private final EnumSetting<Mode> mode = new EnumSetting<>("Mode",
52
        "What a middle click does.", Mode.ADD_FRIEND)
53
        .describe(Mode.ADD_FRIEND, "Toggles the player under the crosshair as a friend.")
54
        .describe(Mode.PEARL, "Throws an ender pearl.")
55
        .describe(Mode.EXPERIENCE, "Throws a bottle of enchanting.")
56
        .describe(Mode.ROCKET, "Uses a firework rocket.")
57
        .describe(Mode.WIND_CHARGE, "Throws a wind charge.")
58
        .describe(Mode.BOW, "Draws a bow fully and fires it.")
59
        .describe(Mode.GOLDEN_APPLE, "Eats a golden apple.")
60
        .describe(Mode.ENCHANTED_APPLE, "Eats an enchanted golden apple.")
61
        .describe(Mode.CHORUS_FRUIT, "Eats a chorus fruit.");
62
    private final BoolSetting notify = new BoolSetting("Notify",
63
        "Say in chat who was added or removed.", true).under(mode, Mode.ADD_FRIEND);
64
    private final BoolSetting sendMessage = new BoolSetting("Send message",
65
        "Sends a chat message to the player you add.", false).under(mode, Mode.ADD_FRIEND);
66
    private final TextSetting message = new TextSetting("Message",
67
        "The message to send. The word %player becomes their name.",
68
        "/msg %player I have added you as a friend.").under(sendMessage);
69
    private final BoolSetting quickSwap = new BoolSetting("Quick swap",
70
        "Also reaches into the main inventory by swapping the item into the hotbar and back.",
71
        false).under(mode, () -> !mode.is(Mode.ADD_FRIEND));
72
    private final BoolSetting swapBack = new BoolSetting("Swap back",
73
        "Returns to the slot you had once the item is used.", false)
74
        .under(mode, () -> !mode.is(Mode.ADD_FRIEND));
75
    private final BoolSetting warnMissing = new BoolSetting("Warn when missing",
76
        "Says in chat when the item cannot be found.", true)
77
        .under(mode, () -> !mode.is(Mode.ADD_FRIEND));
78
    private final BoolSetting skipCreative = new BoolSetting("Skip in creative",
79
        "Does nothing in creative so pick block works as normal.", true);
80
81
    private final HotbarLoan loan = new HotbarLoan();
82
    private final UseHold hold = new UseHold();
83
    private boolean using;
84
85
    public MiddleClickExtra() {
86
        super("MiddleClickExtra", "Does something useful on a middle click.", Category.PLAYER);
87
        addSettings(mode, notify, sendMessage, message, quickSwap, swapBack, warnMissing,
88
            skipCreative);
89
        searchTags("friend", "add friend", "middle click pearl", "middle click bow");
90
    }
91
92
    @Override
93
    public String getSuffix() {
94
        return mode.getValueString();
95
    }
96
97
    @Override
98
    protected void onDisable() {
99
        if (using) {
100
            finish(false);
101
        }
102
    }
103
104
    // Called from the mouse mixin on every middle click press.
105
    public void onMiddleClick() {
106
        if (!isEnabled() || !inGame() || mc.gui.screen() != null || using) {
107
            return;
108
        }
109
        if (skipCreative.isOn() && mc.player.gameMode() == GameType.CREATIVE) {
110
            return;
111
        }
112
        if (mode.is(Mode.ADD_FRIEND)) {
113
            toggleFriend();
114
        } else {
115
            useItem(mode.getValue());
116
        }
117
    }
118
119
    private void toggleFriend() {
120
        if (!(mc.crosshairPickEntity instanceof Player player) || player == mc.player) {
121
            return;
122
        }
123
        String name = player.getGameProfile().name();
124
        FriendManager friends = OfflineClient.INSTANCE.getFriendManager();
125
        boolean added = !friends.isFriend(name);
126
        if (added) {
127
            friends.add(name);
128
        } else {
129
            friends.remove(name);
130
        }
131
        OfflineClient.INSTANCE.getConfigManager().saveSoon();
132
        if (notify.isOn()) {
133
            ChatUtil.message("§b" + name + (added
134
                ? " §7is now a friend." : " §7is no longer a friend."));
135
        }
136
        if (added && sendMessage.isOn() && !message.isBlank()) {
137
            send(message.getValue().replace(NAME_TOKEN, name));
138
        }
139
    }
140
141
    private void send(String text) {
142
        if (text.startsWith("/")) {
143
            mc.getConnection().sendCommand(text.substring(1));
144
        } else {
145
            mc.getConnection().sendChat(text);
146
        }
147
    }
148
149
    private void useItem(Mode chosen) {
150
        int limit = quickSwap.isOn() ? InventoryUtil.WHOLE_INVENTORY : InventoryUtil.HOTBAR_SIZE;
151
        int slot = InventoryUtil.findSlot(chosen.item, limit);
152
        if (slot == -1 || !loan.select(slot)) {
153
            if (warnMissing.isOn()) {
154
                ChatUtil.error("No " + chosen.item.getName(chosen.item.getDefaultInstance())
155
                    .getString().toLowerCase(Locale.ROOT) + " to use.");
156
            }
157
            return;
158
        }
159
        if (chosen.held) {
160
            using = true;
161
            hold.begin();
162
            InputUtil.hold(mc.options.keyUse);
163
            return;
164
        }
165
        mc.gameMode.useItem(mc.player, InteractionHand.MAIN_HAND);
166
        loan.giveBack(swapBack.isOn());
167
    }
168
169
    @Subscribe
170
    private void onTick(TickEvent event) {
171
        if (!using) {
172
            return;
173
        }
174
        // A slot picked by hand cancels the use.
175
        if (!loan.stillMine()) {
176
            finish(false);
177
            return;
178
        }
179
        if (bowDrawn()) {
180
            InputUtil.release(mc.options.keyUse);
181
            return;
182
        }
183
        if (!hold.tick()) {
184
            finish(true);
185
        }
186
    }
187
188
    private boolean bowDrawn() {
189
        return mc.player.isUsingItem() && mc.player.getUseItem().getItem() instanceof BowItem
190
            && BowItem.getPowerForTime(mc.player.getTicksUsingItem()) >= 1;
191
    }
192
193
    // Lets the key go and puts the slots back. A cancelled use keeps the slot the player chose.
194
    private void finish(boolean completed) {
195
        using = false;
196
        hold.release();
197
        loan.giveBack(completed && swapBack.isOn());
198
    }
199
}
200