Monday, 9 March 2015

Troubleshooting Block and Item Rendering

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.

Old version of the troubleshooter.

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 Item or 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 (or 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, or the block instance is null.
  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 [MT81].  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;
}

The blue square (see picture above) on blocks which are transparent (or only take up part of the cube) is caused by isOpaqueBlock()==true when it shouldn't be [MT80].

Problems with transparency are often caused by getBlockLayer() [MT82].

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.

Otherwise, it's time to look at the console for error messages related to your block.  Unfortunately, these vary wildly from one version of Forge to the next.
For version 1.8-11.14.1.1334, use this description of symptoms.
For version 1.8-11.14.1.1441 and higher, including Forge 1.8.9, use this description of symptoms.

Alternatively, you could browse the list of common mistakes for simple blocks here, or blocks with variants here.

A good place for a breakpoint:
ModelLoader::VanillaLoader::
public IModel loadModel(ResourceLocation modelLocation)
{
  try {
    return loader.new VanillaModelWrapper(modelLocation, loader.loadModel(modelLocation));
  } catch(IOException e) {
// ADD A BREAKPOINT HERE AND LOOK AT THE EXCEPTION
    if(loader.isLoading) { //ToDo: Make this less gaging, hides missing models..     // holding error until onPostBakeEvent    } else {
      FMLLog.log(Level.ERROR, e, "Exception loading model %s with vanilla loader, skipping", modelLocation);
    }
    return loader.getMissingModel();
  }
}

or in 1.8.9:
ModelLoaderRegistry::getModel(...)
try {
    model = accepted.loadModel(actual);
} catch (IOException e) {
    throw e;   // BREAKPOINT HERE
} catch(Exception e) {
    FMLLog.log(Level.ERROR, e, "Exception loading model %s with loader %s, skipping", location, accepted);  // BREAKPOINT HERE
    model = getMissingModel();
}

