Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
Auto Clicker
Browse files Browse the repository at this point in the history
  • Loading branch information
CubeWhy committed Aug 1, 2023
1 parent 370fbeb commit 1104bb8
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 15 deletions.
28 changes: 16 additions & 12 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/main/java/org/cubewhy/lunarcn/event/events/MouseEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.cubewhy.lunarcn.event.events;

import org.cubewhy.lunarcn.event.Event;

public class MouseEvent extends Event {

public final MouseButton button;

public MouseEvent(MouseButton button) {
this.button = button;

}
public enum MouseButton {
LEFT,
MIDDLE,
RIGHT
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.common.MinecraftForge;
import org.cubewhy.lunarcn.Client;
import org.cubewhy.lunarcn.event.events.MouseEvent;
import org.cubewhy.lunarcn.event.events.ScreenChangeEvent;
import org.cubewhy.lunarcn.event.events.TickEvent;
import org.cubewhy.lunarcn.event.events.WorldEvent;
Expand Down Expand Up @@ -193,4 +194,18 @@ public void displayGuiScreen(GuiScreen guiScreenIn) {
public void loadWorld(WorldClient worldClientIn, String loadingMessage, CallbackInfo ci) {
new WorldEvent(worldClientIn).callEvent(); // call worldEvent
}

@Inject(method = "clickMouse", at = @At("RETURN"))
public void clickMouse(CallbackInfo ci) {
new MouseEvent(MouseEvent.MouseButton.LEFT).callEvent();
}
@Inject(method = "rightClickMouse", at = @At("RETURN"))
public void rightClickMouse(CallbackInfo ci) {
new MouseEvent(MouseEvent.MouseButton.RIGHT).callEvent();
}

@Inject(method = "middleClickMouse", at = @At("RETURN"))
public void middleClickMouse(CallbackInfo ci) {
new MouseEvent(MouseEvent.MouseButton.MIDDLE).callEvent();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cubewhy.lunarcn.injection.forge.mixins.gui;

import net.minecraft.client.gui.*;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -14,7 +15,7 @@ public void initGui(CallbackInfo ci) {
}

@Inject(method = "actionPerformed", at = @At("RETURN"))
public void actionPerformed(GuiButton button, CallbackInfo ci) {
public void actionPerformed(@NotNull GuiButton button, CallbackInfo ci) {
if (button.id == 114514) {
// server switcher
mc.displayGuiScreen(new GuiMultiplayer(mc.currentScreen)); // display gui multiplayer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@


import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiMultiplayer;
import net.minecraft.client.gui.ServerListEntryNormal;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.util.ResourceLocation;
import org.cubewhy.lunarcn.FeaturedServerData;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import static org.cubewhy.lunarcn.utils.MinecraftInstance.mc;

Expand All @@ -25,11 +29,24 @@ public class MixinServerListEntryNormal {
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected, CallbackInfo ci) {
boolean isFeaturedServer = this.server instanceof FeaturedServerData;
if (isFeaturedServer) {
drawImageStar(x, y, false, FeaturedServerData.starIcon);
liquidLunarForge$drawImageStar(x, y, false, FeaturedServerData.starIcon);
}
}

private void drawImageStar(int x, int y, boolean lower, ResourceLocation starIcon) {
@Inject(method = "mousePressed", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiMultiplayer;connectToSelected()V"))
public void mousePressed(int slotIndex, int p_148278_2_, int p_148278_3_, int p_148278_4_, int p_148278_5_, int p_148278_6_, CallbackInfoReturnable<Boolean> cir) {
// disconnect in server switcher
if (mc.getCurrentServerData() != null && !mc.isSingleplayer()) {
// back to the menu
mc.displayGuiScreen(new GuiMultiplayer(new GuiMainMenu()));
} else if (mc.isSingleplayer()) {
// back to mainMenu
mc.displayGuiScreen(new GuiMainMenu());
}
}

@Unique
private void liquidLunarForge$drawImageStar(int x, int y, boolean lower, ResourceLocation starIcon) {
mc.getTextureManager().bindTexture(starIcon);
Gui.drawModalRectWithCustomSizedTexture(x - 16, lower ? y + 16 : y, 0.00F, 0.00F, 16, 16, 16, 16);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/cubewhy/lunarcn/value/IntValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import org.jetbrains.annotations.NotNull;

public class IntValue extends Value<Integer> {
public final int maxValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.cubewhy.lunarcn.module.impl.cheats

import org.cubewhy.lunarcn.event.EventTarget
import org.cubewhy.lunarcn.event.events.TickEvent
import org.cubewhy.lunarcn.module.Module
import org.cubewhy.lunarcn.module.ModuleCategory
import org.cubewhy.lunarcn.module.ModuleInfo
import org.cubewhy.lunarcn.utils.MSTimer
import org.cubewhy.lunarcn.value.BooleanValue
import org.cubewhy.lunarcn.value.IntValue
import org.lwjgl.input.Mouse
import kotlin.random.Random

@ModuleInfo(name = "AutoClicker", description = "Click agent", category = ModuleCategory.CHEATS)
class AutoClicker : Module() {
private val maxCPS = IntValue("MaxCPS", 6, 0, 40)
private val minCPS = IntValue("MinCPS", 2, 0, 40)

private val targetClick = BooleanValue("TargetClick", false)

private val leftLastPressed: Long = -1
private val rightLastPressed: Long = -1
private var delay: Long = -1;

private val leftHasPressed = false
private val rightHasPressed = false

private val clicksLeft = ArrayList<Long>()
private val clicksRight = ArrayList<Long>()

private val timer = MSTimer()

@EventTarget
fun onTick(event: TickEvent) {
if (minCPS.value > maxCPS.value) {
maxCPS.value = minCPS.value // min can't > max
}
if (targetClick.value && mc.pointedEntity != null || Mouse.isButtonDown(0)) {
handleClickLeft() // click the mouse
}
}

/**
* Click the mouse with the cps
* */
private fun handleClickLeft() {
val cps = Random.nextInt(minCPS.value, maxCPS.value)
delay = if (getLeftCPS() >= cps) {
100
} else {
30
}

if (timer.hasTimePassed(delay)) {
mc.clickMouse() // click mouse
timer.reset() // reset the timer
}
}

private fun getLeftCPS(): Int {
val time = System.currentTimeMillis()
this.clicksLeft.removeIf { clickTime: Long -> clickTime + 1000 < time }
return this.clicksLeft.size
}

private fun getRightCPS(): Int {
val time = System.currentTimeMillis()
this.clicksRight.removeIf { clickTime: Long -> clickTime + 1000 < time }
return this.clicksRight.size
}
}

0 comments on commit 1104bb8

Please sign in to comment.