diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/MinecraftClientMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/MinecraftClientMixin.java index 7f2f15c401..02bdc0cc4b 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/MinecraftClientMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/MinecraftClientMixin.java @@ -21,6 +21,7 @@ import meteordevelopment.meteorclient.systems.modules.player.FastUse; import meteordevelopment.meteorclient.systems.modules.render.UnfocusedCPU; import meteordevelopment.meteorclient.utils.Utils; +import meteordevelopment.meteorclient.utils.misc.CPSUtils; import meteordevelopment.meteorclient.utils.misc.MeteorStarscript; import meteordevelopment.meteorclient.utils.network.OnlinePlayers; import meteordevelopment.starscript.Script; @@ -82,6 +83,7 @@ private void onInit(CallbackInfo info) { @Inject(at = @At("HEAD"), method = "tick") private void onPreTick(CallbackInfo info) { OnlinePlayers.update(); + doItemUseCalled = false; getProfiler().push(MeteorClient.MOD_ID + "_pre_update"); @@ -99,6 +101,11 @@ private void onTick(CallbackInfo info) { getProfiler().pop(); } + @Inject(method = "doAttack", at = @At("HEAD")) + private void onAttack(CallbackInfoReturnable cir) { + CPSUtils.onAttack(); + } + @Inject(method = "doItemUse", at = @At("HEAD")) private void onDoItemUse(CallbackInfo info) { doItemUseCalled = true; diff --git a/src/main/java/meteordevelopment/meteorclient/utils/Utils.java b/src/main/java/meteordevelopment/meteorclient/utils/Utils.java index df8bfa0b4e..c8e84ac468 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/Utils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/Utils.java @@ -64,17 +64,17 @@ import static org.lwjgl.glfw.GLFW.*; public class Utils { + public static final Pattern FILE_NAME_INVALID_CHARS_PATTERN = Pattern.compile("[\\s\\\\/:*?\"<>|]"); + public static final Color WHITE = new Color(255, 255, 255); + private static final Random random = new Random(); public static boolean firstTimeTitleScreen = true; public static boolean isReleasingTrident; - public static final Color WHITE = new Color(255, 255, 255); public static boolean rendering3D = true; public static double frameTime; public static Screen screenToOpen; public static VertexSorter vertexSorter; - public static final Pattern FILE_NAME_INVALID_CHARS_PATTERN = Pattern.compile("[\\s\\\\/:*?\"<>|]"); - @PreInit public static void init() { MeteorClient.EVENT_BUS.subscribe(Utils.class); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/CPSUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/CPSUtils.java new file mode 100644 index 0000000000..ecbc4c056c --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/utils/misc/CPSUtils.java @@ -0,0 +1,50 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.utils.misc; + +import meteordevelopment.meteorclient.MeteorClient; +import meteordevelopment.meteorclient.events.world.TickEvent; +import meteordevelopment.meteorclient.utils.PreInit; +import meteordevelopment.orbit.EventHandler; + + +public class CPSUtils { + private static int clicks; + private static int cps; + private static int secondsClicking; + private static long lastTime; + + @PreInit + public static void init() { + MeteorClient.EVENT_BUS.subscribe(CPSUtils.class); + } + + @EventHandler + private static void onTick(TickEvent.Pre event) { + long currentTime = System.currentTimeMillis(); + // Run every second + if (currentTime - CPSUtils.lastTime >= 1000) { + if (CPSUtils.cps == 0) { + CPSUtils.clicks = 0; + CPSUtils.secondsClicking = 0; + } else { + CPSUtils.lastTime = currentTime; + CPSUtils.secondsClicking++; + CPSUtils.cps = 0; + } + } + } + + + public static void onAttack() { + CPSUtils.clicks++; + CPSUtils.cps++; + } + + public static int getCpsAverage() { + return clicks / (secondsClicking == 0 ? 1 : secondsClicking); + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/MeteorStarscript.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/MeteorStarscript.java index dedb7b8e80..242fb36a4b 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/MeteorStarscript.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/misc/MeteorStarscript.java @@ -78,6 +78,7 @@ public static void init() { ss.set("fps", () -> Value.number(MinecraftClientAccessor.getFps())); ss.set("ping", MeteorStarscript::ping); ss.set("time", () -> Value.string(LocalTime.now().format(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)))); + ss.set("cps", () -> Value.number(CPSUtils.getCpsAverage())); // Meteor ss.set("meteor", new ValueMap() @@ -125,7 +126,7 @@ public static void init() { .set("health", () -> Value.number(mc.player != null ? mc.player.getHealth() : 0)) .set("absorption", () -> Value.number(mc.player != null ? mc.player.getAbsorptionAmount() : 0)) .set("hunger", () -> Value.number(mc.player != null ? mc.player.getHungerManager().getFoodLevel() : 0)) - + .set("speed", () -> Value.number(Utils.getPlayerSpeed().horizontalLength())) .set("speed_all", new ValueMap() .set("_toString", () -> Value.string(mc.player != null ? Utils.getPlayerSpeed().toString() : ""))