Added AND finished successfully the work on the config file. Perfect with comments and stuff and a in-game config pane. that's a new feature. that's so cool!
This commit is contained in:
@@ -1,85 +0,0 @@
|
|||||||
package de.skate702.craftingkeys;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
|
||||||
import net.minecraftforge.common.config.Configuration;
|
|
||||||
import net.minecraftforge.common.config.Property;
|
|
||||||
import org.lwjgl.input.Keyboard;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configuration Management for Keys, etc.
|
|
||||||
*/
|
|
||||||
public class Config {
|
|
||||||
|
|
||||||
|
|
||||||
private static final String categoryKeys = "Keys";
|
|
||||||
private static final String categoryOther = "Other";
|
|
||||||
/**
|
|
||||||
* Defines all 11 Keys you can use with Crafting Keys.
|
|
||||||
*/
|
|
||||||
public static Property keyTopLeft, keyTopCenter, keyTopRight,
|
|
||||||
keyCenterLeft, keyCenterCenter, keyCenterRight,
|
|
||||||
keyLowerLeft, keyLowerCenter, keyLowerRight,
|
|
||||||
keyStack, keyInteract;
|
|
||||||
/**
|
|
||||||
* Defines, if NumPad is always active for crafting
|
|
||||||
*/
|
|
||||||
public static Property enableNumPad;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes the config Files, loads all values (or sets them to default).
|
|
||||||
*
|
|
||||||
* @param event PreInitEvent from Main Class
|
|
||||||
*/
|
|
||||||
public static void loadConfig(FMLPreInitializationEvent event) {
|
|
||||||
|
|
||||||
Configuration config = new Configuration(event.getSuggestedConfigurationFile());
|
|
||||||
|
|
||||||
config.load();
|
|
||||||
|
|
||||||
genComments(config);
|
|
||||||
|
|
||||||
getProperties(config);
|
|
||||||
|
|
||||||
config.save();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates comments for easier understanding of the categories.
|
|
||||||
*
|
|
||||||
* @param config Mod related Configuration File
|
|
||||||
*/
|
|
||||||
private static void genComments(Configuration config) {
|
|
||||||
|
|
||||||
config.addCustomCategoryComment(categoryKeys, "Keyboard codes based on http://minecraft.gamepedia.com/Key_codes");
|
|
||||||
config.addCustomCategoryComment(categoryOther, "Other settings which have effects @ crafting keys");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads all properties from the config file.
|
|
||||||
*
|
|
||||||
* @param config Mod related Configuration File
|
|
||||||
*/
|
|
||||||
private static void getProperties(Configuration config) {
|
|
||||||
|
|
||||||
keyTopLeft = config.get(categoryKeys, "1_keyTopLeft", Keyboard.KEY_Q);
|
|
||||||
keyTopCenter = config.get(categoryKeys, "2_keyTopCenter", Keyboard.KEY_W);
|
|
||||||
keyTopRight = config.get(categoryKeys, "3_keyTopRight", Keyboard.KEY_E);
|
|
||||||
|
|
||||||
keyCenterLeft = config.get(categoryKeys, "4_keyCenterLeft", Keyboard.KEY_A);
|
|
||||||
keyCenterCenter = config.get(categoryKeys, "5_keyCenterCenter", Keyboard.KEY_S);
|
|
||||||
keyCenterRight = config.get(categoryKeys, "6_keyCenterRight", Keyboard.KEY_D);
|
|
||||||
|
|
||||||
keyLowerLeft = config.get(categoryKeys, "7_keyLowerLeft", Keyboard.KEY_Y); // German Keyboard Layout
|
|
||||||
keyLowerCenter = config.get(categoryKeys, "8_keyLowerCenter", Keyboard.KEY_X);
|
|
||||||
keyLowerRight = config.get(categoryKeys, "9_keyLowerRight", Keyboard.KEY_C);
|
|
||||||
|
|
||||||
keyStack = config.get(categoryKeys, "keyStack", Keyboard.KEY_LSHIFT, "Key to move stacks instead of single items");
|
|
||||||
keyInteract = config.get(categoryKeys, "keyInteract", Keyboard.KEY_LCONTROL, "Key to interact with e.g. crafting output");
|
|
||||||
|
|
||||||
enableNumPad = config.get(categoryOther, "enableNumPad", true, "Activates the NumPad for crafting");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package de.skate702.craftingkeys;
|
package de.skate702.craftingkeys;
|
||||||
|
|
||||||
|
import cpw.mods.fml.client.event.ConfigChangedEvent;
|
||||||
import cpw.mods.fml.common.FMLCommonHandler;
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
import cpw.mods.fml.common.Mod;
|
import cpw.mods.fml.common.Mod;
|
||||||
import cpw.mods.fml.common.Mod.EventHandler;
|
import cpw.mods.fml.common.Mod.EventHandler;
|
||||||
@@ -11,6 +12,7 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
|||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
import cpw.mods.fml.common.gameevent.InputEvent;
|
import cpw.mods.fml.common.gameevent.InputEvent;
|
||||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||||
|
import de.skate702.craftingkeys.config.Config;
|
||||||
import de.skate702.craftingkeys.manager.ContainerManager;
|
import de.skate702.craftingkeys.manager.ContainerManager;
|
||||||
import de.skate702.craftingkeys.proxies.CraftingKeysProxy;
|
import de.skate702.craftingkeys.proxies.CraftingKeysProxy;
|
||||||
import net.minecraft.client.gui.inventory.GuiCrafting;
|
import net.minecraft.client.gui.inventory.GuiCrafting;
|
||||||
@@ -22,13 +24,18 @@ import net.minecraft.inventory.Slot;
|
|||||||
*
|
*
|
||||||
* @author skate702
|
* @author skate702
|
||||||
*/
|
*/
|
||||||
@Mod(modid = "craftingkeys", name = "Crafting Keys", version = "1.0.0")
|
@Mod(modid = CraftingKeys.MODID, name = CraftingKeys.VERSION, version = CraftingKeys.NAME,
|
||||||
|
guiFactory = "de.skate702.craftingkeys.config.ConfigGuiFactory")
|
||||||
public class CraftingKeys {
|
public class CraftingKeys {
|
||||||
|
|
||||||
|
public static final String MODID = "craftingkeys";
|
||||||
|
public static final String VERSION = "1.0.0";
|
||||||
|
public static final String NAME = "Crafting Keys";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current Instance of CraftingKeys.
|
* Current Instance of CraftingKeys.
|
||||||
*/
|
*/
|
||||||
@Instance(value = "CraftingKeys")
|
@Instance(value = MODID)
|
||||||
public static CraftingKeys instance;
|
public static CraftingKeys instance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,6 +87,12 @@ public class CraftingKeys {
|
|||||||
public void postInit(FMLPostInitializationEvent event) {
|
public void postInit(FMLPostInitializationEvent event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
|
||||||
|
if (eventArgs.modID.equals(MODID))
|
||||||
|
Config.syncConfig();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be executed every Ingame Tick.
|
* This method will be executed every Ingame Tick.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
package de.skate702.craftingkeys.config;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||||
|
import net.minecraftforge.common.config.Configuration;
|
||||||
|
import net.minecraftforge.common.config.Property;
|
||||||
|
import org.lwjgl.input.Keyboard;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration Management for Keys, etc.
|
||||||
|
*/
|
||||||
|
public class Config {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the config string for the keys-category.
|
||||||
|
*/
|
||||||
|
public static final String categoryKeys = "keys";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the config string for the other-category.
|
||||||
|
*/
|
||||||
|
public static final String categoryOther = "other";
|
||||||
|
/**
|
||||||
|
* Defines all 11 Keys you can use with Crafting Keys.
|
||||||
|
*/
|
||||||
|
public static Property keyTopLeft, keyTopCenter, keyTopRight,
|
||||||
|
keyCenterLeft, keyCenterCenter, keyCenterRight,
|
||||||
|
keyLowerLeft, keyLowerCenter, keyLowerRight,
|
||||||
|
keyStack, keyInteract;
|
||||||
|
/**
|
||||||
|
* Defines, if NumPad is always active for crafting.
|
||||||
|
*/
|
||||||
|
public static Property enableNumPad;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides the Suggested Config File.
|
||||||
|
*/
|
||||||
|
public static Configuration configFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the configFile Files, loads all values (or sets them to default).
|
||||||
|
*
|
||||||
|
* @param event PreInitEvent from Main Class
|
||||||
|
*/
|
||||||
|
public static void loadConfig(FMLPreInitializationEvent event) {
|
||||||
|
|
||||||
|
configFile = new Configuration(event.getSuggestedConfigurationFile());
|
||||||
|
|
||||||
|
configFile.load();
|
||||||
|
|
||||||
|
genComments();
|
||||||
|
|
||||||
|
syncConfig();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Syncs and saves the configFile file.
|
||||||
|
*/
|
||||||
|
public static void syncConfig() {
|
||||||
|
|
||||||
|
syncProperties();
|
||||||
|
|
||||||
|
if (configFile.hasChanged())
|
||||||
|
configFile.save();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates comments for easier understanding of the categories.
|
||||||
|
*
|
||||||
|
* @param config Mod related Configuration File
|
||||||
|
*/
|
||||||
|
private static void genComments() {
|
||||||
|
|
||||||
|
configFile.addCustomCategoryComment(categoryKeys, "Keyboard codes based on http://minecraft.gamepedia.com/Key_codes");
|
||||||
|
configFile.addCustomCategoryComment(categoryOther, "Other settings which have effects @ crafting keys");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads all properties from the configFile file.
|
||||||
|
*
|
||||||
|
* @param config Mod related Configuration File
|
||||||
|
*/
|
||||||
|
private static void syncProperties() {
|
||||||
|
|
||||||
|
// Standart Keys
|
||||||
|
|
||||||
|
keyTopLeft = configFile.get(categoryKeys, "1. Top Left", Keyboard.KEY_Q, "Top Left crafting key (key value)");
|
||||||
|
keyTopCenter = configFile.get(categoryKeys, "2. Top Center", Keyboard.KEY_W, "Top Center crafting key (key value)");
|
||||||
|
keyTopRight = configFile.get(categoryKeys, "3. Top Right", Keyboard.KEY_E, "Top Right crafting key (key value)");
|
||||||
|
|
||||||
|
keyCenterLeft = configFile.get(categoryKeys, "4. Center Left", Keyboard.KEY_A, "Center Left crafting key (key value)");
|
||||||
|
keyCenterCenter = configFile.get(categoryKeys, "5. Center Center", Keyboard.KEY_S, "Center Center crafting key (key value)");
|
||||||
|
keyCenterRight = configFile.get(categoryKeys, "6. Center Right", Keyboard.KEY_D, "Center Right crafting key (key value)");
|
||||||
|
|
||||||
|
keyLowerLeft = configFile.get(categoryKeys, "7. Lower Left", Keyboard.KEY_Y, "Lower Left crafting key (key value)"); // German Keyboard Layout
|
||||||
|
keyLowerCenter = configFile.get(categoryKeys, "8. Lower Center", Keyboard.KEY_X, "Lower Center crafting key (key value)");
|
||||||
|
keyLowerRight = configFile.get(categoryKeys, "9. Lower Right", Keyboard.KEY_C, "Lower Right crafting key (key value)");
|
||||||
|
|
||||||
|
// Special Keys
|
||||||
|
|
||||||
|
keyStack = configFile.get(categoryKeys, "Stack Key", Keyboard.KEY_LSHIFT, "Key to move stacks instead of single items");
|
||||||
|
keyInteract = configFile.get(categoryKeys, "Interaction Key", Keyboard.KEY_LCONTROL, "Key to interact with e.g. crafting output");
|
||||||
|
|
||||||
|
// Other Settings
|
||||||
|
|
||||||
|
enableNumPad = configFile.get(categoryOther, "Enable Num Pad", true, "Activates the NumPad for crafting");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package de.skate702.craftingkeys.config;
|
||||||
|
|
||||||
|
import cpw.mods.fml.client.config.DummyConfigElement;
|
||||||
|
import cpw.mods.fml.client.config.GuiConfig;
|
||||||
|
import cpw.mods.fml.client.config.IConfigElement;
|
||||||
|
import de.skate702.craftingkeys.CraftingKeys;
|
||||||
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
import net.minecraftforge.common.config.ConfigElement;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom Config Gui for Mod Options inside of Minecraft.
|
||||||
|
*/
|
||||||
|
public class ConfigGui extends GuiConfig {
|
||||||
|
public ConfigGui(GuiScreen parent) {
|
||||||
|
super(parent, getConfigElements(),
|
||||||
|
CraftingKeys.MODID, false, false, CraftingKeys.NAME);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates Config Entires based on the main config file.
|
||||||
|
*
|
||||||
|
* @return A List of IConfigElement-Items, ready to add to the gui.
|
||||||
|
*/
|
||||||
|
private static List<IConfigElement> getConfigElements() {
|
||||||
|
List<IConfigElement> list = new ArrayList<IConfigElement>();
|
||||||
|
|
||||||
|
list.add(categoryElement(Config.categoryKeys, Config.categoryKeys, "de.skate702.craftingkeys.keys"));
|
||||||
|
list.add(categoryElement(Config.categoryOther, Config.categoryOther, "de.skate702.craftingkeys.other"));
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatically generates category elements for config categories.
|
||||||
|
*
|
||||||
|
* @param category the given category string (from the config file)
|
||||||
|
* @param name the name of the category
|
||||||
|
* @param tooltip_key a lang-string, must have tooltip available under .tooltip
|
||||||
|
* @return Returns a IConfigElement ready to add to the list of elements
|
||||||
|
*/
|
||||||
|
private static IConfigElement categoryElement(String category, String name, String tooltip_key) {
|
||||||
|
return new DummyConfigElement.DummyCategoryElement(name, tooltip_key,
|
||||||
|
new ConfigElement<java.util.List<cpw.mods.fml.client.config.IConfigElement>>
|
||||||
|
(Config.configFile.getCategory(category)).getChildElements());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package de.skate702.craftingkeys.config;
|
||||||
|
|
||||||
|
import cpw.mods.fml.client.IModGuiFactory;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Config Gui Factory which always returns the ConfigGUI-Class. Nothing more to see here, go away!
|
||||||
|
*/
|
||||||
|
public class ConfigGuiFactory implements IModGuiFactory {
|
||||||
|
@Override
|
||||||
|
public void initialize(Minecraft minecraftInstance) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends GuiScreen> mainConfigGuiClass() {
|
||||||
|
return ConfigGui.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,5 +10,12 @@ key.lowercenter=8. Lower Center
|
|||||||
key.lowerright=9. Lower Right
|
key.lowerright=9. Lower Right
|
||||||
key.stack=Stack Key
|
key.stack=Stack Key
|
||||||
key.interact=Interaction Key
|
key.interact=Interaction Key
|
||||||
|
|
||||||
# Control Category Name
|
# Control Category Name
|
||||||
key.categories.craftingkeys=Crafting Keys
|
key.categories.craftingkeys=Crafting Keys
|
||||||
|
|
||||||
|
# Config Stuff
|
||||||
|
de.skate702.craftingkeys.keys=Keys
|
||||||
|
de.skate702.craftingkeys.other=Other
|
||||||
|
de.skate702.craftingkeys.keys.tooltip=Set your Keys here (Just google "LWJGL Key codes"!)
|
||||||
|
de.skate702.craftingkeys.other.tooltip=All other settings are here!
|
||||||
|
|||||||
@@ -1,16 +1,12 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"modid": "craftingkeys",
|
"modid": "craftingkeys",
|
||||||
"name": "Crafting Keys",
|
"name": "Crafting Keys",
|
||||||
"description": "TODO",
|
"description": "Simple better crafting! You can change the Key Bindings by clicking on Config.",
|
||||||
"version": "${version}",
|
"version": "1.0.0",
|
||||||
"mcversion": "${mcversion}",
|
"credits": "Based on the open-source InvTweaks-Mod. Thanks a lot!",
|
||||||
"url": "http://skate702.de",
|
"mcversion": "1.7.10 - 1.8",
|
||||||
"updateUrl": "http://skate702.de",
|
"url": "http://skate702.de",
|
||||||
"authorList": ["skate702, 0xSeb"],
|
"authorList": [ "skate702", "0xSeb" ]
|
||||||
"credits": "Thanks to Inventory-Tweaks!",
|
|
||||||
"logoFile": "",
|
|
||||||
"screenshots": [],
|
|
||||||
"dependencies": []
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
Reference in New Issue
Block a user