Wuppy’s Minecraft Forge Modding Tutorials for 1.7: Basic File Part 1: Package and Import

In the last tutorial I showed you how to set up Forge for 1.7. When you have finished this you will see an ExampleMod file in your Eclipse. In the next few tutorials I will explain the code in here, what it does and how you should use it. The code is as follows:

In this tutorial I will also explain very quickly the important Java parts you should know. If you are already good at Java this should be very familiar and you may want to skip this part of the tutorial.

The first line in the file is package com.example.examplemod;. This line sets the location of the file. In this case the file is located in the path: com/example/examplemod. This should always be at the start of your file and changes based on in which folders your code is located. If you are making a basic mod you can put all of the code in a single folder, but if you are making a bigger one you may want to have sub folders such as /items/ or /blocks/ in which you store all of your Block and Item files. In the first few tutorials it is going to be all in a single file, but there will be a tutorial later about how to add your files into subfiles.

The next four lines all start with import. Import means that it takes a file from somewhere outside of the package the code is in and makes sure that your code can use it. In this case it imports Block for the line that starts with the System.out.println because it wants to use an Object from that file. This code wants to acces the dirt variable. If you want to learn more about which variables and methods you can and can’t use from other files I suggest you learn some basic Java from for example Thenewboston.

Another important thing you should know about imports is that they not only require the file you want to import, but also the folder structure, or package, which it is in. For example Block is located in the package net.minecraft.block so the import becomes net.minecraft.block.Block. This may seem like a useless thing to do, because it should be obvious that you want that Block file. However, there are multiple versions of a Block file in the Minecraft code. If you ever do an import make sure you get the right one, which is in net.minecraft.block.

In the next tutorial I will explain more of the code.

 

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="">