From accf6cf218ea27b2471f4c42e8c80086a5ad07cf Mon Sep 17 00:00:00 2001 From: RainWarrior Date: Sun, 17 Jan 2016 01:51:50 +0300 Subject: [PATCH] Fixed missing model error reporting, made block and item variants sort before loading, to make the splash screen info more useful. --- .../resources/model/ModelBakery.java.patch | 24 ++-- .../client/model/ModelLoader.java | 117 +++++++++++------- 2 files changed, 78 insertions(+), 63 deletions(-) diff --git a/patches/minecraft/net/minecraft/client/resources/model/ModelBakery.java.patch b/patches/minecraft/net/minecraft/client/resources/model/ModelBakery.java.patch index f9f5a2c51c..3382ee553b 100644 --- a/patches/minecraft/net/minecraft/client/resources/model/ModelBakery.java.patch +++ b/patches/minecraft/net/minecraft/client/resources/model/ModelBakery.java.patch @@ -9,15 +9,7 @@ } } catch (Exception exception) -@@ -160,6 +160,7 @@ - } - } - } -+ catch (FileNotFoundException e) {} - catch (IOException ioexception) - { - throw new RuntimeException("Encountered an exception when loading model definition of model " + resourcelocation.toString(), ioexception); -@@ -294,6 +295,7 @@ +@@ -294,6 +294,7 @@ protected void func_177592_e() { @@ -25,7 +17,7 @@ this.field_177613_u.put(Item.func_150898_a(Blocks.field_150348_b), Lists.newArrayList(new String[] {"stone", "granite", "granite_smooth", "diorite", "diorite_smooth", "andesite", "andesite_smooth"})); this.field_177613_u.put(Item.func_150898_a(Blocks.field_150346_d), Lists.newArrayList(new String[] {"dirt", "coarse_dirt", "podzol"})); this.field_177613_u.put(Item.func_150898_a(Blocks.field_150344_f), Lists.newArrayList(new String[] {"oak_planks", "spruce_planks", "birch_planks", "jungle_planks", "acacia_planks", "dark_oak_planks"})); -@@ -336,6 +338,10 @@ +@@ -336,6 +337,10 @@ this.field_177613_u.put(Item.func_150898_a(Blocks.field_180390_bo), Lists.newArrayList(new String[] {"oak_fence_gate"})); this.field_177613_u.put(Item.func_150898_a(Blocks.field_180407_aO), Lists.newArrayList(new String[] {"oak_fence"})); this.field_177613_u.put(Items.field_179570_aq, Lists.newArrayList(new String[] {"oak_door"})); @@ -36,7 +28,7 @@ } protected List func_177596_a(Item p_177596_1_) -@@ -352,7 +358,7 @@ +@@ -352,7 +357,7 @@ protected ResourceLocation func_177583_a(String p_177583_1_) { @@ -45,7 +37,7 @@ return new ResourceLocation(resourcelocation.func_110624_b(), "item/" + resourcelocation.func_110623_a()); } -@@ -395,7 +401,7 @@ +@@ -395,7 +400,7 @@ for (Entry entry : this.field_177615_s.entrySet()) { ResourceLocation resourcelocation = (ResourceLocation)entry.getValue(); @@ -54,7 +46,7 @@ ModelBlock modelblock1 = (ModelBlock)this.field_177611_h.get(resourcelocation); if (modelblock1 != null && modelblock1.func_178303_d()) -@@ -453,6 +459,11 @@ +@@ -453,6 +458,11 @@ private IBakedModel func_177578_a(ModelBlock p_177578_1_, ModelRotation p_177578_2_, boolean p_177578_3_) { @@ -66,7 +58,7 @@ TextureAtlasSprite textureatlassprite = (TextureAtlasSprite)this.field_177599_g.get(new ResourceLocation(p_177578_1_.func_178308_c("particle"))); SimpleBakedModel.Builder simplebakedmodel$builder = (new SimpleBakedModel.Builder(p_177578_1_)).func_177646_a(textureatlassprite); -@@ -463,13 +474,13 @@ +@@ -463,13 +473,13 @@ BlockPartFace blockpartface = (BlockPartFace)blockpart.field_178240_c.get(enumfacing); TextureAtlasSprite textureatlassprite1 = (TextureAtlasSprite)this.field_177599_g.get(new ResourceLocation(p_177578_1_.func_178308_c(blockpartface.field_178242_d))); @@ -83,7 +75,7 @@ } } } -@@ -479,9 +490,14 @@ +@@ -479,9 +489,14 @@ private BakedQuad func_177589_a(BlockPart p_177589_1_, BlockPartFace p_177589_2_, TextureAtlasSprite p_177589_3_, EnumFacing p_177589_4_, ModelRotation p_177589_5_, boolean p_177589_6_) { @@ -99,7 +91,7 @@ private void func_177597_h() { this.func_177574_i(); -@@ -722,4 +738,35 @@ +@@ -722,4 +737,35 @@ field_177617_q.field_178317_b = "class generation marker"; field_177616_r.field_178317_b = "block entity marker"; } diff --git a/src/main/java/net/minecraftforge/client/model/ModelLoader.java b/src/main/java/net/minecraftforge/client/model/ModelLoader.java index a9a8158b91..d3a25aeaff 100644 --- a/src/main/java/net/minecraftforge/client/model/ModelLoader.java +++ b/src/main/java/net/minecraftforge/client/model/ModelLoader.java @@ -3,13 +3,12 @@ package net.minecraftforge.client.model; import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; +import java.io.FileNotFoundException; import java.io.IOException; -import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; +import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -78,10 +77,11 @@ import com.google.common.collect.Sets; @SuppressWarnings("deprecation") public class ModelLoader extends ModelBakery { - private final Map stateModels = new HashMap(); - private final Set textures = new HashSet(); - private final Set loadingModels = new HashSet(); + private final Map stateModels = Maps.newHashMap(); + private final Set textures = Sets.newHashSet(); + private final Set loadingModels = Sets.newHashSet(); private final Set missingVariants = Sets.newHashSet(); + private final Map loadingExceptions = Maps.newHashMap(); private IModel missingModel = null; private IModel itemModel = new ItemLayerModel(MODEL_GENERATED); @@ -151,28 +151,31 @@ public class ModelLoader extends ModelBakery return bakedRegistry; } - private ArrayDeque loadingBlockModels = new ArrayDeque(); - private void loadBlocks() { Map stateMap = blockModelShapes.getBlockStateMapper().putAllStateModelLocations(); - Collection variants = Lists.newArrayList(stateMap.values()); + List variants = Lists.newArrayList(stateMap.values()); variants.add(new ModelResourceLocation("minecraft:item_frame", "normal")); //Vanilla special cases item_frames so must we variants.add(new ModelResourceLocation("minecraft:item_frame", "map")); + Collections.sort(variants, new Comparator() + { + public int compare(ModelResourceLocation v1, ModelResourceLocation v2) + { + return v1.toString().compareTo(v2.toString()); + } + }); blockBar = ProgressManager.push("ModelLoader: blocks", variants.size()); - loadingBlockModels.addAll(variants); - loadVariants(variants); + for(ModelResourceLocation variant : variants) + { + loadVariants(ImmutableList.of(variant)); + blockBar.step(variant.toString()); + } ProgressManager.pop(blockBar); } @Override protected void registerVariant(ModelBlockDefinition definition, ModelResourceLocation location) { - if(!loadingBlockModels.isEmpty() && loadingBlockModels.peekFirst() == location) - { - blockBar.step(location.toString()); - loadingBlockModels.removeFirst(); - } Variants variants = null; try { @@ -195,50 +198,54 @@ public class ModelLoader extends ModelBakery } } + private void storeException(ModelResourceLocation location, Exception exception) + { + loadingExceptions.put(location, exception); + } + private void loadItems() { registerVariantNames(); - int size = 0; - ImmutableList items = ImmutableList.copyOf(GameData.getItemRegistry().typeSafeIterable()); - for(Item item : items) + List itemVariants = Lists.newArrayList(); + for(Item item : GameData.getItemRegistry().typeSafeIterable()) { - size += getVariantNames(item).size(); + itemVariants.addAll(getVariantNames(item)); } - itemBar = ProgressManager.push("ModelLoader: items", size); - for(Item item : items) + Collections.sort(itemVariants); + itemBar = ProgressManager.push("ModelLoader: items", itemVariants.size()); + for(String s : itemVariants) { - // default loading - for(String s : (List)getVariantNames(item)) + ResourceLocation file = getItemLocation(s); + ModelResourceLocation memory = getInventoryVariant(s); + itemBar.step(memory.toString()); + IModel model = null; + try { - ResourceLocation file = getItemLocation(s); - ModelResourceLocation memory = getInventoryVariant(s); - itemBar.step(memory.toString()); - IModel model = null; + // default loading + model = getModel(file); + if (model == null) + { + model = getMissingModel(); + } + stateModels.put(memory, model); + } + catch (FileNotFoundException e) + { + // try blockstate json if the item model is missing + FMLLog.fine("Item json isn't found for '" + memory + "', trying to load the variant from the blockstate json"); try { - model = getModel(file); + registerVariant(getModelBlockDefinition(memory), memory); } - catch (IOException e) + catch (Exception exception) { - // Handled by our finally block. - } - finally - { - if (model == null || model == getMissingModel()) - { - FMLLog.fine("Item json isn't found for '" + memory + "', trying to load the variant from the blockstate json"); - try - { - registerVariant(getModelBlockDefinition(memory), memory); - } - catch (Exception exception) - { - FMLLog.getLogger().warn("Unable to load definition " + memory, exception); - } - } - else stateModels.put(memory, model); + storeException(memory, new Exception("Could not load item model either from the normal location " + file + " or from the blockstate", exception)); } } + catch (Exception exception) + { + storeException(memory, exception); + } } ProgressManager.pop(itemBar); @@ -850,6 +857,18 @@ public class ModelLoader extends ModelBakery public void onPostBakeEvent(IRegistry modelRegistry) { IBakedModel missingModel = modelRegistry.getObject(MODEL_MISSING); + for(Map.Entry entry : loadingExceptions.entrySet()) + { + IBakedModel model = modelRegistry.getObject(entry.getKey()); + if(model == null || model == missingModel) + { + FMLLog.getLogger().error("Exception loading model for variant " + entry.getKey(), entry.getValue()); + } + if(model == null) + { + modelRegistry.putObject(entry.getKey(), missingModel); + } + } for(ModelResourceLocation missing : missingVariants) { IBakedModel model = modelRegistry.getObject(missing); @@ -857,6 +876,10 @@ public class ModelLoader extends ModelBakery { FMLLog.severe("Model definition for location %s not found", missing); } + if(model == null) + { + modelRegistry.putObject(missing, missingModel); + } } isLoading = false; }