Wuppy’s Minecraft Forge Modding Tutorials for 1.7: Eclipse Tricks: Code Formatting

In this tutorial I will show you how to easily format your code using Eclipse.

Sometimes a piece of code may not look that good, because you haven’t formatted it the right way when writing it. To save you a lot of work you can make Eclipse format it for you. Simply press Ctrl, Shift, F which will format all of the code for you.

However, there is one small problem with this shortcut. In Eclipse you can say in which way it should be formatted, but the standard format settings you get are completely different from what you get with Forge. To change these settings select Window at the top and then Preferences at the bottom of the dropdown window. Next you should click on the little arrow next to Java and after that on the arrow next to Code Style. Finally select Formatter. Then to create your own custom format settings select New and type some name for it. I called mine custom. Once you click Ok a new window will pop up in which you need to select the formatting options. Of course most of the formatting settings will be personal choice, but if you are going for code that looks like what Forge gives you go to Braces and put all of them to Next line except for the last one. You may also want to change a few settings in the New Lines and Control Statement tabs. Finally in Line wrappings and Comments you could change the 80 into something like 800 to make sure you can have a little longer lines of code.

Now when you press Ctrl, Shift, F again it will format the code to the way you want it.

 

For a more detailed explanation and much more, check out my book Sams Teach Yourself Mod Development for Minecraft in 24 Hours.

STY Minecraft Mod Development Book

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">