Skip to content
ploquel edited this page Jun 26, 2015 · 1 revision

Welcome to the Eclipse tricks tutorial. In this tutorial I will talk about using eclipse to learn how minecraft's source code really works. Because most of the time you wont have a tutorial walking you through technical stuff. So you have to know how to find how stuff works by looking at minecraft's code itself. First off you should already know that in java:

-Methods are like functions in python and lua. Declared like: public void setBlock(Parameter par1); and called like: World.setBlock(parameter);

-Classes are the files in eclipse, either .java or.class files. Whenever calling a class' function it goes like: TheClass.theFunction(parameter);

-Interfaces are like classes, but dont actually do anything, and have no code in them. Just empty methods. Other classes implement them and are forced to specify the empty methods, and usually fill them with their own code.

-Abstract classes are like interfaces, but they can have a mix of empty functions, and functions that have code in them, that any class that extends this abstract class will inherit.

-The "super" keyword represents the parent class. For example the Block class has a function public void break(). And a class that extends Block wants to break itself, it calls super.break(), even though it never wrote a break function in it's own file.

-Packages are like folders, but contain classes.

Object sources

Ever have a Method, variable, or Class that you had to dig through minecraft's source code to find? Well this is an easy way to jump to referenced files. Lets say you are calling Block.break() again. But this time you need to know what calling Block.break() will do, so you need to see the source code. You could either dig through the minecraft packages and try to find the Block class and then find the break() method inside of that. or..... you could just do this: Hold Ctrl and hover the mouse over the function. The function should turn blue and a popup appear under it. Click the function while it's blue.

You are now in the function's Class, at the function! you can just ctrl+click objects to go to their sources, this works on just about anything classes, methods, variables, etc.

Also Lets say you implement an abstract class' method. You can ctrl+hover over the method name and in the popup, click super implementation. It will then take you to the same function but in the class you extended.

#References

Lets say you made a method in a class, but you need to see where in the whole workspace that same method has been referenced or called. Well all you have to do is click the object, this will basically select it, putting a grey box around it. And then right click, go down to references, and then click workspace. It will then show up anywhere that that class, method, or variable is referenced.

Ok, but what if you just have a variable in a class and you just want to see whenever it's referenced in that class, without having to search. Well all you have to do is click the object, putting the box around it, and you will see grey rectangles on the very right of the screen, showing where that is referenced in that class, relative to the scrollbar.

Sometimes the rectangles will be yellow this means that the variable was set there, and not just referenced.

If you see any red rectangles that means there's an error there.

Also, if you can get your mouse right on the rectangle, and click it, it will take you to it in the code.

Call hierarchy

Another useful function in eclipse is seeing, from beginning to end, how a function ended up being called. To do this, select a java object and right click it, and click open call hierarchy.

Debug mode

Not really used for learning minecraft source code, but still extremely useful. Whenever you want to run minecraft to test if something works, dont hit the green play button, Instead hit the button with a bug on it, next to it. this will run the game just like normal, except one thing, You can make changes to your code, save it, and it will change in minecraft.

This doesn't work for all things though. Things that are only called or referenced at startup will not affect the game, you will have to restart for that.

I hope this tutorial helped, and really, if you want to learn how to do technical stuff in mods, you have to jump deep into the minecraft source code, to get an idea of how things work.

Clone this wiki locally