Skip to content

Commit 26902d5

Browse files
fix order of operations for *Provider wrappers
1 parent 2cb3d3c commit 26902d5

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/main/java/dev/latvian/mods/kubejs/plugin/builtin/wrapper/MiscWrappers.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ private static DataResult<IntProvider> tryWrapIntProvider(Context cx, Object o)
9393
case Map<?, ?> m -> {
9494
Map<String, Object> map = Cast.to(m);
9595

96-
if (hasBounds(map)) {
97-
yield parseIntBounds(map).map(v -> v);
98-
} else if (map.containsKey("clamped")) {
96+
if (map.containsKey("clamped")) {
9997
yield tryWrapIntProvider(cx, map.get("clamped"))
10098
.apply2(MiscWrappers::toClamped, parseIntBounds(map));
10199
} else if (map.containsKey("clamped_normal")) {
102100
yield tryParseInt(map.get("mean"))
103101
.apply3(MiscWrappers::toClampedNormal, tryParseInt(map.get("deviation")), parseIntBounds(map));
102+
} else if (hasBounds(map)) {
103+
yield parseIntBounds(map).map(v -> v);
104104
} else {
105105
yield IntProvider.CODEC.parse(RegistryAccessContainer.of(cx).nbt(), NBTWrapper.wrapCompound(cx, map))
106106
.mapError(error -> "Failed to decode IntProvider from %s: %s".formatted(map, error));
@@ -177,16 +177,16 @@ private static DataResult<UniformFloat> parseFloatBounds(Map<String, Object> m)
177177
}
178178

179179
private static DataResult<IntProvider> intProviderFromMap(Context cx, Map<String, Object> m) {
180-
if (hasBounds(m)) {
181-
return parseIntBounds(m).map(v -> v);
182-
} else if (m.containsKey("clamped")) {
180+
if (m.containsKey("clamped")) {
183181
return tryWrapIntProvider(cx, m.get("clamped")).apply2(MiscWrappers::toClamped, parseIntBounds(m));
184182
} else if (m.containsKey("clamped_normal")) {
185183
return tryParseInt(m.get("mean"))
186184
.apply3(MiscWrappers::toClampedNormal, tryParseInt(m.get("deviation")), parseIntBounds(m));
185+
} else if (hasBounds(m)) {
186+
return parseIntBounds(m).map(v -> v);
187+
} else {
188+
return IntProvider.CODEC.parse(RegistryAccessContainer.of(cx).nbt(), NBTWrapper.wrapCompound(cx, m)).map(v -> v).mapError(error -> "Failed to decode IntProvider from %s: %s".formatted(m, error));
187189
}
188-
189-
return IntProvider.CODEC.parse(RegistryAccessContainer.of(cx).nbt(), NBTWrapper.wrapCompound(cx, m)).map(v -> v).mapError(error -> "Failed to decode IntProvider from %s: %s".formatted(m, error));
190190
}
191191

192192
private static DataResult<NumberProvider> numberProviderFromMap(Context cx, Map<String, Object> m) {
@@ -202,15 +202,15 @@ private static DataResult<NumberProvider> numberProviderFromMap(Context cx, Map<
202202
}
203203

204204
private static DataResult<FloatProvider> floatProviderFromMap(Context cx, Map<String, Object> m) {
205-
if (hasBounds(m)) {
206-
return parseFloatBounds(m).map(v -> v);
207-
} else if (m.containsKey("clamped_normal")) {
205+
if (m.containsKey("clamped_normal")) {
208206
return tryParseInt(m.get("mean"))
209207
.apply3(MiscWrappers::toClampedNormal, tryParseFloat(m.get("deviation")), parseFloatBounds(m));
208+
} else if (hasBounds(m)) {
209+
return parseFloatBounds(m).map(v -> v);
210+
} else {
211+
return FloatProvider.CODEC.parse(RegistryAccessContainer.of(cx).nbt(), NBTWrapper.wrapCompound(cx, m))
212+
.mapError(error -> "Failed to decode FloatProvider from %s: %s".formatted(m, error));
210213
}
211-
212-
return FloatProvider.CODEC.parse(RegistryAccessContainer.of(cx).nbt(), NBTWrapper.wrapCompound(cx, m))
213-
.mapError(error -> "Failed to decode FloatProvider from %s: %s".formatted(m, error));
214214
}
215215

216216
private static boolean hasBounds(Map<String, Object> m) {

0 commit comments

Comments
 (0)