Changing existing mods, Changing key bindings, etc.

Everything about Minecraft.
User avatar
Sparky
Delta Force
Posts: 4194
Joined: Wed Mar 31, 2004 8:59 pm
Location: New Jersey, USA
Contact:

Changing existing mods, Changing key bindings, etc.

Post by Sparky » Tue Dec 11, 2012 4:14 pm

How do you change keybindings in minecraft?

I'm using the fly/x-ray mod and I would like to rebind F for Fly to another key.

I'm talking about editing the java class files.

EDIT: I figured it out.

How to change key bindings in Minecraft:

0. Force-update to the latest version of Minecraft.
0a. Download any pre-made mods for that version that you would like to use (such as the X-ray + Fly mod).
0b. Install the mods, replacing the appropriate files inside your minecraft.jar file (or folder) and deleting the META-INF folder.
1. Download MCP
2. Follow the included instructions as written in MCP/docs/README-MCP.TXT, using your (optionally modded) minecraft.jar and minecraft_server.jar files:

Code: Select all

How to use:
===========
1) Prepare the files:
- Copy the "minecraft_server.jar" file into the "jars" folder.
- Copy the folders "bin" and "resources" from your "%APPDATA$\.minecraft" folder into the "jars" folder.
By using the modded version of minecraft.jar and minecraft_server.jar, these files will be your working originals while using MCP. The changed files during the MCP modding stage will be patches that only work with your uniquely-modded version of minecraft. During obfuscation, the final step we use with MCP, MCP outputs patch files that are usable to your unique decompiled version, so since the version we used was modified with existing mods (meaning that minecraft.jar and/or minecraft_server.jar are no longer vanilla), the final patch files will be installed after we install the mods in our playable minecraft.jar and/or minecraft_server.jar files. If we share these with other players, we must mention exactly which versions of which mods they would need to install before applying those patch files to their version of the game; any differences, additional or lacking, would almost certainly mean incompatibility.

3. Open Terminal
4. Type cd and drag the MCP folder to the Terminal window so the path to that directory is inserted, then press Return
4a. UPDATE MCP: Paste this into Terminal and press Return:

Code: Select all

python runtime/updatemcp.py "$@"
4b. Increase the memory allocation for the decompilation process:
- Open the MCP folder, then the conf folder, then the file mcp.conf.
- Find:

Code: Select all

CmdFernflower = %s -jar %s -din=0 -rbr=0 -dgs=1 -asc=1 -log=WARN {indir} {outdir}
- Replace with:

Code: Select all

CmdFernflower = %s -Xmx2G -jar %s -din=0 -rbr=0 -dgs=1 -asc=1 -log=WARN {indir} {outdir}
5. Paste this into Terminal and press Return:

Code: Select all

python runtime/decompile.py "$@"
6. Wait for it to decompile the client and/or server
7. When it is finished, open the src folder inside the MCP folder

Modding Key Bindings
Here is how you would change the key bindings of an existing mod, for example:

8. Reference this page for the Key Codes that you are looking for, and use the number of the key you want to find, then Find in the .class files this line, for example:

Code: Select all

if (this.checkKey(33))
Where 33 = F in this case, to rebind the F key for the Fly Mod to something else. Here, the file is GuiIngame.java
9. Replace the key code with the code of the key you want instead.
10. Follow the instructions to recompile, test, and obfuscate the minecraft code.

Code: Select all

3) Modding
- Modify the sourcecode in the "src\minecraft" folder or in the "src\minecraft_server" folder.

4) Compile
- Start the "recompile.bat" script in this folder.
(or paste this into Terminal and press Return:)
python runtime/recompile.py "$@"

5) Testing (optional)
- To test the modified game, start the "startclient.bat" script
(or paste this into Terminal and press Return:)
python runtime/startclient.py "$@"

Note that in the test client (I didn't test the server, but it's probably basically the same principle), you don't log into the Minecraft Host, so you can only do a Single Player game, it defaults all the key bindings to WASD, etc., and you need to start a new world (it's like a new installation of Minecraft, but you can't login with your username and password).

- To test the modified server, start the "startserver.bat" script
(or paste this into Terminal and press Return:)
python runtime/startserver.py "$@"

6) Obfuscation
- Decompile the code, modify and recompile. (testing was optional)
- Start "reobfuscate.bat" to start the reobfuscation step, it will automatically detect changed classes and reobfuscate them.
(or paste this into Terminal and press Return:)
python runtime/reobfuscate.py "$@"

- Your obfuscated classes are now available in "reobf\minecraft" and "reobf\minecraft_server", ready to be injected in MC.
- Make sure to delete the META-INF folder in minecraft.jar, otherwise the game will just black-screen when you start it.
11. Finally, copy/paste the patch file(s) MCP generated which are found in MCP's reobf folder into your minecraft.jar and/or minecraft_server.jar, as mentioned at the bottom of the previous "code" forum BBCode section.
12. Now that you have installed your patch over your modified version of the game (the same modified version you decompiled with MCP), play and test your changes again in your primary installation of Minecraft.

---

So here are my new settings:

Code: Select all

if (this.checkKey(82))
            {
                xray = !xray;
                XRayHelper.a();
            }

            if (this.checkKey(80))
            {
                rf = !rf;
                XRayHelper.a();
            }

            if (this.checkKey(79))
            {
                nightLight = !nightLight;
                XRayHelper.a();
            }

            if (this.checkKey(83))
            {
                fly = !fly;
            }

            if (this.checkKey(81))
            {
                coords = !coords;
            }
Where Fly is Num Pad Decimal, Xray is Num Pad 0, Night Light is Num Pad 1, Redstone Finder is Num Pad 2 and Coordinate Display is Num Pad 3.

Xray = 0 (82)
RF = 2 (80)
NightLight = 1 (79)
Fly = . (83)
Coords = 3 (81)

Upon obfuscation, the output file was atk.class, which is found in the X-ray installation rather than the Fly Mod installation, just as a point of curiosity.

Code: Select all

== MCP 7.23 (data: 7.23, client: 1.4.5, server: 1.4.5) ==
# found ff, ff patches, srgs, name csvs, doc csvs, param csvs, renumber csv, astyle, astyle config
> Creating Retroguard config files
== Reobfuscating client ==
> Cleaning reobf
> Generating md5s
> Packing jar
> Reobfuscating jar
> Extracting modified classes
> Modified class found : net/minecraft/src/GuiIngame
> Outputted net/minecraft/src/GuiIngame         to reobf/minecraft as atk.class
- Done in 8.18 seconds
!! Can not find server md5s !!
Either you are groping for answers, or you are asking God and listening to Jesus.

Who is online

Users browsing this forum: No registered users and 1 guest