Sunday 24 May 2015

Troubleshooting Block and Item Rendering (old version)

This is the old version of the troubleshooter (before 1334).

For the newer version, see here.
---------------------------------------------------
It's pretty certain that the first time you try to create a block or an item, it will probably wind up looking like this:

The dreaded missing texture / missing model.

Unfortunately, there are a lot of things you have to get exactly right before your blocks and items will render properly, and it's often not easy to discover what the problem is.

You can find working examples of a simple block (MBE01) and a simple item (MBE10) here.

Alternatively, this troubleshooting flowchart below might help.
**Note*** - it seems that recent updates to Forge have changed the error messages for some of these errors.  If the guide leads you to a dead end, it might be worth checking each of the possible errors to see if it matches yours.  I'll try to update it soonish.

Before you start

If the problem appears after you have been testing your mod for a while, it is worth taking 2 minutes to start Minecraft, generate a new test world, and see if you still have the problem.  Sometimes the remapping of block and item IDs (that happens when you add and remove blocks or items to your mod) can lead to subtle mismatches and very confusing bugs.

Is it a Block problem, an ItemBlock problem,  or an Item problem?

A Block problem will look wrong when you place it in the world, for example

Block problem
An ItemBlock problem will show up when you are holding the block  in your hand or in the inventory.  (An ItemBlock is the Item that represents your Block when it's not in the world, i.e. in the inventory or in your hand.  It is automatically created when you register a Block.)
ItemBlock problem or Item problem
An Item problem looks the same as an ItemBlock problem except that it doesn't have a Block of course.

If you have a Block problem, go to Blocks Step 1 below.
If you have an Item (ItemBlock) problem, go to Items Step 1.
If you have both, solve the Block problem first.

Blocks - Step 1 - Registration

Does your block appear in the creative tabs?  If not, the problem is probably one of the following:
  1. Your Block registration is not being called (must be called during preInitialisation)
    GameRegistry.registerBlock(blockSimple, "mbe01_block_simple");
  2. You have passed the wrong block to registerBlock.
  3. You haven't set the appropriate creative tab in your Block
public BlockSimple()
{
  super(Material.rock);
  this.setCreativeTab(CreativeTabs.tabBlock);   // the block will appear on the Blocks tab in creative}

Blocks - Step 2

If you place your block in the world, can you see it at all?

Invisible block
If you can see the outline, but no block (with or without the blue square), then your Block.getRenderType() is probably wrong.  Either delete it or override to return 3.
// render using a BakedModel (mbe01_block_simple.json --> mbe01_block_simple_model.json)
// not strictly required because the default (super method) is 3.
@Override
public int getRenderType() {
  return 3;
}

Blocks - Step 3 - Check the console for error messages

If you place your block in the world, does it look like this?
Missing block texture / missing block model.
If not, this troubleshooting guide probably won't help you.

If it does look like this, look in the error console for messages which mention your block's name, eg messages like this:
> [22:14:59] [Client thread/WARN]: Unable to load block model: 'minecraftbyexample:block/mbe01_block_simple.json
> [22:15:00] [Client thread/WARN]: Missing model for: minecraftbyexample:mbe01_block_simple.json
> [22:20:06] [Client thread/WARN]: Unable to load variant: normal from from minecraftbyexample:mbe01_block_simple#normal
> [23:12:54] [Client thread/ERROR]: Using missing texture, unable to load minecraft:textures/blocks/mbe01_block_simple_face1.png
java.io.FileNotFoundException: minecraft:textures/blocks/mbe01_block_simple_face1.png

Did you find any?  If so, continue in Step 4.  Otherwise, skip to Step 7.

Blocks - Step 4 - FileNotFoundException?

Does your console contain a FileNotFoundException for your block?
For example

> [22:06:34] [Client thread/WARN]: Unable to load definition minecraftbyexample:mbe01_block_simple#normal
> java.lang.RuntimeException: Encountered an exception when loading model definition of model minecraftbyexample:blockstates/mbe01_block_simple.json
at net.minecraft.client.resources.model.ModelBakery.getModelBlockDefinition(ModelBakery.java:177) ~[ModelBakery.class:?]
> Caused by: java.io.FileNotFoundException: minecraftbyexample:blockstates/mbe01_block_simple.json

If not, go to step 6.  If so, it means that either
  • one of your filenames is wrong, 
  • your block name is wrong (doesn't match your blockstates filename),  
  • one of the filenames in your json files is wrong, 
  • your resources folder structure is wrong, or
  • your resources folder isn't being copied to the right place.

The extra error information will usually tell you what part of the code was looking for the file.  Fix it by looking through the list of causes below.  If you need more help figuring out which part is the problem, see Step 5.

Some notes about getting filenames and folder structure right:

Your project directory structure should look like the one in this example project here.
i.e. src/main/resources/assets/minecraftbyexample/

When you build your project to debug or run it, the resources in these folders will be copied into the build folder
build/classes/main/assets/minecraftbyexample
which is where forge expects to find them.



There are a few reasons things can go wrong, usually one of the following:
  1. You have spelled a folder name incorrectly, check very closely!
  2. You have added .json or .png where it's not required, for example
    {
        "variants": {
            "normal": { "model": "minecraftbyexample:mbe01_block_simple_model.json" }
        }
    }
  3. I'm told that underscores(_) are not permitted in texture names. For example, in a model json, the texture path "MODID:items/TEXTURE", TEXTURE must not contain any underscores. 
  4. When specifying a resource location, or in one of your json files, you have added the wrong domain, or forgotten it entirely.  This will be obvious from the error message, for example
    java.io.FileNotFoundException: misspelleddomain:models/block/mbe01_block_simple_model.json
    {
        "variants": {
            "normal": { "model": "misspelleddomain:mbe01_block_simple_model" }
        }
    }
    or missing entirely
    java.io.FileNotFoundException: minecraft:models/block/mbe01_block_simple_model.json
    {
        "variants": {
            "normal": { "model": "mbe01_block_simple_model" }
        }
    }
    
    
  5. Upper/Lower case must match!  myModFolder is not the same as mymodfolder!
    Your mod ID, all your package names and folder names should be all lower case.  Your filenames can be mixed case if you are careful to be consistent, but it's probably easier to leave them all lower case too.  Especially since if you use GitHub for your project, it ignores your filename case and will cause you all sorts of grief when you try to fix it without realising what's happening.  (Hint: rename myWROngFile.json to dummyname.json, commit, then rename to mywrongfile.json and commit again).
  6. If you are using IntelliJ 14 instead of Eclipse, you should add this line to the bottom of your build.gradle file, otherwise it won't copy your resources to the right place.
    sourceSets { main { output.resourcesDir = output.classesDir } }
    See here for more information.

Blocks Step 5 - tracking down the source of FileNotFoundException 

If you are getting a FileNotFoundException, the console message will also tell you what part of the code was looking for the file.  These are:

Your blockstates.json file is not being found

> [22:06:34] [Client thread/WARN]: Unable to load definition minecraftbyexample:mbe01_block_simple#normal
> java.lang.RuntimeException: Encountered an exception when loading model definition of model minecraftbyexample:blockstates/mbe01_block_simple.json
at net.minecraft.client.resources.model.ModelBakery.getModelBlockDefinition(ModelBakery.java:177) ~[ModelBakery.class:?]
Caused by: java.io.FileNotFoundException: minecraftbyexample:blockstates/mbe01_block_simple.json

Your blockstates file must exactly match the registered name of the block.  It must be stored in the correct folder (see above).

Model name wrong in blockstates file, or model filename wrong or in wrong folder

> [22:14:59] [Client thread/WARN]: Unable to load block model: 'minecraftbyexample:block/mbe01_block_simple_model' for variant: 'minecraftbyexample:mbe01_block_simple#normal'
> java.io.FileNotFoundException: minecraftbyexample:models/block/mbe01_block_simple_model.json
at
> net.minecraft.client.resources.FallbackResourceManager.getResource( FallbackResourceManager.java:70) ~[FallbackResourceManager.class:?]
> [22:15:00] [Client thread/WARN]: Missing model for: minecraftbyexample:mbe01_block_simple#normal
> [22:15:00] [Client thread/WARN]: No weighted models for: minecraftbyexample:mbe01_block_simple#normal

Either the blockstates.json has the wrong name of the model.json file (remember to include the domain using ":"), or your model.json filename is incorrect or in the wrong folder.

Texture filenames incorrect in block model.json file

> [23:12:54] [Client thread/ERROR]: Using missing texture, unable to load minecraftbyexample:textures/blocks/mbe01_block_simple_face1.png
java.io.FileNotFoundException: minecraftbyexample:textures/blocks/mbe01_block_simple_face1.png
at
> net.minecraft.client.resources.FallbackResourceManager.getResource( FallbackResourceManager.java:70) ~[FallbackResourceManager.class:?]

Your block model file has an incorrect filename, or the texture filename is wrong or in the wrong spot.

{
    "parent": "block/cube_all" 
    "textures":{
        "all": { "minecraftbyexample:blocks/mbe01_block_simple_face1" }
} }

Wrong parent model in your block model.json file

> [23:24:26] [Client thread/WARN]: In parent chain: minecraftbyexample:item/mbe01_block_simple -> minecraftbyexample:block/mbe01_block_simple_model -> minecraft:block/cubeerror; unable to load model: 'minecraft:block/cubeerror'
java.io.FileNotFoundException: minecraft:models/block/cubeerror.json
at
> net.minecraft.client.resources.FallbackResourceManager.getResource(FallbackResourceManager.java:70) ~[FallbackResourceManager.class:?]
at net.minecraft.client.resources.model.ModelBakery.loadModel(ModelBakery.java:260) ~[ModelBakery.class:?]
> [23:24:29] [Client thread/WARN]: Missing model for: minecraftbyexample:mbe01_block_simple#normal
> [23:24:29] [Client thread/WARN]: No weighted models for: minecraftbyexample:mbe01_block_simple#normal

{
    "parent": "block/cubeerror" 
    "textures":{
        "all": { "minecraftbyexample:blocks/mbe01_block_simple_face1" }
} }

Blocks - Step 6 - Console errors other than FileNotFoundException

If your texture is missing but there is no FileNotFoundException, it is usually a block variants mismatch problem.  For example

Incorrect variant names in blockstates files

[22:20:06] [Client thread/WARN]: Unable to load variant: normal from minecraftbyexample:mbe01_block_simple#normal
{
    "variants": {
        "not_normal": { "model": "minecraftbyexample:mbe01_block_simple_model" }
    }
}

Variant listing in blockstates.json doesn't match your code blockstate

[22:26:49] [Client thread/WARN]: Unable to load variant: colour=red,facing=north from minecraftbyexample:mbe03_block_variants#colour=red,facing=north

This might be caused by a mismatch in your blockstates.json file

{
"variants": {
       "colour=red,facing=error": { "model": "minecraftbyexample:mbe03_block_variants_model_red"},
        "colour=red,facing=east": { "model": "minecraftbyexample:mbe03_block_variants_model_red", "y": 90 },
       "colour=red,facing=south": { "model": "minecraftbyexample:mbe03_block_variants_model_red", "y": 180 },
        "colour=red,facing=west": { "model": "minecraftbyexample:mbe03_block_variants_model_red", "y": 270 },
     "colour=green,facing=north": { "model": "minecraftbyexample:mbe03_block_variants_model_green" },
 ... etc...
}

or perhaps your  Block.createBlockState() is wrong...
// necessary to define which properties your blocks use
// will also affect the variants listed in the blockstates model file
@Override
protected BlockState createBlockState()
{
  return new BlockState(this, new IProperty[] {WRONGPROPERTY});
}

note also that for blockstates with multiple properties the order  is important, i.e.
colour=red,facing=north 
won't match
facing=north,colour=red

Incorrect filename or resource location in blockstates.json file

[14:14:22] [Client thread/ERROR] [FML]: Model definition for location
      minecraftpoorexample:mbe01_block_simple_model#normal not found
eg
{
    "variants": {
        "normal": { "model": "minecraftpoorexample:mbe01_block_simple_model" }
    }
}

Blocks Step 7 - no console error message

I have only ever seen this happen in two cases:
a) when one of the texture names is missing from the model file.

For example - the cube_all model needs a texture called #all:
{
    "parent": "block/cube_all",
    "textures": {
        "all_wrong": "minecraftbyexample:blocks/mbe13_block_simple_all_faces",
    }
}
i.e. the parent model cube_all defines #all but we haven't provided it.
{
    "parent": "block/cube",
    "textures": {
        "particle": "#all",
        "down": "#all",
        "up": "#all",
        "north": "#all",
        "east": "#all",
        "south": "#all",
        "west": "#all"    }
}

b) when you have forgotten your mod ID from the blockstates file, eg
blockstates.json
{
    "variants": {
        "normal": { "model": "mbe01_block_simple_model" }
    }
}
instead of
{
    "variants": {
        "normal": { "model": "minecraftbyexample:mbe01_block_simple_model" }
    }
}

Blocks Step 8 - No idea.

Ask your question at the forum...  and when you've solved it, post me a comment to tell me what the problem was.

Items Step 1 - Registration

For ItemBlocks this is not relevant, skip to Step 2.  Otherwise - does your Item appear in the creative tabs?  If not, the problem is probably one of the following:
  1. Your Item registration is not being called (must be called during preInitialisation)
    GameRegistry.registerItem(itemSimple, "mbe10_item_simple");
  2. You have passed the wrong item to registerItem.
  3. You haven't set the appropriate creative tab in your Item
public class ItemSimple extends Item
{
  public ItemSimple()
  {
    this.setCreativeTab(CreativeTabs.tabMisc);   // the item will appear on the Miscellaneous tab in creative  }
}

Items Step 2- ItemCameraTransform problem

Does your model have the right appearance, but is the wrong size, is distorted, or is sitting at the wrong angle in the inventory, your hand, or in third person view?

ItemCameraTransform problem
If so, you have a problem with the ItemCameraTransform information in your item model json.  See here for more information.

Otherwise, contine to step 3...

Items Step 3 - Check the console for error messages

Look in the error console for messages which mention your block or item's name, eg messages like this:
> [23:31:17] [Client thread/WARN]: Unable to load item model: 'minecraftbyexample:item/mbe01_block_simple' for item: 'minecraftbyexample:mbe01_block_simple'
java.io.FileNotFoundException: minecraftbyexample:models/item/mbe01_block_simple.json
at
> net.minecraft.client.resources.FallbackResourceManager.getResource( FallbackResourceManager.java:70) ~[FallbackResourceManager.class:?]
at net.minecraft.client.resources.SimpleReloadableResourceManager.getResource(SimpleReloadableResourceManager.java:67) ~[SimpleReloadableResourceManager.class:?]
at net.minecraft.client.resources.model.ModelBakery.loadModel(ModelBakery.java:260) ~[ModelBakery.class:?]
> [23:31:34] [Client thread/WARN]: Missing model for: minecraftbyexample:item/mbe01_block_simple

Did you find any?  If so, continue to Step 4.  Otherwise, skip to Step 6.

Items Step 4- FileNotFoundException

Does your console contain a FileNotFoundException for your Item?
For example

> [23:31:17] [Client thread/WARN]: Unable to load item model: 'minecraftbyexample:item/mbe01_block_simple' for item: 'minecraftbyexample:mbe01_block_simple'
java.io.FileNotFoundException: minecraftbyexample:models/item/mbe01_block_simple.json
at
> net.minecraft.client.resources.FallbackResourceManager.getResource( FallbackResourceManager.java:70) ~[FallbackResourceManager.class:?]
at
> net.minecraft.client.resources.SimpleReloadableResourceManager.getResource( SimpleReloadableResourceManager.java:67) ~[SimpleReloadableResourceManager.class:?]
at net.minecraft.client.resources.model.ModelBakery.loadModel(ModelBakery.java:260) ~[ModelBakery.class:?]

If not, go to step 4.  If so, it means that either
  • For Items: your item model filename doesn't match the registered item name
  • For ItemBlocks: your item model filename doesn't match the registered block name
  • For Items with subtypes (this.setHasSubtypes(true);), you haven't registered the subtype names properly using ModelBakery.addVariantName (see here for an example.)
  • one of the filenames in your json files is wrong, 
  • your resources folder structure is wrong, or
  • your resources folder isn't being copied to the right place.
For general hints about getting folder structures and filenames right, see Blocks Step 4 above.

item model filename or location wrong

> [23:31:17] [Client thread/WARN]: Unable to load item model: 'minecraftbyexample:item/mbe01_block_simple_model' for item: 'minecraftbyexample:mbe01_block_simple'
java.io.FileNotFoundException: minecraftbyexample:models/item/mbe01_block_simple.json

item model.json file contains incorrect parent model filename

> [17:07:34] [Client thread/WARN]: In parent chain: minecraftbyexample:item/mbe01_block_simple -> minecraftbyexample:block/mbe01_block_simple_model_error; unable to load model: 'minecraftbyexample:block/mbe01_block_simple_model_error'
> java.io.FileNotFoundException: minecraftbyexample:models/block/mbe01_block_simple_model_error.json
at 
> net.minecraft.client.resources.FallbackResourceManager.getResource( FallbackResourceManager.java:70) ~[FallbackResourceManager.class:?]
> [17:07:38] [Client thread/WARN]: Missing model for: minecraftbyexample:item/mbe01_block_simple
{
  "parent": "minecraftbyexample:block/mbe01_block_simple_model_error",
  "display": {
    "thirdperson": {
      "rotation": [ 10, -45, 170 ],
      "translation": [ 0, 1.5, -2.75 ],
      "scale": [ 0.375, 0.375, 0.375 ]
    }
  }
}

Item Step 5 - Console errors other than FileNotFoundException

Never got any of these, so can't help there... Ask your question at the forum...  and when you've solved it, post me a comment to tell me what the problem was...

Item Step 6 - No error messages in the console

This is usually caused when the model renderer goes looking for your item model in the registry, but doesn't find it, so it silently substitutes the missing model instead.  Typically this is because you have messed up the registration with the itemModelMesher.

// required in order for the renderer to know how to render your item. 
ModelResourceLocation itemModelResourceLocation = new ModelResourceLocation("minecraftbyexample:mbe10_item_simple", "inventory");
final int DEFAULT_ITEM_SUBTYPE = 0;
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(StartupCommon.itemSimple, DEFAULT_ITEM_SUBTYPE, itemModelResourceLocation);

Typical causes:
  1. Your model registration with the model mesher is not being executed.  It must be done in the init phase (not preinit), and must be done in the client proxy.
  2. The resource location you have specified is incorrect, missing, or in the wrong location.  See Blocks Step 4 above for advice on making sure that the filenames and locations are correct.  Unfortunately, the model mesher doesn't raise any error messages if you get it wrong.
  3. Your Item has subtypes (this.setHasSubtypes(true);), but you haven't properly registered them with
    ModelBakery.addVariantName("mymodid:subtype1", "mymodid:subtype2", etc)
    and for each subtype metadata value:
    ItemModelMesher().register(StartupCommon.itemSimple, ITEM_SUBTYPE_X_METADATA, itemModelResourceLocationSubTypeX);
    See here for a working example.  The ModelResourceLocation for each subtype must match the strings you provided to ModelBakery.  Don't forget the domain i.e. "mymodid:".
If your item has subtypes but you want the registry to ignore metadata, use the "anonymous class" technique below instead
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(itemVariants, 
  new ItemMeshDefinition()     {
      public ModelResourceLocation getModelLocation(ItemStack stack) {
        return new ModelResourceLocation("spawn_egg", "inventory");
      }
    });


A useful breakpoint to solve registration problems is to set a breakpoint at
ItemModelMesher::
public IBakedModel getItemModel(ItemStack stack)
{
    Item item = stack.getItem();
    IBakedModel ibakedmodel = this.getItemModel(item, this.getMetadata(stack));
}

You can then trace in, to compare 1) the model that your item is looking for, against 2) the contents of the registry.  Where they don't match, you can usually see why immediately.

Item Step 7 - Something else?

Ask your question at the forum...  and when you've solved it, post me a comment to tell me what the problem was...

5 comments:

  1. Hey TGG, I got a weird problem where the console suggests that there's a missing file for a variant of the inventory model? Any ideas?

    [Client thread/ERROR] [FML]: Exception loading model for variant colorama:stainedStoneBricks_3#inventory
    java.lang.Exception: Could not load model definition for variant colorama:stainedStoneBricks_3#inventory

    ReplyDelete
    Replies
    1. Hi
      Probably best if you ask your question on the minecraft forum, we can help you figure it out much faster over there.
      http://www.minecraftforge.net/forum/index.php?board=73.0

      -TGG

      Delete
    2. I have the same problem. Did you fixed it yet?

      Delete
  2. HOLY SHIT I SPENT HOURS TRYING TO FIGURE OUT MY FILE NOT FOUND ERROR BUT I WAS JUST ON A VERSION OF INTELLIJ THAT NEEDED THE EXTRA LINE IN GRADLE.BUILD AAAAGGGGGHGHHHHH

    ReplyDelete