Skip to content

Commit 2a886da

Browse files
committed
optional fields
1 parent 5dbb7ff commit 2a886da

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/main/java/net/just_s/sds/config/Config.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.just_s.sds.config;
22

3+
import com.google.gson.stream.JsonWriter;
34
import com.mojang.serialization.JsonOps;
45
import net.just_s.sds.SDSMod;
56
import net.minecraft.block.Block;
@@ -41,7 +42,9 @@ protected static void deserialize(JsonElement element) {
4142
public static void save() {
4243
JsonElement json = serialize();
4344
try (FileWriter w = new FileWriter(configFile)) {
44-
GSON.toJson(json, w);
45+
final JsonWriter jw = GSON.newJsonWriter(w);
46+
jw.setIndent("\t");
47+
GSON.toJson(json, jw);
4548
SDSMod.LOGGER.info("Saved new config file.");
4649
} catch (IOException e) {SDSMod.LOGGER.error("Error while saving:" + e.getMessage());}
4750
}

src/main/java/net/just_s/sds/config/SDSConfig.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public SDSConfig() {
2323
this(
2424
new Rules(
2525
List.of(
26-
new Entry("iron_bars", Map.of()),
26+
new Entry("iron_bars"),
2727
new Entry("bamboo", Map.of(
2828
"leaves", List.of("none", "large"),
2929
"age", List.of("all")
@@ -32,10 +32,10 @@ public SDSConfig() {
3232
),
3333
Map.of(),
3434
List.of(
35-
new Entry("stairs", Map.of()),
36-
new Entry("walls", Map.of()),
37-
new Entry("c:glass_panes", Map.of()),
38-
new Entry("fences", Map.of()),
35+
new Entry("stairs"),
36+
new Entry("walls"),
37+
new Entry("c:glass_panes"),
38+
new Entry("fences"),
3939
new Entry("slabs", Map.of(
4040
"type", List.of("top", "bottom")
4141
)
@@ -108,10 +108,14 @@ public record Entry(
108108
static Codec<Entry> CODEC = RecordCodecBuilder.create(
109109
instance -> instance.group(
110110
Codec.STRING.fieldOf("id").forGetter(Entry::id),
111-
Codec.unboundedMap(Codec.STRING, Codec.list(Codec.STRING)).fieldOf("properties").forGetter(Entry::properties)
111+
Codec.unboundedMap(Codec.STRING, Codec.list(Codec.STRING)).optionalFieldOf("properties", Map.of()).forGetter(Entry::properties)
112112
).apply(instance, Entry::new)
113113
);
114114

115+
public Entry(String id) {
116+
this(id, Map.of());
117+
}
118+
115119
public boolean isEmpty() {
116120
return properties == null || properties.isEmpty();
117121
}

0 commit comments

Comments
 (0)