|
| 1 | +# Modding guide |
| 2 | +This guide provides information on how to create modifications for Minecraft Diverge. |
| 3 | + |
| 4 | + |
| 5 | +## Prerequisites: |
| 6 | +- JDK 8 (more recent versions do not support modding) (preferrably downloaded from [Adoptium](https://adoptium.net/en-GB/temurin/releases/?version=8), the JDK used to compile Minecraft Diverge) |
| 7 | +- RetroMCP 1.0.1 (https://github.com/MCPHackers/RetroMCP-Java; download 1.0.1 from the "Actions" tab, select the latest workflow, download the build artifacts and use the "GUI" jar if 1.0.1 has not released it) |
| 8 | +- Minecraft Diverge's [patch file](merged.patch) |
| 9 | +- Both the Minecraft Diverge [client](https://github.com/BlueStaggo/MCDiverge/releases/download/latest/mcdiverge.zip) and [server](https://github.com/BlueStaggo/MCDiverge/releases/download/latest/mcdiverge_server.zip) |
| 10 | +- (Optional, but recommended) A Java IDE, like IntelliJ or Eclipse. |
| 11 | + |
| 12 | +## Table of contents: |
| 13 | +- [Chapter 1: Development environment](#chapter-1-development-environment) |
| 14 | + - [Setting up RetroMCP](#setting-up-retromcp) |
| 15 | + - [Decompiling Minecraft Diverge (or at least try to)](#decompiling-minecraft-diverge-or-at-least-try-to) |
| 16 | + - [Decompiling and patching Alpha v1.1.2_01](#decompiling-and-patching-alpha-v112_01) |
| 17 | + - [Recompiling and running Minecraft Diverge](#recompiling-and-running-minecraft-diverge) |
| 18 | +- [Chapter 2: Basic mod development](#chapter-2-basic-mod-development) |
| 19 | + - [Loading the mod](#loading-the-mod) |
| 20 | + - [Adding mod content](#adding-mod-content) |
| 21 | + - [Publishing the mod](#publishing-the-mod) |
| 22 | + - [Additional resources](#further-resources) |
| 23 | + |
| 24 | +# Chapter 1: Development environment |
| 25 | + |
| 26 | +## Setting up RetroMCP |
| 27 | +First, the RetroMCP jar needs to be placed in a new folder. Before decompiling, the `Side` in the `Options` menu needs to be set to `Merged`. Then, go to the "Current version" dropdown and select "Alpha 1.1.2_01". Upon being prompted to run the setup, click yes. RetroMCP will show up a notification when setup is completed, and at that stage RetroMCP should be closed. After this, in the directory RetroMCP is in, two folders called `minecraft` and `minecraft_server` need to be created with each containing a folder called `jars`, since RetroMCP does not create them automatically despite requiring them. |
| 28 | + |
| 29 | +## Decompiling Minecraft Diverge (or at least try to) |
| 30 | +In the `jars` folder (not in `minecraft` or `minecraft_server`), there should be a jar file for the client named `minecraft.jar` and a jar file for the server named `minecraft_server.jar`. Each jar needs to be opened in a file archiver and the contents of `mcdiverge.zip` and `mcdiverge_server.zip` need to be copied over to the respective jar. Make sure to delete META-INF in `minecraft.jar`, but not in `minecraft_server.jar`. |
| 31 | + |
| 32 | +With Diverge ready to decompile, open up RetroMCP again and click on the `Decompile` button. Wait for it to do its work, however the decompilation will fail as there are many missing classes, duplicate members and missing generics. This is supposed to happen, as Minecraft Diverge has changed the source code so much that it is bound to have some major differences from the vanilla source code which RetroMCP cannot cope with. This is fine, as there is a different way to get Minecraft Diverge's source code that actually works. |
| 33 | + |
| 34 | +## Decompiling and patching Alpha v1.1.2_01 |
| 35 | +Create a new folder and copy RetroMCP into it. Open up RetroMCP, set the side to merged, select "Alpha 1.1.2_01" as the current version and click "Decompile". Once decompilation is finished, create a `patches` folder, where the patch file for Minecraft Diverge needs to be moved into and named `merged.patch`. Back in RetroMCP, to the top left of the window, click on `MCP` > `More tasks...` > `Apply patch` to apply the patch file. |
| 36 | + |
| 37 | +## Recompiling and running Minecraft Diverge |
| 38 | +In the `minecraft_merged` folder, there is a `src` folder. This folder needs to be copied over to the `minecraft_merged` folder in the Minecraft Diverge decompilation after its `src` and `src_original` folders have been deleted. After that, the `src` folder needs to be copied as a new folder called `src_original`, so that RetroMCP will now use the fixed source code for recompiling as well as source code patch creation. Open up RetroMCP again and press the following buttons in this order while accepting any prompts that appear: `Recompile`, `Update MD5`, `Reobfuscate`, `Build`. After all of this, click `MCP` > `Launch client` and a decompiled version of Minecraft Diverge should be running! |
| 39 | + |
| 40 | +# Chapter 2: Basic mod development |
| 41 | + |
| 42 | +## Loading the mod |
| 43 | +To start off creating a mod, add a new class in the folder `minecraft_merged/src/net/minecraft/src`. This class needs to inherit `BaseMod` and override the following methods: |
| 44 | + |
| 45 | +```java |
| 46 | +@Override // Name of the mod |
| 47 | +public String getName() { |
| 48 | + return "Example Mod"; |
| 49 | +} |
| 50 | + |
| 51 | +@Override // Mod version |
| 52 | +public String getVersion() { |
| 53 | + return "v0.3_a4"; |
| 54 | +} |
| 55 | + |
| 56 | +@Override // Author of the mod |
| 57 | +public String getAuthor() { |
| 58 | + return "BlueStaggo"; |
| 59 | +} |
| 60 | + |
| 61 | +@Override // Mod icon for mod list (optional) |
| 62 | +public String getIcon() { |
| 63 | + return "/example_mod/icon.png"; |
| 64 | +} |
| 65 | + |
| 66 | +@Override // Is the mod for the client or server? (defaults to both) |
| 67 | +public ModSide getSide() { |
| 68 | + return ModSide.BOTH; |
| 69 | +} |
| 70 | + |
| 71 | +@Override // Load the actual mod |
| 72 | +public void load() throws Exception { |
| 73 | + // Load your mod! |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +All resources are loaded relative to the first `src` folder, so if the mod class was used as the icon, its path would be `/net/minecraft/src/YourMod.class`. In the case above, relative to the RetroMCP jar, the icon would need to be stored in `/minecraft_merged/src/example_mod/icon.png`. |
| 78 | + |
| 79 | +Upon running the game, however, the mod will not load. To force the mod to load, go to `ModLoader.java`, and before the code that loads the example mod, add in this code: |
| 80 | + |
| 81 | +```java |
| 82 | +// ... |
| 83 | + } |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +// v v v |
| 88 | +mods.add(new YourMod()); |
| 89 | +modCount++; |
| 90 | +// ^ ^ ^ |
| 91 | + |
| 92 | +if (loadExampleMod) { |
| 93 | + mods.add(new ExampleMod()); |
| 94 | + modCount++; |
| 95 | +} |
| 96 | +// ... |
| 97 | +``` |
| 98 | + |
| 99 | +Make sure to remove this extra code before publishing the mod. If `ModLoader.class` appears in the final jar, it is safe to delete it. |
| 100 | +To compile the code and run the game, click on `Recompile`, `Reobfuscate` and `Build` in RetroMCP. When the game is opened, check in the mods list and the mod should appear with its icon: |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | +## Adding mod content |
| 105 | +What should the mod do? One simple thing it can do is create an achievement and grant it to the player when the game loads. This is very trivial, as this is all the code that needs to be added in the mod: |
| 106 | + |
| 107 | +```java |
| 108 | +public static Achievement exampleAchievement; |
| 109 | + |
| 110 | +@Override |
| 111 | +public void load() { |
| 112 | + exampleAchievement = new Achievement("example_mod/got_modded", "Got Modded", "Now it is Yourcraft!") |
| 113 | + .setCreativeUnlockable(); |
| 114 | + ModLoader.registry.addAchievement(exampleAchievement); // Make sure it is saved correctly |
| 115 | + if (ModLoader.isClient()) { |
| 116 | + Minecraft.getInstance().achievements.updateProgress(exampleAchievement, 1); |
| 117 | + } |
| 118 | +} |
| 119 | +``` |
| 120 | + |
| 121 | +As for the assets, relative to the src folder, these images need to be stored in the directory `/achievements/example_mod/` as `got_modded.png` and `got_modded_locked.png` respectively: |
| 122 | + |
| 123 | +  |
| 124 | + |
| 125 | +Now when the game is loaded this time, this should appear in the achievements menu: |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | +## Publishing the mod |
| 130 | +First, make sure the mod is not loaded from the ModLoader class. Like before, `Recompile`, `Reobfuscate` and `Build` in RetroMCP. In the `build` folder relative to the RetroMCP jar, two files can be found: `minecraft.zip` and `minecraft_server.zip`. Both of these files contain every class you have modified, but if there are any classes in there that you have not modified then make sure to delete them. Finally, the mod can be shared across the web, but one of the best places to share it in is in the Minecraft Diverge [Discord server](https://discord.gg/rzHsJkvpqw). |
| 131 | + |
| 132 | +## Additional resources |
| 133 | +This guide only shows so much, so looking through the [Example Mod](example_mod/net/minecraft/src/ExampleMod.java) and Minecraft Diverge's source code is recommended. |
0 commit comments