Skip to content

Commit

Permalink
Prepare 4.0.0-alpha.1.20w21a
Browse files Browse the repository at this point in the history
  • Loading branch information
Past Ennui committed May 27, 2020
1 parent 28061e0 commit 57a6b9d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Double> zoomDivisor = PropertyMirror.create(ConfigTypes.DOUBLE.withMinimum(Double.MIN_VALUE));
public static final PropertyMirror<String> cinematicCamera = PropertyMirror.create(ConfigTypes.STRING.withPattern("^off$|^vanilla$|^multiplied$"));
Expand All @@ -23,7 +26,6 @@ public class OkZoomerConfig {
//public static final PropertyMirror<Integer> adjustableZoomSteps = PropertyMirror.create(ConfigTypes.INTEGER.withMinimum(1));
public static final PropertyMirror<Double> minimumZoomDivisor = PropertyMirror.create(ConfigTypes.DOUBLE.withMinimum(Double.MIN_VALUE));
public static final PropertyMirror<Double> maximumZoomDivisor = PropertyMirror.create(ConfigTypes.DOUBLE.withMinimum(Double.MIN_VALUE));
public static final PropertyMirror<Boolean> unbindConflictingKeybind = PropertyMirror.create(ConfigTypes.BOOLEAN);

public static final ConfigTree tree = ConfigTree.builder()
.beginValue("zoom_divisor", ConfigTypes.DOUBLE.withMinimum(Double.MIN_VALUE), 4.0D)
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -38,20 +41,16 @@ public MinecraftClientMixin(RunArgs args) {

@Inject(at = @At("TAIL"), method = "<init>(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();
}
}

0 comments on commit 57a6b9d

Please sign in to comment.