Keyboard event handling and restructuring some packages on the client side

This commit is contained in:
pahimar 2012-06-22 15:18:35 -04:00
parent 00d00be781
commit 5578b9ae11
7 changed files with 75 additions and 41 deletions

View file

@ -5,14 +5,18 @@ import java.lang.reflect.Field;
import cpw.mods.fml.common.ReflectionHelper;
import ee3.client.core.KeyHandler;
import ee3.client.core.SoundHandler;
import ee3.core.interfaces.IProxy;
import static ee3.lib.CustomItemRarity.*;
import net.minecraft.client.Minecraft;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.EnumRarity;
import net.minecraft.src.KeyBinding;
import net.minecraft.src.ModLoader;
import net.minecraft.src.NetworkManager;
import net.minecraft.src.World;
import net.minecraft.src.mod_EE3;
import net.minecraft.src.forge.EnumHelperClient;
import net.minecraft.src.forge.MinecraftForgeClient;
@ -99,5 +103,15 @@ public class EEProxy implements IProxy {
}
return EnumRarity.common;
}
@Override
public void registerKeyBindings() {
KeyHandler.init();
}
@Override
public void keyBindingEvent(Object event) {
KeyHandler.keyboardEvent((KeyBinding)event);
}
}

View file

@ -0,0 +1,36 @@
package ee3.client.core;
import net.minecraft.src.KeyBinding;
import net.minecraft.src.ModLoader;
import net.minecraft.src.mod_EE3;
/**
* TODO Class Description
* @author pahimar
*
*/
public class KeyHandler {
public static KeyBinding Extra;
public static KeyBinding Charge;
public static KeyBinding Toggle;
public static KeyBinding Release;
public static void init() {
Extra = new KeyBinding("ee3.mod.key.extra", 46);
Charge = new KeyBinding("ee3.mod.key.charge", 47);
Toggle = new KeyBinding("ee3.mod.key.toggle", 34);
Release = new KeyBinding("ee3.mod.key.release", 19);
ModLoader.registerKey(mod_EE3.instance(), Extra, false);
ModLoader.registerKey(mod_EE3.instance(), Charge, false);
ModLoader.registerKey(mod_EE3.instance(), Toggle, false);
ModLoader.registerKey(mod_EE3.instance(), Release, false);
}
public static void keyboardEvent(KeyBinding event) {
System.out.println(event.keyDescription);
}
}

View file

@ -1,4 +1,4 @@
package ee3.client;
package ee3.client.core;
import static ee3.lib.Sounds.soundFiles;

View file

@ -32,6 +32,10 @@ public interface IProxy {
public abstract void registerSoundHandler();
public abstract void registerKeyBindings();
public abstract void keyBindingEvent(Object event);
public abstract void handleControl(NetworkManager network, int key);
public abstract void handlePedestalPacket(int x, int y, int z, int itemId, boolean activated);

View file

@ -1,38 +0,0 @@
package ee3.lib;
/**
* TODO Class Description
* @author pahimar
*
*/
public class Keys {
public static final int EXTRA = 0;
public static final int CHARGE = 1;
public static final int TOGGLE = 2;
public static final int RELEASE = 3;
public static final int LEFT_CLICK = 4;
public static final int JUMP = 5;
public static final int SNEAK = 6;
public static String toString(int key) {
switch (key) {
case Keys.CHARGE:
return "KEYS.CHARGE";
case Keys.EXTRA:
return "KEYS.EXTRA";
case Keys.TOGGLE:
return "KEYS.TOGGLE";
case Keys.RELEASE:
return "KEYS.RELEASE";
case Keys.LEFT_CLICK:
return "KEYS.LEFT_CLICK";
case Keys.JUMP:
return "KEYS.JUMP";
case Keys.SNEAK:
return "KEYS.SNEAK";
default:
return "Unknown Key";
}
}
}

View file

@ -1,7 +1,6 @@
package net.minecraft.src;
import cpw.mods.fml.common.FMLCommonHandler;
import ee3.addons.BuildCraftAddon;
import ee3.core.ConfigurationManager;
import ee3.core.CraftingHandler;
import ee3.core.EntityLivingHandler;
@ -27,7 +26,7 @@ import net.minecraft.src.forge.NetworkMod;
*/
public class mod_EE3 extends NetworkMod {
public static mod_EE3 instance;
private static mod_EE3 instance;
@SidedProxy(clientSide="ee3.client.EEProxy", serverSide="ee3.server.EEProxy")
public static IProxy proxy;
public static EMCList emcList;
@ -75,8 +74,20 @@ public class mod_EE3 extends NetworkMod {
// Initialise the EMC List
//this.emcList.initEMCList();
// Register KeyBindings
this.proxy.registerKeyBindings();
}
public static BaseMod instance() {
return instance;
}
@Override
public void keyBindingEvent(Object event) {
this.proxy.keyBindingEvent(event);
}
@Override
public String getVersion() {
return Version.getVersion();

View file

@ -83,4 +83,11 @@ public class EEProxy implements IProxy {
public EnumRarity getCustomEnumRarityType(String custom) {
return null;
}
@Override
public void registerKeyBindings() { }
@Override
public void keyBindingEvent(Object event) { }
}