Minecraft / Blogs

Coding a Minecraft mod that gets loaded directly by the launcher.

  • 3
  • 3
  • comment
  • playlist_add
  • share
  • more_horiz
avatar Hallowizer
Level 16 : Journeyman Network
In the past, I have tried to directly fork Minecraft, and that has two problems. First, you get a ton of errors about missing dependencies, which take forever to resolve. Second, you can't distribute it, because that is a copyright violation. However, when 1.6 came out (when the launcher came out), Mojang create a launch wrapper that allows modifying classes before loading them. This is how FML currently loads. To start, you need to either run a relatively new Forge client, or run a 1.5- Minecraft version. It is recommended to run Forge, because you will not be able to use Launch.blackboard in your code if you choose to run 1.5-. Once you do this, you will need to open your Minecraft directory, and go to minecraft/libraries/net/minecraft/launchwrapper/1.12/launchwrapper-1.12.jar. Replace 1.12 with the latest version you have. Open an Eclipse workspace, and create a project for your mod. Next, add the jar you located into your build path. Now, create a package, and create a class that implements net.minecraft.launchwrapper.ITweaker. Add all unimplemented methods. First, the acceptOptions method is invoked first. It is simply there to give data to the tweaker. Next, the injectIntoClassLoader method is invoked. It is invoked immediately after acceptOptions, and it is given an instance of net.minecraft.launchwrapper.LaunchClassLoader. In this method, the tweaker should invoke addClassLoaderExclusion, addTransformerExclusion, and registerTransformer. The first two methods take prefixes that will apply on classes that start with them. addClassLoaderExclusion indicates that classes starting with the prefix should be loaded with the parent class loader. It is automatically invoked on your tweaker. addTransformerExclusion indicates that transformers should not be invoked with classes starting with the prefix. registerTransformer registers the transformer with the given class name. The launch wrapper does not add a class loader exclusion for your transformer, so it is recommended that you use a fully qualified name, instead of using MyTransformer.getClass().getName(). The transformer you specify should implement net.minecraft.launchwrapper.IClassTransformer. Additionally, tweakers can be cascaded. Launch.blackboard has an entry with the key TweakClasses that is a List<String> of tweakers that it has not constructed yet. This list is empty when getLaunchArguments and getLaunchTarget are being invoked, and writing to it will have no effect. You can also use the Launch.blackboard entry called Tweaks, but it is only writable when a tweaker's constructor is being called. Attempting to write it in a method will result in a java.util.ConcurrentModificationException. If you wish to add the same tweak class multiple times, but with different properties, you need to use this list, because the first list is checked for duplicate tweak classes. Next, in your tweaker, getLaunchArguments will be invoked. These launch arguments will be joined together with the launch arguments specified by other tweakers. However, the arguments passed to the launch wrapper are not saved, so you will need to save them in your acceptOptions method, then return them as an array in getLaunchArguments, but only in one tweaker. A list of arguments that will be passed to the main method can be seen in Launch.blackboard using key ArgumentList. The value is type List<String>. Finally, getLaunchTarget is invoked, but only on the primary tweaker. The primary tweaker is the first tweaker in the tweaker list, and is responsible for specifying the main class.

Comments : 0

star Login or register to post a comment.

Planet Minecraft



© 2010 - 2019