Skip to content

Commit 31a1a70

Browse files
Initial update to use autoconfig
1 parent 2975348 commit 31a1a70

7 files changed

Lines changed: 52 additions & 168 deletions

File tree

build.gradle

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ buildscript {
77
}
88
}
99
dependencies {
10-
classpath 'net.fabricmc:fabric-loom:0.5-SNAPSHOT'
10+
classpath 'net.fabricmc:fabric-loom:0.6-SNAPSHOT'
1111
classpath 'com.github.jengelman.gradle.plugins:shadow:6.1.0'
1212
}
1313
}
1414

1515
apply plugin: 'fabric-loom'
1616
apply plugin: 'maven-publish'
17-
apply plugin: 'com.github.johnrengelman.shadow'
1817

1918
sourceCompatibility = JavaVersion.VERSION_1_8
2019
targetCompatibility = JavaVersion.VERSION_1_8
@@ -34,30 +33,22 @@ repositories {
3433
mavenCentral()
3534
maven { url "https://dl.bintray.com/shedaniel/shedaniel-mods" }
3635
maven { url 'https://jitpack.io' }
36+
jcenter()
3737
}
3838

3939
minecraft {
4040
accessWidener 'src/main/resources/vanillafix_aw.txt'
4141
}
4242

43-
configurations {
44-
shade
45-
}
46-
47-
tasks.remapJar.dependsOn(shadowJar)
48-
(tasks.remapJar.input as FileSystemLocationProperty<? extends FileSystemLocation>).set(shadowJar.archivePath)
49-
5043
dependencies {
51-
implementation "blue.endless:jankson:1.1.0"
52-
shade "blue.endless:jankson:1.1.0"
53-
minecraft "com.mojang:minecraft:${project.minecraft_version}"
54-
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
55-
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
56-
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
44+
minecraft "com.mojang:minecraft:1.16.5"
45+
mappings "net.fabricmc:yarn:1.16.5+build.3:v2"
46+
modImplementation "net.fabricmc:fabric-loader:0.11.1"
47+
modImplementation "net.fabricmc.fabric-api:fabric-api:0.30.0+1.16"
5748

5849
// Cos why not
59-
modImplementation "com.github.Chocohead:Fabric-ASM:${project.fabric_asm_version}"
60-
include "com.github.Chocohead:Fabric-ASM:${project.fabric_asm_version}"
50+
modImplementation "com.github.Chocohead:Fabric-ASM:v2.1"
51+
include "com.github.Chocohead:Fabric-ASM:v2.1"
6152

6253
// Compatibility
6354
modImplementation 'com.github.jellysquid3:lithium-fabric:90c2427'
@@ -72,6 +63,7 @@ dependencies {
7263
exclude module: 'fabric-api'
7364
}
7465
include 'me.shedaniel.cloth:config-2:4.8.2'
66+
modImplementation include('me.sargunvohra.mcmods:autoconfig1u:3.3.1')
7567

7668
// Accessing the config
7769
modImplementation('io.github.prospector:modmenu:1.14.6+build.31') {
@@ -111,7 +103,3 @@ jar {
111103
from "LICENSE"
112104
}
113105

114-
shadowJar {
115-
configurations = [project.configurations.shade]
116-
relocate 'blue.endless.jankson', 'org.dimdev.vanillafix.shadowed.blue.endless.jankson'
117-
}

src/main/java/org/dimdev/vanillafix/VanillaFix.java

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
import java.io.IOException;
44
import java.io.InputStream;
5-
import java.nio.file.Files;
65
import java.nio.file.Path;
76
import java.util.Map;
87
import java.util.stream.Collectors;
98

10-
import blue.endless.jankson.Jankson;
11-
import blue.endless.jankson.JsonObject;
12-
import blue.endless.jankson.impl.SyntaxError;
139
import com.google.common.collect.ImmutableMap;
10+
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
11+
import me.sargunvohra.mcmods.autoconfig1u.ConfigHolder;
12+
import me.sargunvohra.mcmods.autoconfig1u.serializer.JanksonConfigSerializer;
13+
import me.sargunvohra.mcmods.autoconfig1u.shadowed.blue.endless.jankson.Jankson;
14+
import me.sargunvohra.mcmods.autoconfig1u.shadowed.blue.endless.jankson.JsonObject;
15+
import me.sargunvohra.mcmods.autoconfig1u.shadowed.blue.endless.jankson.impl.SyntaxError;
1416
import org.apache.logging.log4j.LogManager;
1517
import org.apache.logging.log4j.Logger;
1618
import org.dimdev.vanillafix.util.ConfigPair;
@@ -24,10 +26,10 @@
2426
public class VanillaFix implements ModInitializer {
2527
public static final Logger LOGGER = LogManager.getLogger();
2628
public static final ModContainer MOD = FabricLoader.getInstance().getModContainer("vanillafix").orElseThrow(IllegalStateException::new);
27-
private static ModConfig MOD_CONFIG;
2829
private static final Path PATH = FabricLoader.getInstance().getConfigDir().resolve("vanillafix.json5");
2930
public static final Jankson JANKSON = Jankson.builder().build();
3031
public static final Map<String, ConfigPair> MIXIN_CONFIGS;
32+
public static final ConfigHolder<ModConfig> CONFIG = AutoConfig.register(ModConfig.class, JanksonConfigSerializer::new);
3133

3234
@Override
3335
public void onInitialize() {
@@ -42,24 +44,6 @@ public void onInitialize() {
4244
}
4345

4446
static {
45-
try {
46-
if (Files.exists(PATH)) {
47-
MOD_CONFIG = JANKSON.fromJson(JANKSON.load(Files.newInputStream(PATH)), ModConfig.class);
48-
} else {
49-
Files.createFile(PATH);
50-
Files.write(PATH, JANKSON.toJson(MOD_CONFIG).toJson(true, true).getBytes());
51-
}
52-
} catch (IOException e) {
53-
LOGGER.error("Error loading config. Using default values");
54-
e.printStackTrace();
55-
MOD_CONFIG = new ModConfig();
56-
} catch (SyntaxError e) {
57-
LOGGER.error("Caught a Syntax error when loading config. Using default values");
58-
LOGGER.error(e.getCompleteMessage());
59-
e.printStackTrace();
60-
MOD_CONFIG = new ModConfig();
61-
}
62-
6347
ImmutableMap.Builder<String, ConfigPair> builder = ImmutableMap.builder();
6448
try (InputStream stream = VanillaFix.class.getResourceAsStream("/data/vanillafix/mixin_configs.json")) {
6549
JsonObject jsonObject = JANKSON.load(stream);
@@ -89,17 +73,7 @@ public ConfigPair setValue(ConfigPair value) {
8973
MIXIN_CONFIGS = builder.build();
9074
}
9175

92-
public static void save() {
93-
String json = JANKSON.toJson(MOD_CONFIG).toJson(true, true);
94-
try {
95-
Files.write(PATH, json.getBytes());
96-
} catch (IOException e) {
97-
LOGGER.error("Error saving config");
98-
e.printStackTrace();
99-
}
100-
}
101-
10276
public static ModConfig config() {
103-
return MOD_CONFIG;
77+
return CONFIG.get();
10478
}
10579
}
Lines changed: 3 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
11
package org.dimdev.vanillafix.client.modsupport;
22

3-
import java.lang.reflect.Field;
4-
import java.lang.reflect.Modifier;
5-
63
import io.github.prospector.modmenu.api.ConfigScreenFactory;
74
import io.github.prospector.modmenu.api.ModMenuApi;
8-
import me.shedaniel.clothconfig2.api.ConfigBuilder;
9-
import me.shedaniel.clothconfig2.api.ConfigCategory;
10-
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
11-
import me.shedaniel.clothconfig2.gui.entries.BooleanListEntry;
12-
import me.shedaniel.clothconfig2.gui.entries.FloatListEntry;
13-
import me.shedaniel.clothconfig2.gui.entries.IntegerListEntry;
14-
import org.dimdev.vanillafix.VanillaFix;
15-
import org.dimdev.vanillafix.util.annotation.Exclude;
16-
17-
import net.minecraft.text.Text;
18-
import net.minecraft.text.TranslatableText;
5+
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
6+
import org.dimdev.vanillafix.util.config.ModConfig;
197

208
import net.fabricmc.api.EnvType;
219
import net.fabricmc.api.Environment;
@@ -24,70 +12,6 @@
2412
public class ModMenuSupport implements ModMenuApi {
2513
@Override
2614
public ConfigScreenFactory<?> getModConfigScreenFactory() {
27-
return (parent) -> {
28-
ConfigBuilder builder = ConfigBuilder.create()
29-
.setParentScreen(parent)
30-
.setSavingRunnable(VanillaFix::save)
31-
.setTitle(new TranslatableText("vanillafix.config.title"));
32-
ConfigEntryBuilder entryBuilder = builder.entryBuilder();
33-
try {
34-
for (Field field : VanillaFix.config().getClass().getDeclaredFields()) {
35-
int mods = field.getModifiers();
36-
if (Modifier.isStatic(mods) || Modifier.isFinal(mods) || Modifier.isTransient(mods) || field.isAnnotationPresent(Exclude.class)) {
37-
continue;
38-
}
39-
String name = field.getName();
40-
ConfigCategory cat = builder.getOrCreateCategory(new TranslatableText("vanillafix.config.category." + name));
41-
Object value = field.get(VanillaFix.config());
42-
for (Field innerField : value.getClass().getDeclaredFields()) {
43-
int innerMods = innerField.getModifiers();
44-
if (Modifier.isStatic(innerMods) || Modifier.isFinal(innerMods) || Modifier.isTransient(innerMods)) {
45-
continue;
46-
}
47-
String innerName = innerField.getName();
48-
Class<?> innerType = innerField.getType();
49-
Text text = new TranslatableText("vanillafix.config.value." + name + "." + innerName);
50-
if (innerType == boolean.class || innerType == Boolean.class) {
51-
BooleanListEntry entry = entryBuilder.startBooleanToggle(text, innerField.getBoolean(value))
52-
.requireRestart()
53-
.setSaveConsumer(bl -> {
54-
try {
55-
innerField.setBoolean(value, bl);
56-
} catch (IllegalAccessException e) {
57-
throw new AssertionError();
58-
}
59-
})
60-
.build();
61-
cat.addEntry(entry);
62-
} else if (innerType == int.class || innerType == Integer.class) {
63-
IntegerListEntry entry = entryBuilder.startIntField(text, innerField.getInt(value))
64-
.requireRestart()
65-
.setSaveConsumer(i -> {
66-
try {
67-
innerField.setInt(value, i);
68-
} catch (IllegalAccessException e) {
69-
throw new AssertionError();
70-
}
71-
}).build();
72-
cat.addEntry(entry);
73-
} else if (innerType == float.class || innerType == Float.class) {
74-
FloatListEntry entry = entryBuilder.startFloatField(text, innerField.getFloat(value))
75-
.requireRestart()
76-
.setSaveConsumer(f -> {
77-
try {
78-
innerField.setFloat(value, f);
79-
} catch (IllegalAccessException e) {
80-
throw new AssertionError();
81-
}
82-
}).build();
83-
cat.addEntry(entry);
84-
}
85-
}
86-
}
87-
return builder.build();
88-
} catch (IllegalAccessException e) {
89-
throw new AssertionError();
90-
}
91-
};
15+
return (parent) -> AutoConfig.getConfigScreen(ModConfig.class, parent).get();
9216
}
9317
}

src/main/java/org/dimdev/vanillafix/util/annotation/Exclude.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/main/java/org/dimdev/vanillafix/util/annotation/Tooltip.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/main/java/org/dimdev/vanillafix/util/config/ModConfig.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,92 @@
11
package org.dimdev.vanillafix.util.config;
22

3-
import blue.endless.jankson.Comment;
4-
import org.dimdev.vanillafix.util.annotation.Exclude;
5-
6-
public class ModConfig {
3+
import me.sargunvohra.mcmods.autoconfig1u.ConfigData;
4+
import me.sargunvohra.mcmods.autoconfig1u.annotation.Config;
5+
import me.sargunvohra.mcmods.autoconfig1u.annotation.ConfigEntry;
6+
import me.sargunvohra.mcmods.autoconfig1u.shadowed.blue.endless.jankson.Comment;
7+
8+
@Config(name = "vanillafix")
9+
public class ModConfig implements ConfigData {
10+
@ConfigEntry.Gui.TransitiveObject
711
public General general = new General();
812

13+
@ConfigEntry.Gui.TransitiveObject
914
public BugFixes bugFixes = new BugFixes();
1015

16+
@ConfigEntry.Gui.TransitiveObject
1117
public ClientOnly clientOnly = new ClientOnly();
1218

13-
@Exclude
19+
@ConfigEntry.Gui.Excluded
1420
public AntiCheat antiCheat = new AntiCheat();
1521

1622
public static class General {
23+
@ConfigEntry.Gui.NoTooltip
1724
@Comment("Improve the profiler by splitting it into more sections")
1825
public boolean profilerImprovements = true;
1926
}
2027

2128
public static class BugFixes {
29+
@ConfigEntry.Gui.NoTooltip
2230
@Comment("Disables loading the spawn chunks when the server starts. This drastically reduces world loading times. As a side effect, invisible chunks may appear for the first few seconds when creating a new world")
2331
public boolean disableInitialChunkLoad = true;
2432

33+
@ConfigEntry.Gui.NoTooltip
2534
@Comment("Compare items by item type rather than NBT when looking for items for the crafting recipe")
2635
public boolean fixRecipeBookIngredientsWithTags = true;
2736

37+
@ConfigEntry.Gui.NoTooltip
2838
@Comment("Updates the fall distance before notifying the block fallen upon that the entity has fallen on it")
2939
public boolean updateFallDistance = true;
3040

41+
@ConfigEntry.Gui.NoTooltip
3142
@Comment("Fixes a bug where the stone shore biome has a different water color than other coastal cold biomes")
3243
public boolean fixStoneShoreColors = true;
3344

45+
@ConfigEntry.Gui.NoTooltip
3446
@Comment("Sets the mob cap for phantoms. Setting this to any negative number will disable phantom check")
3547
public int phantomMobCap = -1;
3648

49+
@ConfigEntry.Gui.NoTooltip
3750
@Comment("Prevent placing sugarcane underwater.")
3851
public boolean underwaterSugarcaneFix = true;
3952

53+
@ConfigEntry.Gui.NoTooltip
4054
@Comment("Prevents consuming of food that is being eaten on death when keepInventory is enabled")
4155
public boolean doNotConsumeFoodOnDeath = true;
4256

57+
@ConfigEntry.Gui.NoTooltip
4358
@Comment("Prevents running commands longer than 255 characters from a sign")
4459
public boolean fixSignCommands = true;
4560
}
4661

4762
public static class ClientOnly {
63+
@ConfigEntry.Gui.NoTooltip
4864
@Comment("Optimizes animated textures by ticking only visible textures. Disabled by default as it currently has quite a few issues")
4965
public boolean optimizedAnimatedTextures = false;
5066

67+
@ConfigEntry.Gui.NoTooltip
5168
@Comment("Allows opening screens when inside a nether portal")
5269
public boolean screenInNetherPortal = true;
5370

71+
@ConfigEntry.Gui.NoTooltip
5472
@Comment("Set the profilers location to \"gui\" from \"texture\" when running gui logic")
5573
public boolean splitScreenAndTextureProfiler = true;
5674

75+
@ConfigEntry.Gui.NoTooltip
5776
@Comment("Makes interdimensional teleportation nearly as fast as same-dimension teleportation by removing the \"Downloading terrain...\" screen")
5877
public boolean fastInterdimensionalTeleportation = true;
5978

79+
@ConfigEntry.Gui.NoTooltip
6080
@Comment("Prevents showing particles that can not be seen")
6181
public boolean cullParticles = true;
6282
}
6383

6484
public static class AntiCheat {
85+
@ConfigEntry.Gui.NoTooltip
6586
@Comment("Prevents players from stepping up one block (stepping does not reduce hunger)")
6687
public boolean fixStepHeight = true;
6788

89+
@ConfigEntry.Gui.NoTooltip
6890
@Comment("Prevents players from being invulnerable during or after a teleport to a new dimension")
6991
public boolean noPlayerInvulnerabilityAfterTeleport = true;
7092
}

src/main/java/org/dimdev/vanillafix/util/serialization/JanksonOps.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
import java.util.Objects;
66
import java.util.stream.Stream;
77

8-
import blue.endless.jankson.JsonArray;
9-
import blue.endless.jankson.JsonElement;
10-
import blue.endless.jankson.JsonNull;
11-
import blue.endless.jankson.JsonObject;
12-
import blue.endless.jankson.JsonPrimitive;
138
import com.google.common.collect.Lists;
149
import com.mojang.datafixers.util.Pair;
1510
import com.mojang.serialization.DataResult;
1611
import com.mojang.serialization.DynamicOps;
1712
import com.mojang.serialization.MapLike;
13+
import me.sargunvohra.mcmods.autoconfig1u.shadowed.blue.endless.jankson.JsonArray;
14+
import me.sargunvohra.mcmods.autoconfig1u.shadowed.blue.endless.jankson.JsonElement;
15+
import me.sargunvohra.mcmods.autoconfig1u.shadowed.blue.endless.jankson.JsonNull;
16+
import me.sargunvohra.mcmods.autoconfig1u.shadowed.blue.endless.jankson.JsonObject;
17+
import me.sargunvohra.mcmods.autoconfig1u.shadowed.blue.endless.jankson.JsonPrimitive;
1818

1919
public enum JanksonOps implements DynamicOps<JsonElement> {
2020
INSTANCE;

0 commit comments

Comments
 (0)