diff --git a/src/main/java/net/minecraftforge/client/model/ModelLoader.java b/src/main/java/net/minecraftforge/client/model/ModelLoader.java index 017939047..c45f7ee3b 100644 --- a/src/main/java/net/minecraftforge/client/model/ModelLoader.java +++ b/src/main/java/net/minecraftforge/client/model/ModelLoader.java @@ -301,22 +301,20 @@ public final class ModelLoader extends ModelBakery Exception exception = null; try { - model = ModelLoaderRegistry.getModel(file); + model = ModelLoaderRegistry.getModel(memory); } - catch(Exception normalException) + catch (Exception blockstateException) { - // try blockstate json if the item model is missing - FMLLog.log.debug("Item json isn't found for '{}', trying to load the variant from the blockstate json", memory); try { - model = ModelLoaderRegistry.getModel(memory); + model = ModelLoaderRegistry.getModel(file); } - catch (Exception blockstateException) + catch (Exception normalException) { exception = new ItemLoadingException("Could not load item model either from the normal location " + file + " or from the blockstate", normalException, blockstateException); } } - if(exception != null) + if (exception != null) { storeException(memory, exception); model = ModelLoaderRegistry.getMissingModel(memory, exception); diff --git a/src/test/java/net/minecraftforge/debug/client/model/ItemModelConflictTest.java b/src/test/java/net/minecraftforge/debug/client/model/ItemModelConflictTest.java new file mode 100644 index 000000000..4797c95b7 --- /dev/null +++ b/src/test/java/net/minecraftforge/debug/client/model/ItemModelConflictTest.java @@ -0,0 +1,63 @@ +package net.minecraftforge.debug.client.model; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; +import net.minecraftforge.client.event.ModelRegistryEvent; +import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.registry.GameRegistry; +import net.minecraftforge.fml.relauncher.Side; + +@Mod.EventBusSubscriber +@Mod(modid = ItemModelConflictTest.MODID, name = "Test mod for model conflicts", version = "1.0", acceptableRemoteVersions = "*") +public class ItemModelConflictTest +{ + public static final String MODID = "item_model_conflict_test"; + + @GameRegistry.ObjectHolder(MODID + ":item") + public static final Item TEST_ITEM = null; + + @GameRegistry.ObjectHolder(MODID + ":test") + public static final Block TEST_BLOCK = null; + + @SubscribeEvent + public static void registerBlocks(RegistryEvent.Register event) + { + event.getRegistry().register( + new Block(Material.ROCK) + .setRegistryName(MODID, "test") + .setUnlocalizedName(MODID + ".test") + .setCreativeTab(CreativeTabs.BUILDING_BLOCKS) + ); + } + + @SubscribeEvent + public static void registerItems(RegistryEvent.Register event) + { + event.getRegistry().registerAll( + new Item() + .setRegistryName(MODID, "item") + .setUnlocalizedName(MODID + ".item") + .setCreativeTab(CreativeTabs.MISC), + new ItemBlock(TEST_BLOCK) + .setRegistryName(TEST_BLOCK.getRegistryName()) + ); + } + + @Mod.EventBusSubscriber(modid = MODID, value = Side.CLIENT) + public static class ClientEventHandler + { + @SubscribeEvent + public static void registerModels(ModelRegistryEvent event) + { + ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(TEST_BLOCK), 0, new ModelResourceLocation(TEST_BLOCK.getRegistryName(), "normal")); + ModelLoader.setCustomModelResourceLocation(TEST_ITEM, 0, new ModelResourceLocation(MODID + ":test", "inventory")); + } + } +} diff --git a/src/test/resources/assets/item_model_conflict_test/blockstates/test.json b/src/test/resources/assets/item_model_conflict_test/blockstates/test.json new file mode 100644 index 000000000..553763b41 --- /dev/null +++ b/src/test/resources/assets/item_model_conflict_test/blockstates/test.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "item_model_conflict_test:test" } + } +} diff --git a/src/test/resources/assets/item_model_conflict_test/models/block/test.json b/src/test/resources/assets/item_model_conflict_test/models/block/test.json new file mode 100644 index 000000000..a76755136 --- /dev/null +++ b/src/test/resources/assets/item_model_conflict_test/models/block/test.json @@ -0,0 +1,3 @@ +{ + "parent": "minecraft:block/cobblestone" +} diff --git a/src/test/resources/assets/item_model_conflict_test/models/item/test.json b/src/test/resources/assets/item_model_conflict_test/models/item/test.json new file mode 100644 index 000000000..311dda20c --- /dev/null +++ b/src/test/resources/assets/item_model_conflict_test/models/item/test.json @@ -0,0 +1,3 @@ +{ + "parent": "minecraft:item/torch" +}