For this tutorial I’m assuming that you have Minecraft 1.7.2 and Forge 1060. Also that you have Eclipse installed, with separate projects for your mod and for the decompiled Minecraft code. (If you haven’t got that far yet, then go and Google for some tutorials!) In order to keep the whole tutorial quite clean looking, I’ve put the code for the main classes up on Dropbox – you can find them here:
- For an entity or mob on Minecraft, there are several different classes that you’ll need. I’m adding a bear to my mod, so as I go through, I’ll type it up here. To define the animal itself, you need an entity class, a model class, and a render class. Then you need a class to load it into Minecraft, which is the main mod, along with a proxy class to tell Minecraft where to find the render and model files. And finally you’ll need a language file and a texture for it, all in the right locations in your file structure.
- I use Techne to make the basic models. As it’s a graphical tool I tried to make a vide of me using it. But Bandicam only captures OpenGL or DirectX directly. I set it to screen capture but it came out as nearly 1GB for a five min video that made YouTube timeout on the upload. I might fix it but in the meantime I know there are Techne video tutorials out there. Once you’ve finished your model with Techne, you export two files, a .png texture map and a .java code file.
- The first class I added I called EntityBear. I’m a great believer in not writing more original code than you need to. So I looked for similar classes in the source to copy code from. Based on what I found, I decided to extend EntityAnimal and copy all the code from EntityWolf that doesn’t have anything to do with taming. This will be a first pass through to get it running. When that’s done I’ll change it to make it more personal. Obviously depending on what you’re writing you can extend whatever you want.
- Once I typed ‘extends EntityAnimal’ a whole host of errors popped up so I followed the suggested fixes to put in the function stubs and add the imports.
- Then I copied over the variables and AI code from the wolf code and edited out all the tameable stuff. I also did a general tidy up to rename variables and functions to reference bear not wolf.
- Next I added a ModelBear class that extends ModelBase. I copied in the body of the code from the Techne .java file, from the first ModelRenderer definition down to the SetRotation Function.
- This step took me ages to find. In the constructor, add super.textureHeight=64 and super.textureWidth=128. Or whatever size your texture map is, if it isn’t 64×32. Without this all sorts of weird and unpleasant things happen! Also note that your map size has to be in binary number steps, 32, 64, 128, 256 etc and must be twice as wide as it’s high.
- Just after the head.addbox, I copied the code from the nose and added a head.setTexture(co-ordinates from the nose render constructor).addbox(parameters from the nose.addbox) This will make the nose move with the head. It can also be used for horns, ears, and other bits attached to boxes. Doing this step I realised that you must set the Position of the nose (which is where the blue ball is on Techne) to the same as the head, otherwise all sorts of odd things happen. For a moment I had a bear with a nose that floated in front of its face.
- Then I tidied up the setRotation function by adding an Entity parameter. And I copied over some Render code to make it actually walk and turn its head.
- Next class to create is RenderBear which extends RenderLiving and contains all the detail about where to find the texture map. Looking at the wolf code, you can put clever stuff in here if you want the appearance of your animal to change depending on variables.
- You need to create a directory called textures at the same level as lang and set-up your own structure beneath there. Personally, I just have sub-directory called entity and put all of my files in there as they’re named one for each animal. Then you have to update the texture location variable and it *should* work. I must admit this part took an awful lot of fiddling around with. Another handy hint is to refresh the folder structure each time you make a change. And you need to add the folder structure into your project as well. While we’re on the subject of text files, you can add a line to the en_US.lang file (or whatever language you’re in) to make your spawn egg have a proper name, like Bear instead of entity.Bear.name.
- The texture file from Techne should be quite self-explanatory. Each box, head, leg, etc. has a multicoloured zone that is a flattened cuboid. It is roughly marked F, B, R, L, T and B for Front, Right, Left, Bottom, Top and Back. And they’re colour coded. Load up your favourite graphics editor and make it beautiful!
- So, now we have an Entity class, a Render class and a Model class. Now we need to tell Minecraft what to do with it. In my main mod class, AnimalLoader I have three lines. In my code, I’ve wrapped these up in a function that I can call for each animal I want to add. In order, they add it to the registry of Entities, make it spawn in the world and give it an egg for creative mode.
EntityRegistry.registerModEntity(entity, name, entID, this, 64, 1, true);
EntityRegistry.addSpawn(entity, 200, 1, 8, creature);
EntityList.addMapping(entity, name, entID, eggColour1, eggColour2);
- In theory you can use getUniqueID to get a unique ID but I can’t make it work. So I just started at 255 and count down. Also, in the addSpawn, you can either add a list of biomes or even use some fancy code with a loop and an array but again, that’s for the future. For the minute I’ve left it blank which means it spawns in all biomes.
- Nearly there now – one more file to modify. ClientProxy which should live in the proxy package. We need to add line to the registerRenderers() function:
RenderingRegistry.registerEntityRenderingHandler(EntityBear.class, new RenderBear(new ModelBear(), 0.8F));
I think that’s about it. Once you’ve got all of those classes with no errors, it’s time to fire it up and see how it goes. As I said this is a fairly bare-bones mod for people who’re already writing mods. I do apologise for the state of the code – it’s all pasted in from the Minecraft source and changed. But I know there’s a bit more work to do to make it uniquely my bear and not just a bigger wolf!
Please comment and let me know if you want me to expand on anything.