Fixed error detection login in ModelLoader, reduced the maximum number of printed stack traces to 5 per domain.

This commit is contained in:
RainWarrior 2016-01-20 01:19:38 +03:00
parent 447a87c0c7
commit 17e8de8a3a

View file

@ -81,7 +81,7 @@ public class ModelLoader extends ModelBakery
private final Set<ResourceLocation> textures = Sets.newHashSet(); private final Set<ResourceLocation> textures = Sets.newHashSet();
private final Set<ResourceLocation> loadingModels = Sets.newHashSet(); private final Set<ResourceLocation> loadingModels = Sets.newHashSet();
private final Set<ModelResourceLocation> missingVariants = Sets.newHashSet(); private final Set<ModelResourceLocation> missingVariants = Sets.newHashSet();
private final Map<ModelResourceLocation, Exception> loadingExceptions = Maps.newHashMap(); private final Map<ResourceLocation, Exception> loadingExceptions = Maps.newHashMap();
private IModel missingModel = null; private IModel missingModel = null;
private IModel itemModel = new ItemLayerModel(MODEL_GENERATED); private IModel itemModel = new ItemLayerModel(MODEL_GENERATED);
@ -198,11 +198,25 @@ public class ModelLoader extends ModelBakery
} }
} }
private void storeException(ModelResourceLocation location, Exception exception) private void storeException(ResourceLocation location, Exception exception)
{ {
loadingExceptions.put(location, exception); loadingExceptions.put(location, exception);
} }
@Override
protected ModelBlockDefinition getModelBlockDefinition(ResourceLocation location)
{
try
{
return super.getModelBlockDefinition(location);
}
catch (Exception exception)
{
storeException(location, new Exception("Could not load model definition for variant " + location, exception));
}
return new ModelBlockDefinition(new ArrayList<ModelBlockDefinition>());
}
private void loadItems() private void loadItems()
{ {
registerVariantNames(); registerVariantNames();
@ -864,16 +878,30 @@ public class ModelLoader extends ModelBakery
public void onPostBakeEvent(IRegistry<ModelResourceLocation, IBakedModel> modelRegistry) public void onPostBakeEvent(IRegistry<ModelResourceLocation, IBakedModel> modelRegistry)
{ {
IBakedModel missingModel = modelRegistry.getObject(MODEL_MISSING); IBakedModel missingModel = modelRegistry.getObject(MODEL_MISSING);
for(Map.Entry<ModelResourceLocation, Exception> entry : loadingExceptions.entrySet()) Map<String, Integer> modelErrors = Maps.newHashMap();
for(Map.Entry<ResourceLocation, Exception> entry : loadingExceptions.entrySet())
{ {
IBakedModel model = modelRegistry.getObject(entry.getKey()); // ignoring pure ResourceLocation arguments, all things we care about pass ModelResourceLocation
if(model == null || model == missingModel) if(entry.getKey() instanceof ModelResourceLocation)
{ {
FMLLog.getLogger().error("Exception loading model for variant " + entry.getKey(), entry.getValue()); ModelResourceLocation location = (ModelResourceLocation)entry.getKey();
} IBakedModel model = modelRegistry.getObject(location);
if(model == null) if(model == null || model == missingModel)
{ {
modelRegistry.putObject(entry.getKey(), missingModel); String domain = entry.getKey().getResourceDomain();
Integer errorCountBox = modelErrors.get(domain);
int errorCount = errorCountBox == null ? 0 : errorCountBox;
errorCount++;
if(errorCount < 5)
{
FMLLog.getLogger().error("Exception loading model for variant " + entry.getKey(), entry.getValue());
}
modelErrors.put(domain, errorCount);
}
if(model == null)
{
modelRegistry.putObject(location, missingModel);
}
} }
} }
for(ModelResourceLocation missing : missingVariants) for(ModelResourceLocation missing : missingVariants)
@ -881,13 +909,28 @@ public class ModelLoader extends ModelBakery
IBakedModel model = modelRegistry.getObject(missing); IBakedModel model = modelRegistry.getObject(missing);
if(model == null || model == missingModel) if(model == null || model == missingModel)
{ {
FMLLog.severe("Model definition for location %s not found", missing); String domain = missing.getResourceDomain();
Integer errorCountBox = modelErrors.get(domain);
int errorCount = errorCountBox == null ? 0 : errorCountBox;
errorCount++;
if(errorCount < 5)
{
FMLLog.severe("Model definition for location %s not found", missing);
}
modelErrors.put(domain, errorCount);
} }
if(model == null) if(model == null)
{ {
modelRegistry.putObject(missing, missingModel); modelRegistry.putObject(missing, missingModel);
} }
} }
for(Map.Entry<String, Integer> e : modelErrors.entrySet())
{
if(e.getValue() >= 5)
{
FMLLog.severe("Supressed additional %s model loading errors for domain %s", e.getValue(), e.getKey());
}
}
isLoading = false; isLoading = false;
} }