This is a good question! First off, I'd like to start by saying that you probably should NOT be rewriting the entire source code of another mod only to change so little. No offense, but it is a bit unorthodox, but in all honesty, if a mod is open source, and I can save the time from writing code to manipulate the mod FROM ANOTHER MOD, I'm downloadin' that source code, so I can't blame you too much for takin' the "easier" option 'cause then I'd be a bit of a hypocrite... However, if you don't want your time spent trying to rewrite the code to go to waste, you could just create a new mod project, copy the forge code for the backpack mod into your new project, and assemble the raw mod from there. But it seems that for some reason you want to push this mod as an artifact, which I honestly don't really see the point when it's just a mod for you and your friends, as you could just as easily slap that thing in ya' google drive and call it a day. Alternatively, you could make your own github repository and change the references in the gradle project to that instead, but this is probably the MOST unorthodox thing you could possibly do, and I honestly think that if you were to do this then Satan himself might personally drag you into hell. So to save yourself from eternal damnation, you might not want to do this. But from a more practical and orthodox standpoint, it is MUCH more appropriate to make a mod that modifies the code for the original mod in some way. There are two ways this can be done: the orthodox way and the unorthodox way. Let's start with the unorthodox way, as it's a lot easier to explain. Basically, you can change the code for another mod by making sure your mod loads in first into the JVM, which is easily done by just putting a bunch of "a"'s in the mods name. Next, find whatever piece of code you want to add in, and create a class with that same code in your mod with the exact same path as the class you wish to change (e.g. net.minecraft.entity.Entity if you wanted to change code in the entity class). The goal here is to trick the JVM into using your class instead of the original. This also means that you don't even have to do like any setup, not even including the backpacks mod as a dependency, so it's SUPER simple. However, this might not be that easy for you to do, because you mention that you need to change enums. I haven't looked too deep into the mods code, and by that I haven't actually looked at all, but if there is one thing I think I remember about enums, it's that they might be treated similar to CONSTANTS after compiling, which means that changing the enum class will have no effect because every usage of the enum is treated like putting in a constant number. If you choose the unorthodox route though, then I could be wrong, so it's still worth a shot. Finally, you have the proper orthodox way to do it, which is with an assembly transformer. If you don't want to go through the headache of having to set up your own bytecode transformer and learning java assembly bytecode, then I would recommend just using mixin. Basically, mixin or any other ASMTransformer are special tools that can be used to modify the code for certain classes. If you have used Harmony for c# or c++ unity mods, then it's much the same thing: give the transformer a class to do it's magic in, give it a function to use for it's magic, and tell it where to do it. For mixin, this is done by using the @Inject thingamabob (legitimately forgot wth this kind of thing was called). If you want examples of the ASMTransformer route and how to set it up, I would recommend looking at the source code for Galacticraft, as it uses transformers EXTENSIVELY. If you wish to use mixin, then there is extensive documentation on it's usage. Hope this helps!
By
Jackson Perr · 45 minutes ago 45 min
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.