Skip to content

Commit

Permalink
config
Browse files Browse the repository at this point in the history
  • Loading branch information
KrLite committed Mar 10, 2024
1 parent 24ededb commit 519e762
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
maven-group = "net.krlite"
archives-name = "tapestop"
mod = "3.0.0"
mod = "3.0.1"

minecraft = "1.20"
yarn = "1.20+build.1"
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/net/krlite/tapestop/TapeStop.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.krlite.tapestop;

import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.ConfigHolder;
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
import net.fabricmc.api.ModInitializer;
import net.krlite.tapestop.config.TapeStopConfig;
Expand All @@ -25,11 +26,11 @@
public class TapeStop implements ModInitializer {
public static final String NAME = "Tape Stop", ID = "tapestop";
public static final Logger LOGGER = LoggerFactory.getLogger(ID);
public static final TapeStopConfig CONFIG;
public static final ConfigHolder<TapeStopConfig> CONFIG;

static {
AutoConfig.register(TapeStopConfig.class, Toml4jConfigSerializer::new);
CONFIG = AutoConfig.getConfigHolder(TapeStopConfig.class).get();
CONFIG = AutoConfig.getConfigHolder(TapeStopConfig.class);
}

private static final Class<?>[] excluded = new Class[]{
Expand Down Expand Up @@ -59,16 +60,16 @@ public void onInitialize() {
}

public static boolean shouldTapeStop(@Nullable Screen screen) {
if (!CONFIG.enabled || MinecraftClient.getInstance().world == null) return false;
if (!CONFIG.get().enabled || MinecraftClient.getInstance().world == null) return false;

if (CONFIG.trigger.whenMinimized && GLFW.glfwGetWindowAttrib(MinecraftClient.getInstance().getWindow().getHandle(), GLFW.GLFW_ICONIFIED) == GLFW.GLFW_TRUE) return true;
if (CONFIG.get().trigger.whenMinimized && GLFW.glfwGetWindowAttrib(MinecraftClient.getInstance().getWindow().getHandle(), GLFW.GLFW_ICONIFIED) == GLFW.GLFW_TRUE) return true;

if (CONFIG.trigger.whenLostFocus && !MinecraftClient.getInstance().isWindowFocused()) return true;
if (CONFIG.get().trigger.whenLostFocus && !MinecraftClient.getInstance().isWindowFocused()) return true;

if (screen == null && CONFIG.trigger.afterGameTimeout && isTimeout()) return true;
if (screen == null && CONFIG.get().trigger.afterGameTimeout && isTimeout()) return true;

if (screen != null && !Arrays.asList(excluded).contains(screen.getClass())
&& CONFIG.trigger.afterGUITimeout && isTimeout()) return true;
&& CONFIG.get().trigger.afterGUITimeout && isTimeout()) return true;

tapeStopTime = Util.getMeasuringTimeMs();
updateColors();
Expand Down Expand Up @@ -113,7 +114,7 @@ public static int color() {
}

public static boolean isTimeout() {
return Util.getMeasuringTimeMs() - lastActionTime > CONFIG.timeoutMs;
return Util.getMeasuringTimeMs() - lastActionTime > CONFIG.get().timeoutMs;
}

public static void action() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import me.shedaniel.autoconfig.AutoConfig;
import net.krlite.tapestop.TapeStop;
import net.krlite.tapestop.config.TapeStopConfig;

public class TapeStopModMenuIntegration implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return parent -> AutoConfig.getConfigScreen(TapeStopConfig.class, parent).get();
return parent -> {
TapeStop.CONFIG.load();
return AutoConfig.getConfigScreen(TapeStopConfig.class, parent).get();
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public class GameRendererMixin {
private boolean skipGameRender(MinecraftClient client) {
boolean skip = TapeStop.shouldTapeStop(client.currentScreen);
if (skip) {
if (!skipped) {
TapeStop.CONFIG.load();
}

Window window = MinecraftClient.getInstance().getWindow();
RenderSystem.clear(256, MinecraftClient.IS_SYSTEM_MAC);

Expand All @@ -48,7 +52,7 @@ private boolean skipGameRender(MinecraftClient client) {
matrixStack.translate(0.0F, 0.0F, -2000.0F);
RenderSystem.applyModelViewMatrix();

if (TapeStop.CONFIG.visual.backgroundStyle == TapeStopConfig.BackgroundStyle.PANORAMA && TapeStop.cubeMapRenderer() != null) {
if (TapeStop.CONFIG.get().visual.backgroundStyle == TapeStopConfig.BackgroundStyle.PANORAMA && TapeStop.cubeMapRenderer() != null) {
panorama: {
TapeStopRenderer.renderPanorama();
}
Expand All @@ -58,7 +62,7 @@ private boolean skipGameRender(MinecraftClient client) {
}
}

if (TapeStop.CONFIG.visual.backgroundStyle == TapeStopConfig.BackgroundStyle.PURE_COLOR) {
if (TapeStop.CONFIG.get().visual.backgroundStyle == TapeStopConfig.BackgroundStyle.PURE_COLOR) {
grassBlock: {
TapeStopRenderer.renderGrassBlock(context);
}
Expand Down

0 comments on commit 519e762

Please sign in to comment.