Improve debug-log when loading resources, Fix #128 and Fix #147

This commit is contained in:
Blue (Lukas Rieger) 2021-02-04 18:05:58 +01:00
parent 46bd75a068
commit 29020c7b72
No known key found for this signature in database
GPG Key ID: 904C4995F9E1F800
2 changed files with 49 additions and 29 deletions

View File

@ -256,7 +256,13 @@ public class BlockModelResource {
for (Entry<Object, ? extends ConfigurationNode> entry : config.getNode("textures").getChildrenMap().entrySet()) {
if (entry.getKey().equals(JSON_COMMENT)) continue;
textures.putIfAbsent(entry.getKey().toString(), entry.getValue().getString(null));
String key = entry.getKey().toString();
String value = entry.getValue().getString(null);
if (("#" + key).equals(value)) continue; // skip direct loop
textures.putIfAbsent(key, value);
}
String parentPath = config.getNode("parent").getString();
@ -286,8 +292,10 @@ public class BlockModelResource {
for (String key : textures.keySet()) {
try {
blockModel.textures.put(key, getTexture("#" + key));
} catch (NoSuchElementException | FileNotFoundException ex) {
throw new ParseResourceException("Failed to map Texture key '" + key + "' for model '" + topModelPath + "': " + ex);
} catch (NoSuchElementException | FileNotFoundException ignore) {
// ignore this so unused textures can remain unresolved. See issue #147
//throw new ParseResourceException("Failed to map Texture key '" + key + "' for model '" + topModelPath + "': " + ex);
}
}
@ -365,12 +373,12 @@ public class BlockModelResource {
Face face = element.new Face(direction);
if (!node.getNode("uv").isVirtual()) face.uv = readVector4f(node.getNode("uv"));
face.texture = getTexture(node.getNode("texture").getString());
face.texture = getTexture(node.getNode("texture").getString(""));
face.tinted = node.getNode("tintindex").getInt(-1) >= 0;
face.rotation = node.getNode("rotation").getInt(0);
if (!node.getNode("cullface").isVirtual()) {
String dirString = node.getNode("cullface").getString();
String dirString = node.getNode("cullface").getString("");
if (dirString.equals("bottom")) dirString = "down";
if (dirString.equals("top")) dirString = "up";
@ -409,14 +417,20 @@ public class BlockModelResource {
nodeList.get(3).getFloat(0)
);
}
private Texture getTexture(String key) throws NoSuchElementException, FileNotFoundException, IOException {
return getTexture(key, 0);
}
private Texture getTexture(String key, int depth) throws NoSuchElementException, FileNotFoundException, IOException {
if (key.isEmpty() || key.equals("#")) throw new NoSuchElementException("Empty texture key or name!");
if (depth > 10) throw new NoSuchElementException("Recursive texture-variable!");
if (key.charAt(0) == '#') {
String value = textures.get(key.substring(1));
if (value == null) throw new NoSuchElementException("There is no texture defined for the key " + key);
return getTexture(value);
return getTexture(value, depth + 1);
}
String path = ResourcePack.namespacedToAbsoluteResourcePath(key, "textures") + ".png";

View File

@ -24,23 +24,8 @@
*/
package de.bluecolored.bluemap.core.resourcepack;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.lang3.StringUtils;
import com.flowpowered.math.vector.Vector2f;
import com.flowpowered.math.vector.Vector3i;
import de.bluecolored.bluemap.core.logger.Logger;
import de.bluecolored.bluemap.core.resourcepack.PropertyCondition.All;
import de.bluecolored.bluemap.core.resourcepack.fileaccess.FileAccess;
@ -48,6 +33,15 @@ import de.bluecolored.bluemap.core.util.MathUtils;
import de.bluecolored.bluemap.core.world.BlockState;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.gson.GsonConfigurationLoader;
import org.apache.commons.lang3.StringUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.Map.Entry;
public class BlockStateResource {
@ -193,7 +187,7 @@ public class BlockStateResource {
blockState.variants.add(variant);
} catch (ParseResourceException | RuntimeException e) {
Logger.global.logDebug("Failed to parse a variant of " + blockstateFile + ": " + e);
logParseError("Failed to parse a variant of " + blockstateFile, e);
}
}
@ -212,7 +206,7 @@ public class BlockStateResource {
blockState.multipart.add(variant);
} catch (ParseResourceException | RuntimeException e) {
Logger.global.logDebug("Failed to parse a multipart-part of " + blockstateFile + ": " + e);
logParseError("Failed to parse a multipart-part of " + blockstateFile, e);
}
}
@ -227,14 +221,14 @@ public class BlockStateResource {
try {
models.add(loadModel(modelNode, overrideTextures));
} catch (ParseResourceException ex) {
Logger.global.logDebug("Failed to load a model trying to parse " + blockstateFile + ": " + ex);
logParseError("Failed to load a model trying to parse " + blockstateFile, ex);
}
}
} else if (node.isMap()) {
try {
models.add(loadModel(node, overrideTextures));
} catch (ParseResourceException ex) {
Logger.global.logDebug("Failed to load a model trying to parse " + blockstateFile + ": " + ex);
logParseError("Failed to load a model trying to parse " + blockstateFile, ex);
}
}
@ -392,7 +386,7 @@ public class BlockStateResource {
variant.checkValid();
blockState.variants.add(variant);
} catch (ParseResourceException ex) {
Logger.global.logDebug("Failed to parse a variant (forge/property) of " + blockstateFile + ": " + ex);
logParseError("Failed to parse a variant (forge/property) of " + blockstateFile, ex);
}
}
@ -425,7 +419,7 @@ public class BlockStateResource {
variant.checkValid();
blockState.variants.add(variant);
} catch (ParseResourceException ex) {
Logger.global.logDebug("Failed to parse a variant (forge/straight) of " + blockstateFile + ": " + ex);
logParseError("Failed to parse a variant (forge/straight) of " + blockstateFile, ex);
}
}
@ -445,7 +439,7 @@ public class BlockStateResource {
return false;
}
private class ForgeVariant {
private static class ForgeVariant {
public Map<String, String> properties = new HashMap<>();
public ConfigurationNode node = GsonConfigurationLoader.builder().build().createEmptyNode();
@ -462,5 +456,17 @@ public class BlockStateResource {
}
}
private static void logParseError(String message, Throwable throwable) {
Logger.global.logDebug(message);
while (throwable != null){
String errorMessage = throwable.getMessage();
if (errorMessage == null) errorMessage = throwable.toString();
Logger.global.logDebug(" > " + errorMessage);
throwable = throwable.getCause();
}
}
}
}