Friday, 27 January 2012

Minecraft Rotator Mod.

A while ago, during my exams or maybe just before my exams, there was a post on reddit, which I will link below.

http://www.reddit.com/r/ModdingMC/comments/o0e9p/reorient_pumpkins_with_wrench

This is quite an interesting project because my previous experience with modding is adding new blocks with fancy textures. I havnt dealt with rotation before. So let us disguss what makes a rotated object different.
 Here is a stair block in minecraft:

Hosted at imgur


Here are the 4 stairs, pointing in all sorts of magical directions. But what about them is different??
As all good (and newbie) MC modders know, each block has its own block ID. Could these stairs each have their different block ID? As it turns out no, they do not. It turns out that the game calculates what direction the player is facing, then creates the stair block with a variable called "Metadata" As far as I could tell, When it came to stairs, acceptable metadata values for stairs varied from 0 to 3 (ie 4 values). I did not know which value refered to which direction. Which lead to an experiment!!!

The Hoe in minecraft is an item which turns 1 block (grass or dirt) into another block (tilled soil). So, using modloader I modified it so that it would change the direction of the Stairs to meta data zero. The code below shows only the function that was changed in order to achieve the desired effect. Apart from the Item Icon, the rest of the hoe's functions remain the same.


Click anywhere inside the box to show spoiler.

The code above was designed to make the stairs face in the direction of metadata zero. no matter what part of the stairs were clicked (the l==5 variable refers a side of the block, ie pointing north, however we are not sure which l refers to which side).

After this code was impletented, the program was compiled, and the tool was used on the stairs. A sign was placed in the dection of metadata 0. Then all of the code was changed to point the sign to metadata 1. After running this, A sign was used to indicate metadata 1. The following diagram shows the results.

Hosted at imgur


I am surprised That the numberes were not in order. but that was irrelevent. The next Step was to Send each value of L to a different direction. Bare in mind that i did not know which value of L refered to the Metadata I wanted. So the code was as below:
Click anywhere inside the box to show spoiler.

And then this was compiled, and the program was run. I chose a random direction, and applied the tool.

Hosted at imgur


As you can see, by clicking on the side next to metadata = 2, the stairs points to metadata = 0. Looking at the code above, we can see that when l = 2, metadata is changed to equal 0. We know know that we want to change it to metadata = 2.

This method was used with the rest of the directions. Now, whenever the side of the stairs is clicked, the stairs will rotate in that direction. The following youtube video will hopefully explain this better. As the video was recorded on a none optifined Minecraft, the sound isnt too spectacular, I recomend turning the sound off if it annoys you.



What I learned:
  • How To use an item to affect a Block
  • That metadata affects the rotation in some blocks
  • That my computer is too slow for effective Frapsing
Where I'm going from here:
  • Expand this to pumpkins + Jacko lanterns
  • see if it is possible to make the above look upwards
  • If not, then to add a new block.

No comments:

Post a Comment