Frizkie

Keyboard: Keybinds that do stuff

Jun 6th, 2011
1,051
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. // Taken from "?menu keybinds" on #mcp-modding, and then annotated.
  2.  
  3. package net.minecraft.src;
  4.  
  5. // Import these, we'll need 'em
  6. import net.minecraft.client.Minecraft;
  7. import java.lang.reflect.Method;
  8.  
  9. public class mod_ToggleKey extends BaseMod
  10. {
  11.     public mod_ToggleKey()
  12.     {
  13.         // Register a key with ModLoader. Keep the params the way they are.
  14.         ModLoader.RegisterKey(this, this.key_toggle, false);
  15.         // Name the key.
  16.         ModLoader.AddLocalization("key.toggle", "name of key");
  17.     }
  18.  
  19.     // Code here is executed every tick, see other tutorial in my pastebin.
  20.     public void OnTickInGame(Minecraft minecraft)
  21.     {
  22.         if(toggle)
  23.         {
  24.                 // The stuff that the toggle does goes here.
  25.             }
  26.     }
  27.  
  28.     // This code just helps us realize when you push the key down.
  29.     public void KeyboardEvent(KeyBinding event)
  30.     {
  31.         Minecraft minecraft = ModLoader.getMinecraftInstance();
  32.         if (event == this.key_time)
  33.             {
  34.             toggle = !toggle;
  35.             }
  36.     }
  37.    
  38.     // Standard ModLoader procedure...
  39.     public String Version()
  40.     {
  41.         return "v0.1 for Beta 1.6.6 - Frizkie's Keybind Tut";
  42.     }
  43.  
  44.     // Define our key_toggle. The "20" parameter is the key code which can be found here: http://img87.imageshack.us/img87/5476/keyboardt.png
  45.     private KeyBinding key_toggle = new KeyBinding("key.toggle", 20);
  46.     private boolean toggle = false;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment