Skip to content

Commit

Permalink
Fix auto clicker not working when a screen is open (#5066)
Browse files Browse the repository at this point in the history
  • Loading branch information
Toshimichi0915 authored Jan 5, 2025
1 parent f33a21b commit 43a72d6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ static int getFps() {
@Accessor("resourceReloadLogger")
ResourceReloadLogger getResourceReloadLogger();

@Accessor("attackCooldown")
int getAttackCooldown();

@Accessor("attackCooldown")
void setAttackCooldown(int attackCooldown);

@Invoker("doAttack")
boolean leftClick();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
package meteordevelopment.meteorclient.systems.modules.player;

import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.settings.EnumSetting;
import meteordevelopment.meteorclient.settings.IntSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.settings.*;
import meteordevelopment.meteorclient.systems.modules.Categories;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.Utils;
Expand All @@ -18,6 +15,13 @@
public class AutoClicker extends Module {
private final SettingGroup sgGeneral = settings.getDefaultGroup();

private final Setting<Boolean> inScreens = sgGeneral.add(new BoolSetting.Builder()
.name("while-in-screens")
.description("Whether to click while a screen is open.")
.defaultValue(true)
.build()
);

private final Setting<Mode> leftClickMode = sgGeneral.add(new EnumSetting.Builder<Mode>()
.name("mode-left")
.description("The method of clicking for left clicks.")
Expand Down Expand Up @@ -74,6 +78,8 @@ public void onDeactivate() {

@EventHandler
private void onTick(TickEvent.Post event) {
if (!inScreens.get() && mc.currentScreen != null) return;

switch (leftClickMode.get()) {
case Disabled -> {}
case Hold -> mc.options.attackKey.setPressed(true);
Expand All @@ -85,6 +91,7 @@ private void onTick(TickEvent.Post event) {
}
}
}

switch (rightClickMode.get()) {
case Disabled -> {}
case Hold -> mc.options.useKey.setPressed(true);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/meteordevelopment/meteorclient/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,14 @@ public static double random(double min, double max) {
}

public static void leftClick() {
// check if a screen is open
// see net.minecraft.client.Mouse.lockCursor
// see net.minecraft.client.MinecraftClient.tick
int attackCooldown = ((MinecraftClientAccessor) mc).getAttackCooldown();
if (attackCooldown == 10000) {
((MinecraftClientAccessor) mc).setAttackCooldown(0);
}

mc.options.attackKey.setPressed(true);
((MinecraftClientAccessor) mc).leftClick();
mc.options.attackKey.setPressed(false);
Expand Down

0 comments on commit 43a72d6

Please sign in to comment.