Skip to content

Commit 7cc2d18

Browse files
committed
Created a basic config so people can use this in production.
1 parent 1a4b8e5 commit 7cc2d18

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ yarn_mappings = 1.16.4+build.1
77
loader_version = 0.10.6+build.214
88

99
# Mod Properties
10-
mod_version = 0.0.3
10+
mod_version = 0.1.0
1111
maven_group = dev.hephaestus
1212
archives_base_name = sax
1313

src/main/java/dev/hephaestus/sax/SAX.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public static Identifier id(String... path) {
2222

2323
@Override
2424
public void onInitialize() {
25+
Config.load();
26+
2527
for (Map.Entry<Block, Block> entry : Config.HIDDEN.entrySet()) {
2628
FibLib.Blocks.register(new HideOccludedOre(entry.getKey(), entry.getValue()));
2729
}

src/main/java/dev/hephaestus/sax/server/Config.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
package dev.hephaestus.sax.server;
22

3+
import com.google.gson.Gson;
4+
import com.google.gson.GsonBuilder;
5+
import com.google.gson.JsonElement;
6+
import com.google.gson.JsonObject;
7+
import net.fabricmc.loader.api.FabricLoader;
38
import net.minecraft.block.Block;
49
import net.minecraft.block.Blocks;
10+
import net.minecraft.util.Identifier;
11+
import net.minecraft.util.JsonHelper;
12+
import net.minecraft.util.registry.Registry;
513

14+
import java.io.IOException;
15+
import java.io.Writer;
16+
import java.nio.file.Files;
17+
import java.nio.file.Path;
618
import java.util.HashMap;
19+
import java.util.Map;
720

8-
// Dummy config for now
21+
// Simple config for now
922
public class Config {
23+
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
1024
public static final HashMap<Block, Block> HIDDEN = new HashMap<>();
1125

1226
static {
@@ -19,4 +33,39 @@ public class Config {
1933
HIDDEN.put(Blocks.MOSSY_COBBLESTONE, Blocks.STONE);
2034
HIDDEN.put(Blocks.SPAWNER, Blocks.CAVE_AIR);
2135
}
36+
37+
public static void load() {
38+
Path configDir = FabricLoader.getInstance().getConfigDir().normalize().resolve("sax");
39+
Path configFile = configDir.resolve("blocks.json");
40+
41+
try {
42+
if (!Files.exists(configFile)) {
43+
Files.createDirectories(configDir);
44+
45+
JsonObject jsonObject = new JsonObject();
46+
47+
for (Map.Entry<Block, Block> entry : HIDDEN.entrySet()) {
48+
jsonObject.addProperty(
49+
Registry.BLOCK.getId(entry.getKey()).toString(),
50+
Registry.BLOCK.getId(entry.getValue()).toString()
51+
);
52+
}
53+
54+
Writer writer = Files.newBufferedWriter(configFile);
55+
writer.write(GSON.toJson(jsonObject));
56+
writer.close();
57+
} else {
58+
HIDDEN.clear();
59+
60+
for (Map.Entry<String, JsonElement> element : JsonHelper.deserialize(Files.newBufferedReader(configFile)).entrySet()) {
61+
HIDDEN.put(
62+
Registry.BLOCK.get(new Identifier(element.getKey())),
63+
Registry.BLOCK.get(new Identifier(element.getValue().getAsString()))
64+
);
65+
}
66+
}
67+
} catch (IOException e) {
68+
e.printStackTrace();
69+
}
70+
}
2271
}

0 commit comments

Comments
 (0)