Use LibJF for config
This commit is contained in:
parent
39d3f88c8b
commit
07425a86a5
|
@ -11,7 +11,9 @@ dependencies {
|
|||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
|
||||
// For testing in dev environment
|
||||
modRuntime "net.fabricmc.fabric-api:fabric-api:0.34.9+1.17"
|
||||
modRuntime "net.fabricmc.fabric-api:fabric-api:0.37.0+1.17"
|
||||
|
||||
modImplementation "maven.modrinth:sodium:mc1.17.1-0.3.0"
|
||||
|
||||
download("https://gitlab.com/jfmods/LibJF/-/jobs/artifacts/master/raw/latest-dev.jar?job=build_test", "libjf")
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
org.gradle.jvmargs=-Xmx1G
|
||||
# Fabric Properties
|
||||
# check these on https://modmuss50.me/fabric.html
|
||||
minecraft_version=1.17
|
||||
yarn_mappings=build.1
|
||||
loader_version=0.11.3
|
||||
minecraft_version=1.17.1
|
||||
yarn_mappings=build.24
|
||||
loader_version=0.11.6
|
||||
# Mod Properties
|
||||
mod_version=1.4.1
|
||||
maven_group=io.gitlab.jfronny
|
||||
|
|
|
@ -1,53 +1,13 @@
|
|||
package io.gitlab.jfronny.slyde;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Properties;
|
||||
|
||||
public class Cfg {
|
||||
public boolean sodiumCompat = true;
|
||||
public boolean forceSodiumCompat = false;
|
||||
public boolean holdKeyToActivate = false;
|
||||
|
||||
private static Cfg conf = null;
|
||||
|
||||
public static Cfg get() {
|
||||
if (conf == null)
|
||||
load();
|
||||
return conf;
|
||||
}
|
||||
|
||||
private static void load() {
|
||||
Properties p = new Properties();
|
||||
conf = new Cfg();
|
||||
Path c = FabricLoader.getInstance().getConfigDir().resolve("slyde.cfg");
|
||||
try (InputStream s = Files.newInputStream(c)) {
|
||||
p.load(s);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
conf.sodiumCompat = getBool(p, "sodiumCompat", conf.sodiumCompat);
|
||||
conf.forceSodiumCompat = getBool(p, "forceSodiumCompat", conf.forceSodiumCompat);
|
||||
conf.holdKeyToActivate = getBool(p, "holdKeyToActivate", conf.holdKeyToActivate);
|
||||
try {
|
||||
p.store(Files.newOutputStream(c), "Slyde config");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean getBool(Properties p, String name, boolean def) {
|
||||
Object o = p.get(name);
|
||||
if (o instanceof Boolean)
|
||||
return (Boolean) o;
|
||||
if (o instanceof String)
|
||||
return Boolean.parseBoolean((String) o);
|
||||
p.put(name, Boolean.toString(def));
|
||||
return def;
|
||||
}
|
||||
import io.gitlab.jfronny.libjf.config.Entry;
|
||||
import io.gitlab.jfronny.libjf.config.JfConfig;
|
||||
|
||||
public class Cfg implements JfConfig {
|
||||
@Entry
|
||||
public static boolean sodiumCompat = true;
|
||||
@Entry
|
||||
public static boolean forceSodiumCompat = false;
|
||||
@Entry
|
||||
public static boolean holdKeyToActivate = false;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package io.gitlab.jfronny.slyde;
|
||||
|
||||
import io.gitlab.jfronny.slyde.mixin.SodiumSliderControlMixin;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class Plugin implements IMixinConfigPlugin {
|
||||
|
@ -24,7 +22,7 @@ public class Plugin implements IMixinConfigPlugin {
|
|||
@Override
|
||||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
||||
if ("io.gitlab.jfronny.slyde.mixin.SodiumSliderControlMixin".equals(mixinClassName))
|
||||
return Cfg.get().forceSodiumCompat || (Cfg.get().sodiumCompat && FabricLoader.getInstance().isModLoaded("sodium"));
|
||||
return Cfg.forceSodiumCompat || (Cfg.sodiumCompat && FabricLoader.getInstance().isModLoaded("sodium"));
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,25 +1,16 @@
|
|||
package io.gitlab.jfronny.slyde;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class SlydeClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
Cfg.get();
|
||||
}
|
||||
|
||||
public class Slyde {
|
||||
public static boolean isActive() {
|
||||
long handle = MinecraftClient.getInstance().getWindow().getHandle();
|
||||
boolean down = InputUtil.isKeyPressed(handle, GLFW.GLFW_KEY_LEFT_SHIFT)
|
||||
|| InputUtil.isKeyPressed(handle, GLFW.GLFW_KEY_RIGHT_SHIFT)
|
||||
|| InputUtil.isKeyPressed(handle, GLFW.GLFW_KEY_LEFT_CONTROL)
|
||||
|| InputUtil.isKeyPressed(handle, GLFW.GLFW_KEY_RIGHT_CONTROL);
|
||||
return down == Cfg.get().holdKeyToActivate;
|
||||
return down == Cfg.holdKeyToActivate;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package io.gitlab.jfronny.slyde.mixin;
|
||||
|
||||
import io.gitlab.jfronny.slyde.SlydeClient;
|
||||
import io.gitlab.jfronny.slyde.Slyde;
|
||||
import net.minecraft.client.gui.widget.SliderWidget;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
@ -11,6 +11,6 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
|||
public abstract class SliderWidgetMixin {
|
||||
@Redirect(method = "setValue(D)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(DDD)D"))
|
||||
private double adjustClamp(double value, double min, double max) {
|
||||
return SlydeClient.isActive() ? value : MathHelper.clamp(value, min, max);
|
||||
return Slyde.isActive() ? value : MathHelper.clamp(value, min, max);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.gitlab.jfronny.slyde.mixin;
|
||||
|
||||
import io.gitlab.jfronny.slyde.SlydeClient;
|
||||
import io.gitlab.jfronny.slyde.Slyde;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
@ -10,6 +10,6 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
|||
public abstract class SodiumSliderControlMixin {
|
||||
@Redirect(method = "setValue(D)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(DDD)D"))
|
||||
private double adjustClamp(double value, double min, double max) {
|
||||
return SlydeClient.isActive() ? value : MathHelper.clamp(value, min, max);
|
||||
return Slyde.isActive() ? value : MathHelper.clamp(value, min, max);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
"license": "MIT",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"client": [
|
||||
"io.gitlab.jfronny.slyde.SlydeClient"
|
||||
"libjf:config": [
|
||||
"io.gitlab.jfronny.slyde.Cfg"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
|
@ -24,6 +24,7 @@
|
|||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.10.0+build.208",
|
||||
"minecraft": "*"
|
||||
"minecraft": "*",
|
||||
"libjf": ">=1.2.0"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue