|
1 | 1 | package dev.kinau.resourcepackvalidator.validator.models; |
2 | 2 |
|
| 3 | +import com.google.gson.JsonArray; |
3 | 4 | import com.google.gson.JsonElement; |
4 | 5 | import com.google.gson.JsonObject; |
5 | 6 | import dev.kinau.resourcepackvalidator.ValidationJob; |
|
15 | 16 | import lombok.extern.slf4j.Slf4j; |
16 | 17 |
|
17 | 18 | import java.io.File; |
18 | | -import java.util.*; |
| 19 | +import java.util.ArrayList; |
| 20 | +import java.util.HashMap; |
| 21 | +import java.util.HashSet; |
| 22 | +import java.util.List; |
| 23 | +import java.util.Map; |
| 24 | +import java.util.Optional; |
| 25 | +import java.util.Set; |
19 | 26 | import java.util.stream.Collectors; |
20 | 27 |
|
21 | 28 | @Slf4j |
@@ -114,11 +121,13 @@ private boolean validateTextureData(ModelPathWithSource model, ValidationJob job |
114 | 121 | textureReferences.put(s, textureReferenceWithSource.referenceValue()); |
115 | 122 | }); |
116 | 123 |
|
117 | | - |
118 | 124 | if (!detectReferenceChain(textureData, model, context)) |
119 | 125 | return false; |
120 | 126 |
|
121 | 127 | Set<TextureReferenceWithSource> references = textureData.values().stream().filter(s -> s.referenceValue().startsWith("#")).collect(Collectors.toSet()); |
| 128 | + for (ModelWithSource parent : parents) { |
| 129 | + references.addAll(getFaceReferenceTextures(parent)); |
| 130 | + } |
122 | 131 | if (references.isEmpty()) return true; |
123 | 132 |
|
124 | 133 | boolean failed = false; |
@@ -199,6 +208,28 @@ private Map<String, TextureReferenceWithSource> getTextureData(ModelWithSource m |
199 | 208 | return textureData; |
200 | 209 | } |
201 | 210 |
|
| 211 | + private Set<TextureReferenceWithSource> getFaceReferenceTextures(ModelWithSource modelData) { |
| 212 | + Set<TextureReferenceWithSource> faceTextures = new HashSet<>(); |
| 213 | + |
| 214 | + if (modelData.modelObject().has("elements") && modelData.modelObject().get("elements").isJsonArray()) { |
| 215 | + JsonArray elements = modelData.modelObject().getAsJsonArray("elements"); |
| 216 | + for (JsonElement element : elements) { |
| 217 | + if (!element.isJsonObject()) continue; |
| 218 | + JsonObject elementObj = element.getAsJsonObject(); |
| 219 | + if (!elementObj.has("faces") || !elementObj.get("faces").isJsonObject()) continue; |
| 220 | + JsonObject facesObj = elementObj.getAsJsonObject("faces"); |
| 221 | + for (String face : facesObj.keySet()) { |
| 222 | + if (!facesObj.get(face).isJsonObject()) continue; |
| 223 | + JsonObject faceObj = facesObj.getAsJsonObject(face); |
| 224 | + if (!faceObj.has("texture") || !faceObj.get("texture").isJsonPrimitive() || !faceObj.getAsJsonPrimitive("texture").isString()) continue; |
| 225 | + if (!faceObj.getAsJsonPrimitive("texture").getAsString().startsWith("#")) continue; |
| 226 | + faceTextures.add(new TextureReferenceWithSource(modelData.vanilla(), faceObj.getAsJsonPrimitive("texture").getAsString())); |
| 227 | + } |
| 228 | + } |
| 229 | + } |
| 230 | + return faceTextures; |
| 231 | + } |
| 232 | + |
202 | 233 | private boolean detectReferenceChain(Map<String, TextureReferenceWithSource> textureData, ModelPathWithSource model, FileContext context) { |
203 | 234 | for (TextureReferenceWithSource textureField : textureData.values()) { |
204 | 235 | // a child is already failing, do not fail twice for the parent again |
|
0 commit comments