Render Item Basic-1.9

From McJty Modding
Jump to: navigation, search

In order to have a basic model for our first item we need to make a json file and access this. Again there are many approaches that one can follow and this tutorial just presents one possibility:

First we have to extend our item class so that we can initialize where Minecraft can find our model. The name 'inventory' refers to the variant in the json. It is commonly used to indicate the model as it should render in the inventory itself:

public class SimpleTexturedItem extends Item {

    public SimpleTexturedItem() {
        setRegistryName("simpletextureditem");
        setUnlocalizedName(ModTut.MODID + ".simpletextureditem");
        GameRegistry.register(this);
    }

    @SideOnly(Side.CLIENT)
    public void initModel() {
        ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(getRegistryName(), "inventory"));
    }
}

This has to be called from within ClientProxy.preInit so you can add a method for this in ModItems:

public class ModItems{

    public static SimpleTexturedItem simpleTexturedItem;

    public static void init() {
        simpleTexturedItem = new SimpleTexturedItem();
    }

    @SideOnly(Side.CLIENT)
    public static void initModels() {
        simpleTexturedItem.initModel();
    }
}

Now the only thing left to do is to define your json file and add a texture. In this case we just need a single json file located in main/resources/assets/<yourmod>/models/item/simpletextureditem.json:

{
  "parent": "builtin/generated",
  "textures": {
    "layer0": "modtut:items/itemtexture"
  },
  "display": {
    "thirdperson": {
      "rotation": [ -90, 0, 0 ],
      "translation": [ 0, 1, -3 ],
      "scale": [ 0.55, 0.55, 0.55 ]
    },
    "firstperson": {
      "rotation": [ 0, -135, 25 ],
      "translation": [ 0, 4, 2 ],
      "scale": [ 1.7, 1.7, 1.7 ]
    }
  }
}

Then add a texture file called 'itemtexture.png' in the directory main/resources/assets/modtut/textures/items/itemtexture.png