Skip to content

Commit

Permalink
Some fixes here and there
Browse files Browse the repository at this point in the history
  • Loading branch information
Grayray75 committed Jul 17, 2023
1 parent 71419f0 commit d8a52d9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id "fabric-loom" version "1.3-SNAPSHOT"
id 'io.github.juuxel.loom-vineflower' version "1.11.0"
id "com.modrinth.minotaur" version "2.+"
id "com.matthewprenger.cursegradle" version "1.4.0"
id "maven-publish"
Expand Down Expand Up @@ -103,7 +104,7 @@ curseforge {

project {
id = "440228"
changelog = "A changelog can be found at https://github.com/Grayray75/FPS-Display/blob/${shortMinecraftVersion}/CHANGELOG.md"
changelog = "A changelog can be found at https://github.com/Grayray75/FPS-Display/blob/v3/CHANGELOG.md"
releaseType = "release"
addGameVersion "${project.minecraft_version}"
addGameVersion "Fabric"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public void onInitializeClient() {
}
if (config.keybindMode == ConfigData.KeyMode.PushToShow) {
ShowOverlay = toggleKeybinding.isPressed();
} else {
}
else {
ShowOverlay = config.enabled;
}
});
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/grayray75/mods/fpsdisplay/FpsHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import java.util.List;

public class FpsHistory {
private static final int limit = 1000;
private static final int LIMIT = 420;

private final List<Integer> list = new ArrayList<Integer>();
private final List<Integer> list = new ArrayList<>();

public void add(int fps) {
this.list.add(fps);

if (this.list.size() > 1000) {
if (this.list.size() > LIMIT) {
this.list.remove(0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.terraformersmc.modmenu.api.ModMenuApi;
import io.grayray75.mods.fpsdisplay.gui.ClothOptionScreen;
import io.grayray75.mods.fpsdisplay.gui.FallbackOptionScreen;
import me.shedaniel.autoconfig.AutoConfig;
import net.fabricmc.loader.api.FabricLoader;

public class ModMenuIntegration implements ModMenuApi {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// https://shedaniel.gitbook.io/cloth-config/

public class ClothOptionScreen {
public static Screen generateScreen(Screen parent ){
public static Screen generateScreen(Screen parent) {
ConfigBuilder builder = ConfigBuilder.create();
builder.setParentScreen(parent);
builder.setTitle(Text.translatable("text.fpsdisplay.options.title"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ public void render(DrawContext context, float tickDelta, CallbackInfo info) {
ConfigData config = ConfigManager.getConfig();

if (!client.options.debugEnabled && config.enabled && config.textAlpha > 3 && FpsDisplayMod.ShowOverlay) {
String text;
if (!config.advancedStats) {
text = ((MinecraftClientAccessor) client).getCurrentFps() + " FPS";
}
else {
text = String.format("%d FPS (%d min %d avg %d max)", ((MinecraftClientAccessor) client).getCurrentFps(), FpsDisplayMod.FpsHistory.getMinimum(), FpsDisplayMod.FpsHistory.getAverage(), FpsDisplayMod.FpsHistory.getMaximum());
}

String displayString = String.format("%d FPS (%d min %d avg %d max)",
((MinecraftClientAccessor) client).getCurrentFps(),
FpsDisplayMod.FpsHistory.getMinimum(),
FpsDisplayMod.FpsHistory.getAverage(),
FpsDisplayMod.FpsHistory.getMaximum());
int textPosX = config.offsetLeft;
int textPosY = config.offsetTop;

Expand All @@ -37,14 +39,14 @@ public void render(DrawContext context, float tickDelta, CallbackInfo info) {
}

// Prevent text to render outside screenspace
int maxTextPosX = client.getWindow().getScaledWidth() - client.textRenderer.getWidth(displayString);
int maxTextPosX = client.getWindow().getScaledWidth() - client.textRenderer.getWidth(text);
int maxTextPosY = client.getWindow().getScaledHeight() - client.textRenderer.fontHeight;
textPosX = Math.min(textPosX, maxTextPosX);
textPosY = Math.min(textPosY, maxTextPosY);

int textColor = ((config.textAlpha & 0xFF) << 24) | config.textColor;

this.renderText(context, client.textRenderer, displayString, textPosX, textPosY, textColor, config.textSize, config.textShadows);
this.renderText(context, client.textRenderer, text, textPosX, textPosY, textColor, config.textSize, config.textShadows);
}
}

Expand All @@ -57,7 +59,8 @@ private void renderText(DrawContext context, TextRenderer textRenderer, String t
matrixStack.translate(-x, -y, 0);
context.drawText(textRenderer, text, x, y, color, shadowed);
matrixStack.pop();
} else {
}
else {
context.drawText(textRenderer, text, x, y, color, shadowed);
}
}
Expand Down

0 comments on commit d8a52d9

Please sign in to comment.