12
\$\begingroup\$

I would like to know how the animation system works in minecraft. I get a feeling that all the mobs are hardcoded into the game. Did notch really sit there and create the matrices for all the animation bones by hand?

I like recreating games for fun, so I would like to know how he did this. Also, if he truly does hardcode them... is there a better way?

\$\endgroup\$
7
  • 2
    \$\begingroup\$ why do you think he may have hardcoded animations? \$\endgroup\$
    – Ali1S232
    Commented Oct 2, 2011 at 16:51
  • \$\begingroup\$ Seems like this question is only answerable by Notch. \$\endgroup\$
    – House
    Commented Oct 2, 2011 at 18:01
  • 9
    \$\begingroup\$ More to the point, why do you care how Minecraft did it? Do you have an idea on how to accomplish the same thing some other way? \$\endgroup\$
    – Tetrad
    Commented Oct 2, 2011 at 19:37
  • 1
    \$\begingroup\$ minecraftforum.net/topic/361430-181smp-smart-moving The maker of this mod might have an answer for you but animation is not an area of the minecraft code I have looked through before. \$\endgroup\$
    – James
    Commented Oct 3, 2011 at 2:59
  • 1
    \$\begingroup\$ I've looked through the MCP code before, and I'm 99% sure I remember seeing the animations hard-coded. I no longer have minecraft (or even Eclipse) to check, though. \$\endgroup\$ Commented Oct 3, 2011 at 6:28

3 Answers 3

18
+250
\$\begingroup\$

As others have said, yes the models as well as the animations are hard-coded. If you would like to see how this was done, go to the Minecraft Coder Pack wiki.

The package was created to help mod creators to decompile, change and recompile the Minecraft classes. Instructions are included in the readme files which come with the package. The package contains scripts to decompile, recompile, and reobfuscate the game and the server.

The classes you will want to look at are: ModelBase, ModelBiped, and ModelRenderer.

ModelBiped contains the following functions which do the humanoid animations:

public void render(Entity entity, float time, float f1, ...)
{
    setRotationAngles(time, f1, ...);
    ...
}

public void setRotationAngles(float time, float f1, ...)
{
    ...
    bipedRightArm.rotateAngleX = MathHelper.cos(time * 0.6662F + 3.141593F) * 2.0F * f1 * 0.5F;
    bipedLeftArm.rotateAngleX = MathHelper.cos(time * 0.6662F) * 2.0F * f1 * 0.5F;
    ...
}

The arm swings are simply cosine functions. The right arm is offset by PI to make them swing in opposing directions.

graph of the arm swings

I hope that answers your question =)


If you would like more information on how to actually mod Minecraft, then check out this question:

How do I add a custom mob to Minecraft?

\$\endgroup\$
1
  • \$\begingroup\$ Sis! Euclidean rotation :(. \$\endgroup\$ Commented Oct 10, 2011 at 8:04
8
\$\begingroup\$

Models in Minecraft are hard-coded. There is no notion of block hierarchy (only a list of blocks). This means animations are either done procedurally (in a very basic way) or hard-coded values with interpolation.

There are a few editors for Minecraft models like Techne or FMCModeler which allow importing / exporting Minecraft model code for mods, but they don't support animations since it is probably handled differently for each model.

Here's a quick sample generated with FMCModeler:

//variables init:
public ModelRenderer box;

//constructor:
box = new ModelRenderer(0, 0);
box.addBox(0F, 0F, 0F, 16, 16, 16);

//render:
box.render(f5);

A better way to do it would be to build a full block-based modeler with some notions of block hierarchy so you can animate the models with keyframes and interpolation.

I'm currently building a multiplayer game building tool which does just that (among other things, http://craftstud.io/). It already allows building complex static textured models and more is on the way.

Here's a complex model built with CraftStudio As you can see, the blocks are arranged in a tree on the right: https://i.sstatic.net/FRQeV.png

Each block is serialized to disk / over the network with the following data:

  • Unique ID
  • Parent node ID
  • Position (affects descendants)
  • Scale (affects descendants)
  • Angle (affects descendants)
  • Offset from pivot point
  • Block Size
  • Block texture offset (UV coordinates offset for the texturing)

I plan on adding animation support by storing a map with animation names as key and a list of keyframes as value. Each keyframe will be associated with a block and a value to animate. Between keyframes, values should be interpolated (either linearly for position or spherically for angles, search for lerp and slerp).

\$\endgroup\$
0
\$\begingroup\$

Minecraft block models are actually not hardcoded into the game as of 1.8 and can be edited using resource packs. The JSON modeling system is fairly easy to understand and models exist at /models/block. You can then look at the code to see how it interprets the JSON models.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .