From da19eda51e1d8ebe45f1e68bfceff14bec5c7141 Mon Sep 17 00:00:00 2001 From: RainWarrior Date: Tue, 27 Oct 2015 18:34:25 +0300 Subject: [PATCH] Provide a IModel for "builtin/generated", fixes #2147 --- .../client/model/ModelLoader.java | 47 ++++++++++++------- .../client/model/ModelLoaderRegistry.java | 6 ++- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/minecraftforge/client/model/ModelLoader.java b/src/main/java/net/minecraftforge/client/model/ModelLoader.java index 3c36588ebf..9217d5bee5 100644 --- a/src/main/java/net/minecraftforge/client/model/ModelLoader.java +++ b/src/main/java/net/minecraftforge/client/model/ModelLoader.java @@ -69,6 +69,7 @@ public class ModelLoader extends ModelBakery private final Set loadingModels = new HashSet(); private final Set missingVariants = Sets.newHashSet(); private IModel missingModel = null; + private IModel itemModel = new ItemLayerModel(MODEL_GENERATED); private boolean isLoading = false; public boolean isLoading() @@ -255,29 +256,36 @@ public class ModelLoader extends ModelBakery // setting parent here to make textures resolve properly if(model.getParentLocation() != null) { - try + if(model.getParentLocation().getResourcePath().equals("builtin/generated")) { - IModel parent = getModel(model.getParentLocation()); - if(parent instanceof VanillaModelWrapper) - { - model.parent = ((VanillaModelWrapper) parent).model; - } - else - { - throw new IllegalStateException("vanilla model '" + model + "' can't have non-vanilla parent"); - } + model.parent = MODEL_GENERATED; } - catch (IOException e) + else { - FMLLog.warning("Could not load vanilla model parent '" + model.getParentLocation() + "' for '" + model + "': " + e.toString()); - IModel missing = ModelLoader.this.getMissingModel(); - if (missing instanceof VanillaModelWrapper) + try { - model.parent = ((VanillaModelWrapper)missing).model; + IModel parent = getModel(model.getParentLocation()); + if(parent instanceof VanillaModelWrapper) + { + model.parent = ((VanillaModelWrapper) parent).model; + } + else + { + throw new IllegalStateException("vanilla model '" + model + "' can't have non-vanilla parent"); + } } - else + catch (IOException e) { - throw new IllegalStateException("vanilla model '" + model + "' has missing parent, and missing model is not a vanilla model"); + FMLLog.warning("Could not load vanilla model parent '" + model.getParentLocation() + "' for '" + model + "': " + e.toString()); + IModel missing = ModelLoader.this.getMissingModel(); + if (missing instanceof VanillaModelWrapper) + { + model.parent = ((VanillaModelWrapper)missing).model; + } + else + { + throw new IllegalStateException("vanilla model '" + model + "' has missing parent, and missing model is not a vanilla model"); + } } } } @@ -630,6 +638,11 @@ public class ModelLoader extends ModelBakery return missingModel; } + public IModel getItemModel() + { + return itemModel; + } + static enum VanillaLoader implements ICustomModelLoader { instance; diff --git a/src/main/java/net/minecraftforge/client/model/ModelLoaderRegistry.java b/src/main/java/net/minecraftforge/client/model/ModelLoaderRegistry.java index ff03a1fb3e..6a8f73ee04 100644 --- a/src/main/java/net/minecraftforge/client/model/ModelLoaderRegistry.java +++ b/src/main/java/net/minecraftforge/client/model/ModelLoaderRegistry.java @@ -64,8 +64,8 @@ public class ModelLoaderRegistry public static IModel getModel(ResourceLocation location) throws IOException { - ResourceLocation actual = getActualLocation(location); if(cache.containsKey(location)) return cache.get(location); + ResourceLocation actual = getActualLocation(location); ICustomModelLoader accepted = null; for(ICustomModelLoader loader : loaders) { @@ -127,5 +127,9 @@ public class ModelLoaderRegistry public static void clearModelCache() { cache.clear(); + // putting the builtin models in + cache.put(new ResourceLocation("minecraft:builtin/generated"), ModelLoader.VanillaLoader.instance.getLoader().getItemModel()); + cache.put(new ResourceLocation("minecraft:block/builtin/generated"), ModelLoader.VanillaLoader.instance.getLoader().getItemModel()); + cache.put(new ResourceLocation("minecraft:item/builtin/generated"), ModelLoader.VanillaLoader.instance.getLoader().getItemModel()); } }