Skip to content

Commit

Permalink
Set frameCounter to 1 when begin record
Browse files Browse the repository at this point in the history
  • Loading branch information
NyaNLI authored and mchorse committed Dec 7, 2021
1 parent e8c62c1 commit 10ec13c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ protected void doEnable() {
// set fixed delay timer
timer = new FixedTimer(defaultTps, fps, speed);
PrivateAccessor.setMinecraftTimer(MC, timer);

PrivateAccessor.setFrameCounter(-1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public final class PrivateAccessor {
// (Mod classes of which the corresponding mod is not yet loaded)
private static Boolean shaderpackSupport;
private static Optional<Field> Shaders_frameTimeCounter;
private static Optional<Field> Shaders_frameCounter;
private static Optional<Field> ofLazyChunkLoading;
private static Optional<Field> ofChunkUpdates;
private static Optional<Field> ofShaderPackLoaded;
Expand All @@ -51,6 +52,9 @@ private static void lateLoadOptifineField() {
if (Shaders_frameTimeCounter == null) {
Shaders_frameTimeCounter = Optional.ofNullable(getAccessibleField("net.optifine.shaders.Shaders", "frameTimeCounter"));
}
if (Shaders_frameCounter == null) {
Shaders_frameCounter = Optional.ofNullable(getAccessibleField("net.optifine.shaders.Shaders", "frameCounter"));
}
if (ofLazyChunkLoading == null) {
ofLazyChunkLoading = Optional.ofNullable(getAccessibleField(GameSettings.class, "ofLazyChunkLoading"));
}
Expand Down Expand Up @@ -189,6 +193,33 @@ public static void setFrameTimeCounter(float frameTimerCounter) {
}
}

public static int getFrameCounter() {
lateLoadOptifineField();

if (Shaders_frameCounter.isPresent()) {
try {
// this field is static, just using null as the object
return Shaders_frameCounter.get().getInt(null);
} catch (IllegalArgumentException | IllegalAccessException e) {
}
}

// just a default
return 0;
}

public static void setFrameCounter(int frameCounter) {
lateLoadOptifineField();

if (Shaders_frameCounter.isPresent()) {
try {
// this field is static, just using null as the object
Shaders_frameCounter.get().setInt(null, frameCounter);
} catch (IllegalArgumentException | IllegalAccessException e) {
}
}
}

public static boolean isLazyChunkLoading() {
lateLoadOptifineField();

Expand Down

0 comments on commit 10ec13c

Please sign in to comment.