Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a CPS variable to Meteor Starscript #4057

Merged
merged 3 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -99,6 +101,11 @@ private void onTick(CallbackInfo info) {
getProfiler().pop();
}

@Inject(method = "doAttack", at = @At("HEAD"))
private void onAttack(CallbackInfoReturnable<Boolean> cir) {
CPSUtils.onAttack();
}

@Inject(method = "doItemUse", at = @At("HEAD"))
private void onDoItemUse(CallbackInfo info) {
doItemUseCalled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public class Utils {
public static double frameTime;
public static Screen screenToOpen;
public static VertexSorter vertexSorter;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why. If you want to cleanup then move the 2 constants to the top of the file and with a new line to separate constants and static variables.

public static final Pattern FILE_NAME_INVALID_CHARS_PATTERN = Pattern.compile("[\\s\\\\/:*?\"<>|]");

@PreInit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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;
import meteordevelopment.starscript.value.Value;


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) {
CPSUtils.cpsChecker();
}


public static void onAttack() {
CPSUtils.clicks++;
CPSUtils.cps++;
}

public static Value getCpsAverage() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return an int in case something also wants to get the value.

return Value.number((int)(
clicks / (secondsClicking == 0 ? 1 : (float)secondsClicking)
));
}

public static void cpsChecker() {
Copy link
Member

@MineGame159 MineGame159 Sep 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesnt need to be a method, and a public one at that. You can just move the body to the onTick handler.

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;
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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", CPSUtils::getCpsAverage);

// Meteor
ss.set("meteor", new ValueMap()
Expand Down Expand Up @@ -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() : ""))
Expand Down