From 57a6b9dd9f2b08a6ab86f9bd2dc1bd879f20d46a Mon Sep 17 00:00:00 2001 From: Past Ennui Date: Wed, 27 May 2020 18:02:06 -0300 Subject: [PATCH] Prepare 4.0.0-alpha.1.20w21a --- .../joaoh1/okzoomer/config/OkZoomerConfig.java | 9 ++++----- .../okzoomer/mixin/MinecraftClientMixin.java | 15 +++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/java/io/github/joaoh1/okzoomer/config/OkZoomerConfig.java b/src/main/java/io/github/joaoh1/okzoomer/config/OkZoomerConfig.java index f170e4dc..cb2f49ca 100644 --- a/src/main/java/io/github/joaoh1/okzoomer/config/OkZoomerConfig.java +++ b/src/main/java/io/github/joaoh1/okzoomer/config/OkZoomerConfig.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import io.github.fablabsmc.fablabs.api.fiber.v1.exception.FiberException; @@ -12,6 +13,8 @@ import io.github.fablabsmc.fablabs.impl.fiber.serialization.FiberSerialization; public class OkZoomerConfig { + public static final Path okZoomerConfigPath = Paths.get("./config/okzoomer-next.json5"); + //TODO - Organize the config in categories public static final PropertyMirror zoomDivisor = PropertyMirror.create(ConfigTypes.DOUBLE.withMinimum(Double.MIN_VALUE)); public static final PropertyMirror cinematicCamera = PropertyMirror.create(ConfigTypes.STRING.withPattern("^off$|^vanilla$|^multiplied$")); @@ -23,7 +26,6 @@ public class OkZoomerConfig { //public static final PropertyMirror adjustableZoomSteps = PropertyMirror.create(ConfigTypes.INTEGER.withMinimum(1)); public static final PropertyMirror minimumZoomDivisor = PropertyMirror.create(ConfigTypes.DOUBLE.withMinimum(Double.MIN_VALUE)); public static final PropertyMirror maximumZoomDivisor = PropertyMirror.create(ConfigTypes.DOUBLE.withMinimum(Double.MIN_VALUE)); - public static final PropertyMirror unbindConflictingKeybind = PropertyMirror.create(ConfigTypes.BOOLEAN); public static final ConfigTree tree = ConfigTree.builder() .beginValue("zoom_divisor", ConfigTypes.DOUBLE.withMinimum(Double.MIN_VALUE), 4.0D) @@ -58,15 +60,12 @@ public class OkZoomerConfig { .beginValue("maximum_zoom_divisor", ConfigTypes.DOUBLE.withMinimum(Double.MIN_VALUE), 50.0D) .withComment("The maximum value that you can scroll up.") .finishValue(maximumZoomDivisor::mirror) - .beginValue("unbind_conflicting_keybind", ConfigTypes.BOOLEAN, true) - .withComment("Unbinds the \"Save Hotbar Activator\" keybind, which is binded to C by default.\nOnce it's unbinded/ignored, this config value is set to false.") - .finishValue(unbindConflictingKeybind::mirror) .build(); private static JanksonValueSerializer serializer = new JanksonValueSerializer(false); public static void loadJanksonConfig() { - if (Files.exists(Paths.get("./config/okzoomer-next.json5"))) { + if (Files.exists(okZoomerConfigPath)) { try { FiberSerialization.deserialize(tree, Files.newInputStream(Paths.get("./config/okzoomer-next.json5")), serializer); } catch (IOException | FiberException e) { diff --git a/src/main/java/io/github/joaoh1/okzoomer/mixin/MinecraftClientMixin.java b/src/main/java/io/github/joaoh1/okzoomer/mixin/MinecraftClientMixin.java index db72e96c..0962f6f2 100644 --- a/src/main/java/io/github/joaoh1/okzoomer/mixin/MinecraftClientMixin.java +++ b/src/main/java/io/github/joaoh1/okzoomer/mixin/MinecraftClientMixin.java @@ -1,6 +1,8 @@ package io.github.joaoh1.okzoomer.mixin; import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -18,6 +20,7 @@ import net.minecraft.client.util.InputUtil; //TODO - Create a mixin plugin for this, this should only be injected once and then never more. +//Responsible for loading the config and handling the hijacking of "Save Toolbar Activator". @Mixin(MinecraftClient.class) public class MinecraftClientMixin { @Shadow @@ -38,20 +41,16 @@ public MinecraftClientMixin(RunArgs args) { @Inject(at = @At("TAIL"), method = "(Lnet/minecraft/client/RunArgs;)V") public void hijackCKeybind(RunArgs args, CallbackInfo info) { - //Load the configuration. - OkZoomerConfig.loadJanksonConfig(); - - //If "Unbind Conflicting Keybind" is true, unbind the "Save Toolbar Activator" keybind if it hasn't been changed. - if (OkZoomerConfig.unbindConflictingKeybind.getValue()) { + //If the configuration didn't exist before, unbind the "Save Toolbar Activator" keybind if there's a conflict. + if (!Files.exists(OkZoomerConfig.okZoomerConfigPath)) { if (OkZoomerMod.zoomKeyBinding.isDefault()) { if (this.options.keySaveToolbarActivator.isDefault()) { modLogger.info("[Ok Zoomer Next] The \"Save Toolbar Activator\" keybind was occupying C! Unbinding... This process won't be repeated."); this.options.keySaveToolbarActivator.setBoundKey(InputUtil.fromKeyCode(InputUtil.UNKNOWN_KEY.getCode(), InputUtil.UNKNOWN_KEY.getCode())); } } - //Set self to false. - OkZoomerConfig.unbindConflictingKeybind.setValue(false); - OkZoomerConfig.saveJanksonConfig(); } + //Load the configuration. + OkZoomerConfig.loadJanksonConfig(); } } \ No newline at end of file