tangled
alpha
login
or
join now
codexarchonic.nekoweb.org
/
ProjectInfinity
0
fork
atom
Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.
0
fork
atom
overview
issues
6
pulls
pipelines
Start futureproofing NbtUtils
cassian.cc
9 months ago
073e226b
1773b655
+39
-18
3 changed files
expand all
collapse all
unified
split
common
src
main
java
net
lerariemann
infinity
options
InfinityOptions.java
util
core
NbtUtils.java
RandomProvider.java
+5
-4
common/src/main/java/net/lerariemann/infinity/options/InfinityOptions.java
···
5
5
import net.lerariemann.infinity.InfinityMod;
6
6
import net.lerariemann.infinity.access.InfinityOptionsAccess;
7
7
import net.lerariemann.infinity.util.core.CommonIO;
8
8
+
import net.lerariemann.infinity.util.core.NbtUtils;
8
9
import net.minecraft.client.MinecraftClient;
9
10
import net.minecraft.nbt.NbtCompound;
10
11
import net.minecraft.nbt.NbtElement;
···
31
32
32
33
public InfinityOptions(NbtCompound data) {
33
34
this.data = data;
34
34
-
this.shifter = PitchShifter.decode(test(data, "pitch_shift", new NbtCompound()));
35
35
-
this.effect = EffectGiver.of(test(data, "effect", new NbtCompound()));
36
36
-
this.iridMap = IridescentMap.decode(test(data, "iridescent_map", new NbtCompound()));
35
35
+
this.shifter = PitchShifter.decode(NbtUtils.getCompound(data, "pitch_shift", new NbtCompound()));
36
36
+
this.effect = EffectGiver.of(NbtUtils.getCompound(data, "effect", new NbtCompound()));
37
37
+
this.iridMap = IridescentMap.decode(NbtUtils.getCompound(data, "iridescent_map", new NbtCompound()));
37
38
this.mavity = test(data, "mavity", 1.0);
38
39
this.timeScale = test(data, "time_scale", 1.0);
39
40
this.haunted = test(data, "haunted", false);
···
81
82
}
82
83
83
84
public NbtCompound getShader() {
84
84
-
return test(data, "shader", new NbtCompound());
85
85
+
return NbtUtils.getCompound(data, "shader", new NbtCompound());
85
86
}
86
87
87
88
public double getTimeScale() {
+20
-1
common/src/main/java/net/lerariemann/infinity/util/core/NbtUtils.java
···
12
12
static String test(NbtCompound data, String key, String def) {
13
13
return data.contains(key, NbtElement.STRING_TYPE) ? data.getString(key) : def;
14
14
}
15
15
-
static NbtCompound test(NbtCompound data, String key, NbtCompound def) {
15
15
+
static NbtCompound getCompound(NbtCompound data, String key, NbtCompound def) {
16
16
return data.contains(key, NbtElement.COMPOUND_TYPE) ? data.getCompound(key) : def;
17
17
}
18
18
static float test(NbtCompound data, String key, float def) {
···
26
26
}
27
27
static boolean test(NbtCompound data, String key, boolean def) {
28
28
return data.contains(key) ? data.getBoolean(key) : def;
29
29
+
}
30
30
+
31
31
+
static String getString(NbtCompound data, String key) {
32
32
+
return data.getString(key);
33
33
+
}
34
34
+
static NbtCompound getCompound(NbtCompound data, String key) {
35
35
+
return data.getCompound(key);
36
36
+
}
37
37
+
static float getFloat(NbtCompound data, String key) {
38
38
+
return data.getFloat(key);
39
39
+
}
40
40
+
static int getInt(NbtCompound data, String key) {
41
41
+
return data.getInt(key);
42
42
+
}
43
43
+
static double getDouble(NbtCompound data, String key) {
44
44
+
return data.getDouble(key);
45
45
+
}
46
46
+
static boolean getBoolean(NbtCompound data, String key) {
47
47
+
return data.getBoolean(key);
29
48
}
30
49
31
50
static String elementToName(NbtElement e) {
+14
-13
common/src/main/java/net/lerariemann/infinity/util/core/RandomProvider.java
···
117
117
118
118
void readRootConfig() {
119
119
NbtCompound rootConfig = CommonIO.read(configPath.resolve("infinity.json"));
120
120
-
portalKey = rootConfig.getString("portalKey");
121
121
-
salt = rootConfig.getString("salt");
122
122
-
NbtCompound gameRules = rootConfig.getCompound("gameRules");
120
120
+
portalKey = NbtUtils.getString(rootConfig, "portalKey");
121
121
+
salt = NbtUtils.getString(rootConfig, "salt");
122
122
+
NbtCompound gameRules = NbtUtils.getCompound(rootConfig, "gameRules");
123
123
for (String s: gameRules.getKeys()) {
124
124
NbtElement elem = gameRules.get(s);
125
125
if (elem!=null) {
126
126
-
if (elem.getType() == NbtElement.INT_TYPE) gameRulesInt.put(s, gameRules.getInt(s));
127
127
-
if (elem.getType() == NbtElement.DOUBLE_TYPE) gameRulesDouble.put(s, gameRules.getDouble(s));
126
126
+
if (elem.getType() == NbtElement.INT_TYPE) gameRulesInt.put(s, NbtUtils.getInt(gameRules, s));
127
127
+
if (elem.getType() == NbtElement.DOUBLE_TYPE) gameRulesDouble.put(s, NbtUtils.getDouble(gameRules, s));
128
128
else this.gameRules.put(s, gameRules.getBoolean(s));
129
129
}
130
130
}
131
131
-
NbtCompound rootChances = rootConfig.getCompound("rootChances");
131
131
+
NbtCompound rootChances = NbtUtils.getCompound(rootConfig, "rootChances");
132
132
for (String c: rootChances.getKeys()) {
133
133
-
for (String s: rootChances.getCompound(c).getKeys()) {
134
134
-
this.rootChances.put(s, rootChances.getCompound(c).getDouble(s));
133
133
+
var compound = NbtUtils.getCompound(rootChances, c);
134
134
+
for (String s: compound.getKeys()) {
135
135
+
this.rootChances.put(s, NbtUtils.getDouble(compound, s));
135
136
}
136
137
}
137
138
138
138
-
NbtList disabledDimensions = rootConfig.getList("disabledDimensions", 8);
139
139
+
NbtList disabledDimensions = rootConfig.getList("disabledDimensions", NbtElement.STRING_TYPE);
139
140
for (NbtElement jsonElement : disabledDimensions) {
140
141
this.disabledDimensions.add(jsonElement.asString());
141
142
}
···
149
150
List<NbtCompound> blocksFeatures = new ArrayList<>();
150
151
List<NbtCompound> fullBlocksWG = new ArrayList<>();
151
152
for (NbtCompound block : blocksSettings) {
152
152
-
NbtCompound data = NbtUtils.test(block, "data", new NbtCompound());
153
153
+
NbtCompound data = NbtUtils.getCompound(block, "data", new NbtCompound());
153
154
boolean isfull, istop, isfloat, islaggy;
154
155
isfull = popBlockData(data, "full", false);
155
156
islaggy = popBlockData(data, "laggy", false);
···
181
182
List<NbtCompound> cleanMobs = new ArrayList<>();
182
183
for (ConfigType type : ConfigType.mobCategories) byCategory.put(type, new ArrayList<>());
183
184
for (NbtCompound mob : allmobs) {
184
184
-
String group = mob.getCompound("data").getString("Category");
185
185
+
String group = NbtUtils.getString(NbtUtils.getCompound(mob, "data"), "Category");
185
186
mob.remove("data");
186
187
ConfigType type = ConfigType.byName(group);
187
188
if (type != null) {
···
218
219
219
220
public NbtCompound blockToProvider(NbtCompound block, Random random) {
220
221
NbtCompound res = new NbtCompound();
221
221
-
boolean isRotatable = Registries.BLOCK.get(Identifier.of(block.getString("Name"))).getDefaultState().getProperties().contains(Properties.AXIS);
222
222
+
boolean isRotatable = Registries.BLOCK.get(Identifier.of(NbtUtils.getString(block, "Name"))).getDefaultState().getProperties().contains(Properties.AXIS);
222
223
res.putString("type", isRotatable && roll(random, "rotate_blocks") ?
223
224
"minecraft:rotated_block_provider" : "minecraft:simple_state_provider");
224
225
res.put("state", block);
···
257
258
registry.remove(ConfigType.BIOMES);
258
259
List<NbtCompound> biomes = CommonIO.readCategory(ConfigType.BIOMES);
259
260
Registry<Biome> reg = s.get(RegistryKeys.BIOME);
260
260
-
registerCategory(ConfigType.BIOMES, biomes.stream().filter(comp -> reg.containsId(Identifier.of(comp.getString("Name")))).toList());
261
261
+
registerCategory(ConfigType.BIOMES, biomes.stream().filter(comp -> reg.containsId(Identifier.of(NbtUtils.getString(comp,"Name")))).toList());
261
262
}
262
263
}