Like all 3D games, there is a need for "models" that describe the shape of the various things that should be displayed, and "renderers" that actually convert the shape into something visible.
Note that Minecraft uses Light-Weight Java Graphics Library (LWJGL) interface also called GL11, so inside rendering classes you can apply related operations and transformations to modify the rendering.
Historically, there are various types of models and rendering options available. In the most original format, the models were simply a collection of cubes that could be rotated and textured to create the classical Minecraft blocky look. However, since then the approach has changed to allow more complex model formats (like those used by computer graphics programs), as well as animations and state-based rendering.
I cover a few tips here, but it is a broad topic for which you may need to do further Googling.
How Models For Blocks And Items Load
Choonster has a good explanation in his github documentation.
The block model format approach has changed over the various versions of Minecraft and this causes a great amount of work when upgrading your mod, and it greatly complicated making animated models. An explanation of the evolution of the block model approach is described well by williewillus in his Rendering Primer.
Thanks to Choonster for this information.
Forge has an animation system for baked models in the net.minecraftforge.client.model.animation package, though there's not a lot of documentation on it.
RainWarrior briefly described the purpose of each class in the commit that introduced the system. They've also documented the grammar of the Animation State Machine files here.
Forge has a test mod for the system here.
Good Tutorial On How Transparency And Blending Works
This tutorial gives a thorough explanation of GL11 and alpha blending.
Rendering Transparent Blocks
See a detailed explanation: TheGreyGhost's Transparent Block Tutorial
Model Texture Mapping For Entities
There is a good tutorial here: Schwarzeszeux's Modeling Tutorial
Creating Complex Animated Entity Models
Here is Jabelar's Complex Animated Models tutorial. It uses the classic built-in modeling system.
Scaling An Entity Model
In your entity model's render() function you can use GL11 methods to scale the model before rendering. However, since the model origin is at 1.5 blocks above the ground, if you just scale the feet of your model will go into the ground if you scale bigger and will float above the ground if you scale smaller. So you need to also use GL11 to translate the method.
Also, you need to create a GL11 matrix for this with the push() method, and need to make sure to pop() the matrix when done.
Putting it all together, the code should look something like this:
Changing The Camera Position
It is common for modders to want to change the "camera" position. In other words, show a view from the world from a different position and/or angle. For example, you could add a "roll" effect while doing a flying mod, or you could shake the camera for an earthquake.
In 1.8, they added a CameraUpdateEvent which can be used to change the position and angle of the camera. See Jabelar's Events Tutorial for more on how to use an event.
Finding Color Of A Pixel
In computer systems, color is often represented as "RGB" (Red-Green-Blue) which is the additive colors that can be used to combine to create all colors. In hexadecimal it is usually shown as an 8-digit number, with each two digits representing the amount of red, green and blue respectively. The higher the number the more of the color is present, and since the color is additive it also gets lighter. So black is 0x000000 (0x is the way Java indicates a number is in hexadecimal format), white is 0xFFFFFF, medium red is 0xCC0000, and a brown might be 0xCC6600. Check out this page of RGB colors to better understand.
Java has a class called BufferImage that is used within Minecraft. Buffered image has a method called getRGB() where you specify the x and y coordinates (starting in top-left) and it returns the RGB int value.
Minecraft already has certain images and textures in BufferedImage instances, but if you want to load a file into a BufferedImage you can use the javax.imageio.ImageIO.read() function where you pass the File parameter which can be PNG, JPG, etc. Check out my tutorial on file and resources for more information.
Warning: In Minecraft most texture information is only on the client side. If you want the server to react or control textures then you will need to use custom packets to communicate between client and server.
Render A Sphere
Thanks to jajo_11 for this tip.
GL11 of course has the ability to render spheres, it's just that Minecraft intentionally tries to be blocky and so doesn't tend to do so. To render a sphere you need to create a "call list" for the sphere, then in an appropriate render function use the GL11.glCallList() function to invoke it.
In this example, I'll create a sphere around a custom entity. The sphere will be partially transparent, and if you enter the sphere you'll be able to see it from the inside as well (this is important point because extra work is required to make that happen).
Since in Minecraft rendering is client side only, it is good idea to make the sphere call lists in the client proxy.
First we need to add two integer fields that will reference the id of the call list for the outside and inside of the sphere. Something like this in your client proxy class:
Then, in your method that handles the init FML life cycle, you should have something like this to generate the call lists:
Now, we'll be able to invoke these spheres during rendering.
The texture you reference with the ResourceLocation should generally be a solid square of color without any transparent portions, but you should try textures and patterns if you think it is better for your mod. I choose a purple color and just filled in a square then saved as PNG. You need to make sure you put the texture asset in the same place referenced in the ResourceLocation.
For a custom entity you should have a custom Renderer class registered for the entity. In that custom Renderer class, you can overrride the passSpecialRender() method which is intended for these extra rendering effects (it is automatically called for all entities). So something like this:
To understand the code, it is best to read up on the G11 API.
The important methods to understand are the glScale(), which in this case we're making 3 times bigger than standard block. You can change the values to get the size you want.
The glColor4f() is blending white (meaning no change in color) with alpha (transparency) of 0.5F. You can play with the alpha value to get the effect you want.
You can see we use glCallList() for both the outside and inside sphere.
Making A Healthbar Over Mob (Like Boss)
It is very easy to get health bar. First, you should just have your mob implement tge IBossDisplayData interface (just put "implements IBossDisplayData" on your class declaration.
Secondly, in the custom Renderer class for your mob, in the PreRenderCallback() method you should put "BossStatus.setBossStatus(entity, true)" where you replace "entity" with the field that represents the entity parameter passed to the PreRenderCallback() method.
Ensuring Custom Entity Renders If Partially Out Of View
In computer graphics, it usually doesn't make sense to process things that are outside the field of view. The space that represents a clipped pyramid of view is called the "frustum". The process of deciding whether something is inside the frustum (and should be rendered) is called frustum culling.
In Minecraft, whether and entity is considered inside the frustum is based on the bounding box of the entity (in the isBoundingBoxInFrustum() method in the Frustum class). This causes a problem with large entities or unusual custom entities though because the model of an entity might extend well beyond the bounding box -- imagine a tail of a dinosaur that has the collision box just on its body. This causes a visual problem because if the entity goes to the edge of the view it will seem to suddenly disappear when the bounding box goes off screen even if other parts of the model could still be rendered on screen.
Therefore, entities have a public boolean field called ignoreFrustumCheck. This should be set to true for those entities that have models that extend significantly beyond the bounding box of the entity.
Draw The Texture Of An Item
See my modding tips for Items.
A Useful Utility Function For Debugging GL11
G11 works on a stack and so you can easily lose track of the applied methods if you forget to pop the stack, letting previous setting "bleed" into later code and causing unexpected effects. Therefore it can be useful to report all GL11 settings in effect at a given point in time.
Here is a utility written by TheGreyGhost and previously posted on github (although link now shows file not found). Since he offered it before, I hope he doesn't mind if I post it here. The idea is simple, but credit to him for taking the time to type it all out.
Tip: You can add this class to your mod and call the dumpAllIsEnabled() method at points in your code where you're debugging GL11.