adding net.minecraft.server source to Eclipse

Discussion in 'Plugin Development' started by Bone008, Aug 25, 2012.

Thread Status:
Not open for further replies.
  1. So, FINALLY, mc-dev is back to public! (thank you to whoever made that happen :))

    Short explanation of my problem: Browsing code via GitHub is pretty uncomfortable, so having it directly within eclipse is the best solution for me. There are 3 parts of the code I need to access: Bukkit, CraftBukkit, mc-dev (the latter being all classes not contained in CraftBukkit).

    To get the first two combined, I simply used to download both CB and Bukkit source from GitHub, throw them together in one zip file and add it as a source attachment to the craftbukkit.jar library.
    All worked fine and dandy. Just, as stated above, with the problem that all unmodified net.minecraft.server (=NMS) classes were missing, because they are only in mc-dev (which was private since the update until now).

    In my head, I imagined adding that code being just as simple when it would be back public: Simply throw the files to all the other craftbukkit NMS ones (making sure not to overwrite anything). But it apparently doesn't work like that.

    From the research I did, I assume that the linked native unmodified NMS ".class" files within the compiled jar don't contain that information about the "SourceFile" they were compiled off of. That way, Eclipse doesn't recognize the .java files, even though they are there.
    Could that actually be the case?

    Has anyone a solution to that?
    My only requirement is: Being able to browse NMS classes that are not in the CraftBukkit repository from within Eclipse (while still having access to the rest of the source, but that should be the easy part that I already have).

    Thanks in advance!
  2. *cough*cough*
  3. You need to add craftbukkit.jar as a dependency rather than bukkit.jar. craftbukkit has all the mc-dev stuff in it :)
  4. I am talking about the source code right now, not the compiled classes. While in craftbukkit.jar, every single .class file is included, in its source (available from the CraftBukkit repository) it only contains the NMS classes that were modified. mc-dev contains all of them, unmodified.

    So in order to have code for all of the NMS classes (especially Pathfinders are what I mostly need) within Eclipse, I need to add these additional source files - which for some reason isn't doing anything, as stated above.
  5. Well if you want to do it manually download mc-dev then copy in Bukkit then CraftBukkit.
  6. Bone008
    Like Jacek said. I have a 'source' folder. In there are three folders:
    • net.minecraft.server
    • org.bukkit
    • org.bukkit.craftbukkit
    First I copy all mc-dev source code into net.minecraft.server. Then I download the source code of CraftBukkit and copy all of the java files in the net/minecraft/server folder into net.minecraft.server. Then I copy over all other source codes into org.bukkit.craftbukkit. Finally, I download Bukkit and put all of that into org.bukkit.

    There are free compilers btw: jad.exe can perfectly decompile all the source files. And it still allows you to see the real line numbers (if configured). You can use that until MC-dev is updated.
  7. That's weird, because that's pretty much what I did. But for some reason the unmodified part of the code still doesn't show up in the IDE.
    Now I tried it again, same results.
    • Opening a bukkit API class (org.bukkit.something) shows me the source
    • Opening a craftbukkit class (org.bukkit.craftbukkit.something) shows me the source
    • Opening a NMS class that is contained in the craftbukkit package shows me the source
    • Opening a NMS class that was only in the mc-dev package doesn't work (shows the javap descriptor)
    The java file is right there, in the exact same location as the other net.minecraft.server files of craftbukkit (3rd bullet).
    But the modified files show up, the original ones don't.

    What the zip file looks like right now (open)

    A stripped down version of the files in the zip file.
    |  \---minecraft
    |      \---server
    |              ...
            |  ... (all the bukkit classes)
            |  ... (all the craftbukkit classes)

    The steps I've taken:
    1. Paste the "net/" folder from the mc-dev source
    2. Paste the "org/" folder from the bukkit source
    3. Paste the "org/bukkit/craftbukkit/" folder from the craftbukkit source to "org/bukkit/"
    4. Paste the "net/" folder from the craftbukkit source (overwrite existing files)
    That zip file is set as the "source attachment" for craftbukkit.jar library in the build path in Eclipse.

    I even tried directly putting the java files next to the class files in the library, which had the exact same effect (everything working except original NMS classes). I can't find any reason ...
  8. Bone008
    It could be that Maven (is it a maven project?) hides the mc-dev files that are not part of the CraftBukkit source. Got no other clue to why that is happening. (I don't use the IDE to view code, Notepad++ does the job as well)
  9. I mostly use an decompiler to decompile l the craftbukkits ocntents, and use that decompiles classes to show it at my ide. Ok, it has some errors inside the code, but you know what they are trying to do (most of the time)
  10. No idea about Eclipse, I use Netbeans. But what I do is simply create a new 'project from existing sources' with the mc-dev repo src/ folder as the source. Whenever I want to look up a file I simply open that project and take a poke, like what bergerkiller does. As most of mc-dev won't compile there is no way in Netbeans and likely eclipse to get the auto source hotlinking (when you ctrl+click on a class/method and it takes you to the source). A minor inconvenience, but navigating there yourself is the best option I can think of.

    Hope this answers part of your question.
  11. If you have the jd-gui plugin for Eclipse and craftbukkit as a dependency you can ctrl+click and it shows you the source by decompiling. (I have no idea if it's actually ctrl+click, I usually right click then view declaration).
  12. Uncompilable code might explain why it doesn't show up in spite of the .java files being present.
    I guess an extra project is a good start. I just have multiple workspaces, but I guess it's a lot better than nothing.

    I'll take a look at jd-gui. Sounds pretty useful to me.

    On a side note, since mc-dev contains loads of compile errors - what source/classes are actually used to build craftbukkit.jar? It's not just linked to minecraft_server.jar, since that's using obfuscated stuff.
  13. Since the bytecode contained in minecraft_server.jar is still valid despite decompiling to invalid source, all the non modified classes are just linked to and taken from that jar.
  14. But minecraft_server.jar contains the obfuscated classes, CraftBukkit contains the deobfuscated ones. They can't be linked from there.
    As far as I know, deobfuscation is done on source code level, not byte code level (I might be wrong).
  15. You are wrong, deobfuscation is done on a byte code level, since the decompiled source code is not valid, and it is impossible to parse source for renames effectively. minecraft-server.jar is the mc-dev deobfuscated bytecode. Bare in mind this is the Bukkit provided minecraft-server.jar I am talking about.
    Bone008 likes this.
  16. I have / am making a request to get minecraft-server-sources.jar uploaded to the bukkit maven repo. Once / if this is done it should allow your ide to automatically display the sources.
    Bone008 likes this.
Thread Status:
Not open for further replies.

Share This Page