and if you are having trouble figuring out where Forge is looking for your assets folder:
public IResource getResource(ResourceLocation location) throws IOException
{
    IResourceManager iresourcemanager = (IResourceManager)this.domainResourceManagers.get(location.getResourceDomain());  // breakpoint here.
--> the resourcemanager will contain the path, eg
C:\Users\TGG\IdeaProjects\MinecraftByExample1-8-9\out\production\MinecraftByExample1-8-9

Items Step 1 - Registration

For ItemBlocks skip to step 2 because this is not relevant unless you are manually registering the ItemBlock (in which case - check your Block is registered before your ItemBlock!).

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, or the item instance is null.
  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

A useful clue is given by the appearance of the item in the inventory and in your hand.

If it looks like this, i.e. 3D, then it is a "missing model".
Missing model

If it looks like this, i.e. 2D, or it has the correct shape but the wrong texture, then it is a "missing texture".  Your block model is being registered and loaded correctly, but the texture filename is probably wrong.
Missing texture
Next step is to look at the console for error messages related to your block.  Unfortunately, these vary wildly from one version of Forge to the next.
For version 1.8-11.14.1.1334, use this description of symptoms.
For version 1.8-11.14.1.1441 and higher, including Forge 1.8.9, use this description of symptoms.

Alternatively, you could browse the list of common mistakes for simple items here, simple itemblocks here, or itemblocks with variants here.

20 comments:

  1. Hey, great blog. Really helpful for transitioning into 1.8, and for new coders. I just want to add another step to troubleshooting textures, that you may or may not have mentioned (I followed the steps accordingly for myself): Make sure that your texture name is correct. Obviously. But here's a fact that I just found out, underscores(_) are not permitted in texture names. Such as in the item model json, the texture path "MODID:items/TEXTURE", TEXTURE must not contain the underscores.

    For example, "MODID:items/ore_Copper" will not work but "MODID:items/oreCopper" will

    I do not know why this is, but for anyone still having problems, it is worth checking your texture names. Anyways keep up with the good work TGG!!

    ReplyDelete
  2. Keen, thanks for the tip, I'll add it...

    ReplyDelete
  3. Model definition for location expansion:Blue_Flower#type=dandelion not found
    What about this Type Json file? Where is that?

    ReplyDelete
  4. http://greyminecraftcoder.blogspot.com.au/2014/12/block-models-18.html

    ReplyDelete
  5. My ItemBlock/Item rendering problem came from not calling super() in the methods of the client proxy. As a result, it seemed that the client proxy, and the resource location assignment happening within, were not being used at all, leaving me with registered Items/Blocks that didn't know how to be ItemBlocks. Trying breakpoints in multiple places helped me figure this out.
    Thanks TGG :)

    avin

    ReplyDelete
  6. Your Block Step 5 saved me. I could not get the textures of a custom crop I made to render. After hours of checking my code over and over again (and the corresponding json files for spelling mistakes), I stumbled upon your guide. After reading that step, I focused fully only on the json files, since I was getting the FileNotFoundException error on the console.

    I had a file named rice_ crops.json instead of rice_crops.json -.- Still though, underscores work for me, I even used them in the blockstate variants json of the crop. I love you <3

    ReplyDelete
    Replies
    1. Yeah that's a pretty subtle one :) Glad I could help

      -TGG

      Delete
  7. Hi TGG :)
    I really like your tutorials, because after some basics like creating a block and an item, you go further. Plus your tuts are up-to-date!
    But I'm facing a problem you didn't mention here. My block itself renders fine, but there seems to be a problem related to "cullface", take a look:
    http://puu.sh/ik9Jd/17c07c8d3c.jpg

    To test, I took your .json from mbe02, and there it also happens:
    http://puu.sh/ikVe3/384ad4112e.jpg

    So the problem lies somewhere else, but I have no idea why :( Could you help?

    Thanks a lot in advance!

    Jerry

    ReplyDelete
  8. Hi Jerry

    Thanks for the feedback :)

    That looks a lot like a Block.isOpaque() problem, i.e. your Block needs to return false from isOpaque() if it doesn't occupy the full cube.

    If that doesn't help, try asking on this forum
    http://www.minecraftforge.net/forum/index.php/board,73.0.html

    Lots of helpful knowledgable folks there.

    -TGG

    ReplyDelete
  9. what does this mean exactly and how do i fix this Model definition for location fm:Staff#inventory not found

    ReplyDelete
  10. Thanks for all of your very helpful posts; this is one of the best sites I've found for sorting through Minecraft 1.8. One tip I wanted to pass along while working this troubleshooter: sequence of registration is important. I was wrestling with a block rendering find when placed, but not in the hand or in inventory. It turned out the problem was that I had the block registration following the ItemBlock registration.


    All the best,

    Max

    ReplyDelete
  11. Keen, thanks for the feedback! That's a useful tip too, I'll add it.

    ReplyDelete
  12. Something ate my previous comment, so I'll try again.

    Another 'gotcha': when using Eclipse, make sure your 'resources' tree is marked as a source folder. If it is not, it won't be included in the build when you try to test in the dev environment, and ALL your textures and JSONs will be missing.

    I felt rather stupid when I figured that one out.

    ReplyDelete
  13. I was having a problem with my item textures, and my player held a 3D magenta/black block, (as per items step 3). I had previously renamed my domain:models/Item folder to domain:models/item (case sensitive) when I spotted this error, but this didn't appear to fix it. Turns out, this did fix it, but Windows didn't bother renaming the folder in the build/resources/main/assets/domain/models folder, as Windows doesn't case about the case of file & directory names. Manually renamed it from Item to item, and my texture started working.

    Probably not an issue on Linux/Mac as item and Item are treated as different directories.

    ReplyDelete
  14. Know anything about this issue? I copied the whole section where the issue is happening.
    [Client thread/ERROR] [FML]: Exception loading blockstate for the variant ea:tut_block#normal:
    java.lang.Exception: Could not load model definition for variant ea:tut_block
    at net.minecraftforge.client.model.ModelLoader.getModelBlockDefinition(ModelLoader.java:293) ~[ModelLoader.class:?]
    at net.minecraft.client.renderer.block.model.ModelBakery.loadBlock(ModelBakery.java:121) ~[ModelBakery.class:?]
    at net.minecraftforge.client.model.ModelLoader.loadBlocks(ModelLoader.java:248) ~[ModelLoader.class:?]
    at net.minecraftforge.client.model.ModelLoader.setupModelRegistry(ModelLoader.java:155) ~[ModelLoader.class:?]
    at net.minecraft.client.renderer.block.model.ModelManager.onResourceManagerReload(ModelManager.java:28) [ModelManager.class:?]
    at net.minecraft.client.resources.SimpleReloadableResourceManager.registerReloadListener(SimpleReloadableResourceManager.java:122) [SimpleReloadableResourceManager.class:?]
    at net.minecraft.client.Minecraft.init(Minecraft.java:541) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:387) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_121]
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_121]
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
    at GradleStart.main(GradleStart.java:26) [start/:?]
    Caused by: java.lang.RuntimeException: Encountered an exception when loading model definition of 'ea:tut_block' from: 'ea:blockstates/tut_block.json' in resourcepack: 'FMLFileResourcePack:Expanded Aesthetics'
    at net.minecraft.client.renderer.block.model.ModelBakery.loadModelBlockDefinition(ModelBakery.java:246) ~[ModelBakery.class:?]
    at net.minecraft.client.renderer.block.model.ModelBakery.loadMultipartMBD(ModelBakery.java:223) ~[ModelBakery.class:?]
    at net.minecraft.client.renderer.block.model.ModelBakery.getModelBlockDefinition(ModelBakery.java:208) ~[ModelBakery.class:?]
    at net.minecraftforge.client.model.ModelLoader.getModelBlockDefinition(ModelLoader.java:289) ~[ModelLoader.class:?]
    ... 20 more

    Any help would be appreciated, as I can't find a solution anywhere. Your tutorial is great, and I've double checked everything, and everything is correct as far as I can tell.

    ReplyDelete
  15. Hi Ryan
    Sorry for the slow reply. I'm way out of practice troubleshooting these issues now, so I don't see it off the top of my head. You could try asking your question here
    http://www.minecraftforge.net/forum/forum/70-modder-support/
    Some very helpful folks there.

    Cheers
    TGG

    ReplyDelete
  16. hey there! Thank you for your help!

    There seems to be a problem. During 1.11 the getRenderType function seems to be depreciated and i cant seem to find its replacement. This is a problem mainly because the block is invisible in the world and i cant seem to find anything else on this subject.

    It would be amazing to get a good idea of where to find the function to call or override after getRendertype() was depreciated.

    Thank you ^-^
    Ian

    ReplyDelete