From 8ee4fa01472d1f15213e87789196d9ed539724b3 Mon Sep 17 00:00:00 2001 From: Pahimar Date: Fri, 2 May 2014 16:06:56 -0400 Subject: [PATCH] Some starter work on keybindings and config files --- .../com/pahimar/ee3/EquivalentExchange3.java | 6 ++++ .../client/handler/KeyInputEventHandler.java | 20 +++++++++++ .../ee3/client/settings/Keybindings.java | 14 ++++++++ .../configuration/ClientConfiguration.java | 34 +++++++++++++++++++ .../configuration/ConfigurationHandler.java | 11 ++++++ .../java/com/pahimar/ee3/item/IKeyBound.java | 9 +++++ 6 files changed, 94 insertions(+) create mode 100644 src/main/java/com/pahimar/ee3/client/handler/KeyInputEventHandler.java create mode 100644 src/main/java/com/pahimar/ee3/client/settings/Keybindings.java create mode 100644 src/main/java/com/pahimar/ee3/configuration/ClientConfiguration.java create mode 100644 src/main/java/com/pahimar/ee3/configuration/ConfigurationHandler.java create mode 100644 src/main/java/com/pahimar/ee3/item/IKeyBound.java diff --git a/src/main/java/com/pahimar/ee3/EquivalentExchange3.java b/src/main/java/com/pahimar/ee3/EquivalentExchange3.java index d8ae29eb..fa51d56b 100644 --- a/src/main/java/com/pahimar/ee3/EquivalentExchange3.java +++ b/src/main/java/com/pahimar/ee3/EquivalentExchange3.java @@ -1,5 +1,6 @@ package com.pahimar.ee3; +import com.pahimar.ee3.configuration.ConfigurationHandler; import com.pahimar.ee3.handler.CraftingHandler; import com.pahimar.ee3.handler.FuelHandler; import com.pahimar.ee3.handler.GuiHandler; @@ -23,6 +24,8 @@ import cpw.mods.fml.common.registry.GameRegistry; import net.minecraft.init.Items; import net.minecraftforge.common.MinecraftForge; +import java.io.File; + @Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, certificateFingerprint = Reference.FINGERPRINT, version = "0.2") public class EquivalentExchange3 { @@ -47,6 +50,9 @@ public class EquivalentExchange3 @EventHandler public void preInit(FMLPreInitializationEvent event) { + // Initialize the configuration + ConfigurationHandler.init(event.getModConfigurationDirectory().getAbsolutePath() + File.separator + Reference.MOD_ID.toLowerCase() + File.separator); + // Initialize mod items ModItems.init(); diff --git a/src/main/java/com/pahimar/ee3/client/handler/KeyInputEventHandler.java b/src/main/java/com/pahimar/ee3/client/handler/KeyInputEventHandler.java new file mode 100644 index 00000000..ec793a48 --- /dev/null +++ b/src/main/java/com/pahimar/ee3/client/handler/KeyInputEventHandler.java @@ -0,0 +1,20 @@ +package com.pahimar.ee3.client.handler; + +import cpw.mods.fml.client.FMLClientHandler; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.InputEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class KeyInputEventHandler +{ + @SubscribeEvent + public void handleKeyInputEvent(InputEvent.KeyInputEvent event) + { + if (FMLClientHandler.instance().getClient().inGameHasFocus) + { + + } + } +} diff --git a/src/main/java/com/pahimar/ee3/client/settings/Keybindings.java b/src/main/java/com/pahimar/ee3/client/settings/Keybindings.java new file mode 100644 index 00000000..7e8e8cad --- /dev/null +++ b/src/main/java/com/pahimar/ee3/client/settings/Keybindings.java @@ -0,0 +1,14 @@ +package com.pahimar.ee3.client.settings; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.settings.KeyBinding; + +@SideOnly(Side.CLIENT) +public class Keybindings +{ + public static KeyBinding charge; + public static KeyBinding extra; + public static KeyBinding release; + public static KeyBinding toggle; +} diff --git a/src/main/java/com/pahimar/ee3/configuration/ClientConfiguration.java b/src/main/java/com/pahimar/ee3/configuration/ClientConfiguration.java new file mode 100644 index 00000000..10341b1b --- /dev/null +++ b/src/main/java/com/pahimar/ee3/configuration/ClientConfiguration.java @@ -0,0 +1,34 @@ +package com.pahimar.ee3.configuration; + +import com.pahimar.ee3.reference.Reference; +import com.pahimar.ee3.util.LogHelper; +import net.minecraftforge.common.config.Configuration; + +import java.io.File; + +public class ClientConfiguration +{ + public static final String CATEGORY_KEYBIND = "keybindings"; + private static Configuration configuration; + + protected static void init(File configFile) + { + configuration = new Configuration(configFile); + + try + { + configuration.load(); + + /* KeyBindings */ + configuration.addCustomCategoryComment(CATEGORY_KEYBIND, "Keybindings for Equivalent Exchange 3. See http://www.minecraftwiki.net/wiki/Key_codes for mapping of key codes to keyboard keys"); + } + catch (Exception e) + { + LogHelper.error(Reference.MOD_NAME + " has had a problem loading its general configuration"); + } + finally + { + configuration.save(); + } + } +} diff --git a/src/main/java/com/pahimar/ee3/configuration/ConfigurationHandler.java b/src/main/java/com/pahimar/ee3/configuration/ConfigurationHandler.java new file mode 100644 index 00000000..ad60db95 --- /dev/null +++ b/src/main/java/com/pahimar/ee3/configuration/ConfigurationHandler.java @@ -0,0 +1,11 @@ +package com.pahimar.ee3.configuration; + +import java.io.File; + +public class ConfigurationHandler +{ + public static void init(String configPath) + { + ClientConfiguration.init(new File(configPath + "client.properties")); + } +} diff --git a/src/main/java/com/pahimar/ee3/item/IKeyBound.java b/src/main/java/com/pahimar/ee3/item/IKeyBound.java new file mode 100644 index 00000000..d5fc9648 --- /dev/null +++ b/src/main/java/com/pahimar/ee3/item/IKeyBound.java @@ -0,0 +1,9 @@ +package com.pahimar.ee3.item; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +public interface IKeyBound +{ + public abstract void doKeyBindingAction(EntityPlayer entityPlayer, ItemStack itemStack, String keyBinding); +}