Amazon Ad

Tuesday, May 23, 2017

Moderate Minecraft Modding Tutorial Part 2: Setting Up with IntelliJ Part 2

Before we start programming, we gotta fix a few things first! We have to set our language level and target level to be Java 8 and setup our run configurations to use the correct modules. First let's go into our settings by opening File > Settings... and then navigate our way to Build, Execution, Deployment > Compiler > Java Compiler. There we should see three modules.


We need to change the Target bytecode version to 1.8. After we change it, apply the settings and return to the main screen. Next we need to change our JDK to Java 8 by going to File > Project Structure > Project. We need to make sure that Project SDK is set to 1.8 and Project Language Level is set to 8. Next we need to go to Modules and go to tutorial > tutorial_main, which is the module we will use for building our mod. This is needs to have the language level set to 8 as well. If you didn't have to change anything then just close out and you're good, otherwise apply changes and return to the main screen.

Now we can finally start on programming!! Hooray! The fun part! Oh but wait! We still need to set everything up! Damn! Well, this time around it'll go smoother than last time!

First we will need to create the main mod class just like last time with the @Mod annotation and the three main event handlers, in a package with the same naming convention as last time (see my first modding tutorial for more details).


Ref is throwing an error at us so we need to create it and put our static constants in it.


Now we need to set up our proxies. We need to create the common and the client proxy. We need to get an instance of the common proxy which we will be accessing the proxy methods through.



Now we gotta create the necessary methods for the common and client proxies. There are two extra methods that I will get into some other time (such as commands). You should make two classes (CommonProxy and Client Proxy, Client Proxy inheriting from CommonProxy) and they should look like these two images:



In our main class, we need to call our proxies in our even handlers and pass the parameters as arguments so we can use them later whenever we need to.


Now we should probably get, for future reference, the instance of our mod.


Next we need to create a logger so that we can log to the console for debugging purposes.


Now we can use this logger in our main methods to signal to us that our mod initialization has began.


If we run our mod, we shouldn't have any problems and we should find our logs in the console during the pre-init, init, and the post-init phases of modloading.

We are now done with setting up! We can finally begin coding our blocks and items!

15 comments:

  1. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. If you haven't followed the first part of Setting Up with IntelliJ then you will be lost at this part. All you have to do is run the Forge Gradle task "genIntellijRuns" which is what sets up your intelliJ to have the three modules. Of course, it's recommended that you do that after running setupDecompWorkspace.

      Delete
    2. I didnt realize that you were referring to the mdk_main, I thought that I didnt do something right because Idea is not importing everything, the code is still very helpful, but I think I prefer eclipse with a little n++.

      Delete
  2. Shouldn't

    public static final Logger LOGGER = LogManager.getLogger(Ref.MODID);

    be

    public static final Logger LOGGER = Logger.getLogger(Ref.MODID);?

    ReplyDelete
  3. Either or...I actually did not know about Logger.getLogger(...) but you can use either one. I'm sure there are differences but most modders that I know use LogManager.getLogger(...). The FML team uses their own called FMLLog.getLogger but that one prints to the FML logger, but using either Logger.getLogger(...) or LogManager.getLogger(...) will allow you to log to your own logger. I think LogManager is faster, but I may be wrong.

    ReplyDelete
    Replies
    1. The Logger class in question is the java logger, right?
      Or is it the log4j one?

      Delete
  4. I probably missed something, but just in case, when I run the project, it runs the setup decomp workspace and not minecraft.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. Yeah i'm having the same problem and I can't find anything online to help.

      Delete
  5. This comment has been removed by the author.

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. I did everything as in the tutorial but i get this error Error:(45, 1) java: class, interface, or enum expected

    ReplyDelete
  10. where and how do you set up the @Mod annotation?

    ReplyDelete