Skip to content

Commit

Permalink
Fix detecting Patcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed Apr 22, 2024
1 parent 1b17697 commit 14c9ed0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public Object setValue(Object value) {
options.add(new ConfigHeader(field, hud, hudAnnotation.name(), category, subcategory, 2));
options.add(new ConfigSwitch(fields.get("enabled"), hud, "Enabled", "If the HUD is enabled", category, subcategory, 1));
options.add(new ConfigButton(fields.get("resetPosition"), hud, "Position", "Reset HUD to default position", category, subcategory, 1, "Reset"));
options.add(new ConfigSwitch(fields.get("locked"), hud, "Locked", "If the position is locked", category, subcategory, HudCore.isPatcher ? 1 : 2));
if (HudCore.isPatcher) options.add(new ConfigSwitch(fields.get("ignoreCaching"), hud, "Ignore HUD Caching", "Ignore Patcher's HUD Caching feature, which limits HUDs to a specific FPS.", category, subcategory, 1));
options.add(new ConfigSwitch(fields.get("locked"), hud, "Locked", "If the position is locked", category, subcategory, HudCore.isPatcher() ? 1 : 2));
if (HudCore.isPatcher()) options.add(new ConfigSwitch(fields.get("ignoreCaching"), hud, "Ignore HUD Caching", "Ignore Patcher's HUD Caching feature, which limits HUDs to a specific FPS.", category, subcategory, 1));
options.add(new ConfigSlider(fields.get("scale"), hud, "Scale", "The scale of the HUD", category, subcategory, 0.3f, 10f, 0, false));
ConfigDropdown dropdown = new ConfigDropdown(fields.get("positionAlignment"), hud, "Position Alignment", "The alignment of the HUD", category, subcategory, 2, new String[]{"Auto", "Left", "Center", "Right"});
dropdown.addListener(() -> hud.setScale(hud.scale, Platform.getGuiPlatform().getCurrentScreen() instanceof HudGui));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cc/polyfrost/oneconfig/hud/Hud.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public boolean isLocked() {
* @return If the hud is ignored from hud caching
*/
public boolean isCachingIgnored() {
return ignoreCaching && (config == null || config.enabled) && HudCore.isPatcher;
return ignoreCaching && (config == null || config.enabled) && HudCore.isPatcher();
}

/**
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import cc.polyfrost.oneconfig.config.elements.BasicOption;
import cc.polyfrost.oneconfig.events.event.HudRenderEvent;
import cc.polyfrost.oneconfig.events.event.InitializationEvent;
import cc.polyfrost.oneconfig.hud.Hud;
import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
import cc.polyfrost.oneconfig.platform.Platform;
Expand All @@ -40,7 +41,7 @@
public class HudCore {
public static final ConcurrentHashMap<Map.Entry<Field, Object>, Hud> huds = new ConcurrentHashMap<>();
public static final ArrayList<BasicOption> hudOptions = new ArrayList<>();
public static final boolean isPatcher = Platform.getLoaderPlatform().isModLoaded("patcher");
private static boolean isPatcher = false;
public static boolean editing = false;

@Subscribe
Expand All @@ -56,6 +57,11 @@ public void onRender(HudRenderEvent event) {
}
}

@Subscribe
public void onInit(InitializationEvent event) {
isPatcher = Platform.getLoaderPlatform().isModLoaded("patcher");
}

public static void reInitHuds() {
for (Map.Entry<Field, Object> field : huds.keySet()) {
if (field == null || field.getKey() == null || field.getValue() == null) continue;
Expand All @@ -74,4 +80,8 @@ public static void reInitHuds() {
}
}
}

public static boolean isPatcher() {
return isPatcher;
}
}

0 comments on commit 14c9ed0

Please sign in to comment.