Skip to content

Commit ed08ba1

Browse files
committed
fix: position convert in BlockBench 5.0
1 parent fc35a5e commit ed08ba1

File tree

6 files changed

+13
-24
lines changed

6 files changed

+13
-24
lines changed

api/src/main/java/kr/toxicity/model/api/data/blueprint/BlueprintTexture.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ public boolean canBeRendered() {
9595

9696
/**
9797
* Gets model resolution
98+
* @param resolution parent resolution
9899
* @return resolution
99100
*/
100-
public @NotNull ModelResolution resolution() {
101-
return new ModelResolution(uvWidth, uvHeight);
101+
public @NotNull ModelResolution resolution(@NotNull ModelResolution resolution) {
102+
return resolution.width() == image.getWidth() && resolution.height() == image.getHeight() ? new ModelResolution(image.getWidth(), image.getHeight()) : new ModelResolution(uvWidth, uvHeight);
102103
}
103104
}

api/src/main/java/kr/toxicity/model/api/data/raw/ModelKeyframe.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.jetbrains.annotations.Nullable;
1515

1616
import java.util.List;
17+
import java.util.Locale;
1718

1819
import static java.util.Optional.ofNullable;
1920

@@ -62,7 +63,7 @@ public boolean hasPoint() {
6263
*/
6364
public @NotNull VectorInterpolator findInterpolator() {
6465
if (interpolation == null) return VectorInterpolator.defaultInterpolator();
65-
return switch (interpolation.toLowerCase()) {
66+
return switch (interpolation.toLowerCase(Locale.ROOT)) {
6667
case "linear" -> LinearInterpolator.INSTANCE;
6768
case "catmullrom" -> CatmullRomInterpolator.INSTANCE;
6869
case "step" -> StepInterpolator.INSTANCE;

api/src/main/java/kr/toxicity/model/api/data/raw/ModelMeta.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public enum FormatVersion {
4747

4848
@Override
4949
public @NotNull Vector3f convertAnimationPosition(@NotNull Vector3f vector) {
50+
vector.x = -vector.x;
5051
vector.z = -vector.z;
5152
return vector.div(MathUtil.MODEL_TO_BLOCK_MULTIPLIER);
5253
}

api/src/main/java/kr/toxicity/model/api/data/raw/ModelResolution.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package kr.toxicity.model.api.data.raw;
88

99
import org.jetbrains.annotations.ApiStatus;
10-
import org.jetbrains.annotations.NotNull;
1110

1211
/**
1312
* A texture resolution of a model
@@ -19,15 +18,4 @@ public record ModelResolution(
1918
int width,
2019
int height
2120
) {
22-
/**
23-
* Selects correct resolution to use
24-
* @param other another resolution
25-
* @return correct resolution
26-
*/
27-
public @NotNull ModelResolution then(@NotNull ModelResolution other) {
28-
return new ModelResolution(
29-
Math.max(width, other.width),
30-
Math.max(height, other.height)
31-
);
32-
}
3321
}

api/src/main/java/kr/toxicity/model/api/data/raw/ModelUV.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
public record ModelUV(
2121
@NotNull Float4 uv,
2222
float rotation,
23-
@Nullable String texture
23+
@Nullable Integer texture
2424
) {
2525
/**
2626
* Gets json data of uv
@@ -31,12 +31,10 @@ public record ModelUV(
3131
public @NotNull JsonObject toJson(@NotNull ModelBlueprint parent, int tint) {
3232
var object = new JsonObject();
3333
if (texture == null) return object;
34-
int textureIndex = Integer.parseInt(texture);
35-
object.add("uv", uv.div(parent.resolution()
36-
.then(parent.textures().get(textureIndex).resolution())).toJson());
34+
object.add("uv", uv.div(parent.textures().get(texture).resolution(parent.resolution())).toJson());
3735
if (rotation != 0) object.addProperty("rotation", rotation);
3836
object.addProperty("tintindex", tint);
39-
object.addProperty("texture", "#" + textureIndex);
37+
object.addProperty("texture", "#" + texture);
4038
return object;
4139
}
4240
}

api/src/main/java/kr/toxicity/model/api/util/CollectionUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static <E, R> Stream<R> filterIsInstance(@NotNull Collection<E> collectio
6262
@NotNull
6363
@Unmodifiable
6464
public static <E, R> List<R> mapToList(@NotNull Collection<E> collection, @NotNull Function<E, R> mapper) {
65-
return mapToList(collection.stream(), mapper);
65+
return collection.isEmpty() ? Collections.emptyList() : mapToList(collection.stream(), mapper);
6666
}
6767

6868
/**
@@ -89,7 +89,7 @@ public static <E, R> List<R> mapToList(@NotNull Stream<E> stream, @NotNull Funct
8989
*/
9090
@NotNull
9191
public static <E, R extends JsonElement> JsonArray mapToJson(@NotNull Collection<E> collection, @NotNull Function<E, R> mapper) {
92-
return mapToJson(collection.size(), collection.stream(), mapper);
92+
return collection.isEmpty() ? new JsonArray() : mapToJson(collection.size(), collection.stream(), mapper);
9393
}
9494

9595
/**
@@ -234,7 +234,7 @@ public static <K, V, R> Map<K, R> mapValue(@NotNull Map<K, V> original, @NotNull
234234
@NotNull
235235
@Unmodifiable
236236
public static <E, K, V> Map<K, V> associate(@NotNull Collection<E> collection, @NotNull Function<E, K> keyMapper, @NotNull Function<E, V> valueMapper) {
237-
return associate(collection.stream(), keyMapper, valueMapper);
237+
return collection.isEmpty() ? Collections.emptyMap() : associate(collection.stream(), keyMapper, valueMapper);
238238
}
239239

240240
/**
@@ -265,7 +265,7 @@ public static <T> Predicate<T> filterWithWarning(@NotNull Predicate<T> predicate
265265
@NotNull
266266
@Unmodifiable
267267
public static <E, K> Map<K, E> associate(@NotNull Collection<E> collection, @NotNull Function<E, K> keyMapper) {
268-
return associate(collection.stream(), keyMapper);
268+
return collection.isEmpty() ? Collections.emptyMap() : associate(collection.stream(), keyMapper);
269269
}
270270

271271
/**

0 commit comments

Comments
 (0)