How the java in MC works.

Discussion in 'Off Topic' started by 0070071, Apr 8, 2012.

  1. 0070071

    0070071 Too many arguments with Neon/Shad, or about GT.

    Joined:
    Jan 21, 2012
    Messages:
    210
    Likes Received:
    14
    Ok. To start off, I'll let you know, that i HAVE NO IDEA how it works, this is for people(*cough cough* sk) to tell other people how it, and their minecraft... additions... work.

    About a year ago, I decided that I wanted to learn a programming language, this was just after I discovered minecraft, so, of course, without thinking, I got straight in. And now when I see java code that I didn't write (By the way, I am rubbish) my head explodes.

    I really want to develop stuff in java, and my way of learning, is to actually do it, or in this case, use other peoples code to understand it better in such a way that I can develop better applications.

    So, any java coders (*cough cough* sk89q), if you WANT to, please explain a smallish chunk of your code on this thread.

    Thank you.
     
  2. TexasGamer

    TexasGamer Well-Known Member

    Joined:
    Dec 1, 2011
    Messages:
    684
    Likes Received:
    254
    I'm willing to help if you have something more specific that you want me to explain. I also learn by looking at code so I know where you are coming from. Try looking at my Bukkit plugins and feel free to ask questions on how they work.
     
  3. 0070071

    0070071 Too many arguments with Neon/Shad, or about GT.

    Joined:
    Jan 21, 2012
    Messages:
    210
    Likes Received:
    14
    YAY!!!! To start off with, how does the skcraft launcher work? because I looked through it, and found that the main method was empty. Also, I don't understand the $1 $2 stuff at the end of the class name.
    Thanks
     
  4. alexanderpas

    alexanderpas I'll show you how deep the rabbit hole goes.

    Joined:
    Mar 13, 2012
    Messages:
    91
    Likes Received:
    23
  5. TexasGamer

    TexasGamer Well-Known Member

    Joined:
    Dec 1, 2011
    Messages:
    684
    Likes Received:
    254
    Are you decompiling the code? It's much easier to browse the source on GitHub (there's a easy source download link somewhere). The launcher itself is a relatively basic Swing (Java's GUI) application. Most of the stuff isn't anything special, but the launching of Minecraft and the loading of mods are two things that you are most likely interested in.

    For launching Minecraft, the launcher essentially calls the main method of the minecraft.jar. Of course, there's a specific way to do it so the game shows up properly.

    For the mod loading, the launcher uses reflection to accomplish this. In layman's terms, the launcher copies class files into the .jar before the main method of Minecraft is called. It's been hard-coded to handle different mods (such as ModLoader) differently as appropriate. I'm personally not the most well-versed in reflection, so sk has a better idea than me...
     
  6. sk89q

    sk89q Administrator
    Staff Member

    Joined:
    Dec 1, 2011
    Messages:
    2,490
    Likes Received:
    1,504
    The $1 and $2 are anonymous classes that are generated by compilation.

    I recommend checking the original source on GitHub.

    Also, a fair warning: my code tends to be abstract and utilizes a lot of more advance language features and so you're usually better off reading other people's code... My launcher is fairly simple though.
     
  7. 0070071

    0070071 Too many arguments with Neon/Shad, or about GT.

    Joined:
    Jan 21, 2012
    Messages:
    210
    Likes Received:
    14
    I extracted the files from the .jar then I used xcode to read the .class files, of which ALL methods etc. were empty.
     
  8. sk89q

    sk89q Administrator
    Staff Member

    Joined:
    Dec 1, 2011
    Messages:
    2,490
    Likes Received:
    1,504
  9. 0070071

    0070071 Too many arguments with Neon/Shad, or about GT.

    Joined:
    Jan 21, 2012
    Messages:
    210
    Likes Received:
    14
    I still don't understand most of the code. perhaps you could explain to me the most simple of those files.
    (my current level is starting GUIs)
     
  10. sk89q

    sk89q Administrator
    Staff Member

    Joined:
    Dec 1, 2011
    Messages:
    2,490
    Likes Received:
    1,504
  11. 0070071

    0070071 Too many arguments with Neon/Shad, or about GT.

    Joined:
    Jan 21, 2012
    Messages:
    210
    Likes Received:
    14
    Ok thanks, I now understand that main method, but most of the rest still knocks me out. Sorry for being such a slow learner, I hope you don't get impatient when you see my replies.
     
  12. sk89q

    sk89q Administrator
    Staff Member

    Joined:
    Dec 1, 2011
    Messages:
    2,490
    Likes Received:
    1,504
    Do you want to start with the launcher to learn with? You'd have to both learn regular Java and GUI at the same time, which is, of course, by all means doable.
     
  13. 0070071

    0070071 Too many arguments with Neon/Shad, or about GT.

    Joined:
    Jan 21, 2012
    Messages:
    210
    Likes Received:
    14
    Yes please. As I said before, I know a bit of regular java, thanks for your time :)