Files
src
build.gradle
gradle.properties
settings.gradle
VERSE BOOST
Code
6 129
src/client/java/dev/kodari/potatofps/PotatoFpsClient.java
package dev.kodari.potatofps;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.Minecraft;
import net.minecraft.client.OptionInstance;
public class PotatoFpsClient implements ClientModInitializer {
private static final int SAMPLE_INTERVAL_TICKS = 40;
private static final int LOW_FPS_THRESHOLD = 40;
private static final int HIGH_FPS_THRESHOLD = 55;
private static final int MIN_RENDER_DISTANCE = 2;
private int ticksUntilSample = SAMPLE_INTERVAL_TICKS;
private int userRenderDistance = -1;
private int lastAppliedDistance = -1;
@Override
public void onInitializeClient() {
ClientTickEvents.END_CLIENT_TICK.register(this::onEndTick);
}
private void onEndTick(Minecraft client) {
OptionInstance<Integer> renderDistanceOption = client.options.renderDistance();
int currentDistance = renderDistanceOption.get();
if (userRenderDistance < 0) {
userRenderDistance = currentDistance;
lastAppliedDistance = currentDistance;
} else if (currentDistance != lastAppliedDistance) {
userRenderDistance = currentDistance;
lastAppliedDistance = currentDistance;
}
if (--ticksUntilSample > 0) {
return;
}
ticksUntilSample = SAMPLE_INTERVAL_TICKS;
int fps = client.getFps();
int nextDistance = currentDistance;
if (fps < LOW_FPS_THRESHOLD && currentDistance > MIN_RENDER_DISTANCE) {
nextDistance--;
} else if (fps > HIGH_FPS_THRESHOLD && currentDistance < userRenderDistance) {
nextDistance++;
}
if (nextDistance != currentDistance) {
renderDistanceOption.set(nextDistance);
lastAppliedDistance = nextDistance;
}
}
}