parse 26.x texture objects in block models (redstone, glass, panes)

Since 26.x a model texture can be an object {"sprite": ..., "force_translucent": ...}
instead of a string. The block-model DTO only accepted strings, so those
models failed to load and rendered as the grey fallback cube: redstone
wire and every glass block and pane (110 models). Accept both forms in
ModelResolver (shared with ItemGeometry).

Edge-case test plugin: redstone/glass scene.
This commit is contained in:
MineTec committed 2026-11-04 13:28:10 +01:00
1 parent 9e59435e13
commit 73e521131b
4 files changed
+37 -9

No files matched your search

@@ -29,6 +29,16 @@ public final class ModelResolver {
return resolved;
}
/** A texture value: a plain reference, or the {@code sprite} of a 26.x texture object; null otherwise. */
public static String textureRef(com.google.gson.JsonElement v) {
if (v == null) return null;
if (v.isJsonPrimitive()) return v.getAsString();
if (v.isJsonObject() && v.getAsJsonObject().has("sprite")) {
return v.getAsJsonObject().get("sprite").getAsString();
}
return null;
}
private FlatModel resolve(ResourceLocation modelId, int depth) {
ModelFileDto dto =
reader.readJson(AssetPaths.model(modelId), ModelFileDto.class).orElse(null);
@@ -47,7 +57,10 @@ public final class ModelResolver {
}
}
if (dto.textures != null) {
textures.putAll(dto.textures);
dto.textures.forEach((key, value) -> {
String ref = textureRef(value);
if (ref != null) textures.put(key, ref);
});
}
return new FlatModel(textures, elements);
@@ -1,5 +1,6 @@
package eu.mhsl.minecraft.pixelpics.assets.dto;
import com.google.gson.JsonElement;
import java.util.List;
import java.util.Map;
@@ -9,7 +10,8 @@ import java.util.Map;
*/
public class ModelFileDto {
public String parent;
public Map<String, String> textures;
// Values are texture refs ("block/stone", "#side") or, since 26.x, objects {"sprite": …, "force_translucent": …}.
public Map<String, JsonElement> textures;
public List<ElementDto> elements;
public static class ElementDto {
@@ -6,6 +6,7 @@ import com.google.gson.JsonObject;
import eu.mhsl.minecraft.pixelpics.assets.AssetPaths;
import eu.mhsl.minecraft.pixelpics.assets.AssetReader;
import eu.mhsl.minecraft.pixelpics.assets.BlockModelRegistry;
import eu.mhsl.minecraft.pixelpics.assets.ModelResolver;
import eu.mhsl.minecraft.pixelpics.assets.ResourceLocation;
import eu.mhsl.minecraft.pixelpics.assets.TextureCache;
import eu.mhsl.minecraft.pixelpics.assets.model.Direction;
@@ -183,13 +184,7 @@ public final class ItemGeometry {
if (mo.has("textures")) {
for (Map.Entry<String, JsonElement> e :
mo.getAsJsonObject("textures").entrySet()) {
JsonElement v = e.getValue();
// 26.x textures may be objects ({"sprite": …, "force_translucent": …}).
String val = v.isJsonPrimitive()
? v.getAsString()
: (v.isJsonObject() && v.getAsJsonObject().has("sprite")
? v.getAsJsonObject().get("sprite").getAsString()
: null);
String val = ModelResolver.textureRef(e.getValue());
if (val != null) tex.putIfAbsent(e.getKey(), val);
}
}