diff --git a/resources/assets/storagedrawers/lang/en_US.lang b/resources/assets/storagedrawers/lang/en_US.lang index 0ab0b3c..ce4da01 100644 --- a/resources/assets/storagedrawers/lang/en_US.lang +++ b/resources/assets/storagedrawers/lang/en_US.lang @@ -1,11 +1,13 @@ itemGroup.storageDrawers=Storage Drawers +# Items item.upgrade.iron.name=Drawer Upgrade (II) item.upgrade.gold.name=Drawer Upgrade (III) item.upgrade.obsidian.name=Drawer Upgrade (IV) item.upgrade.diamond.name=Drawer Upgrade (V) item.upgrade.emerald.name=Drawer Upgrade (VI) +# Blocks tile.fullDrawers2.oak.name=Oak Drawers 1x2 tile.fullDrawers2.spruce.name=Spruce Drawers 1x2 tile.fullDrawers2.birch.name=Birch Drawers 1x2 @@ -37,6 +39,24 @@ tile.halfDrawers4.big_oak.name=Compact Dark Oak Drawers 2x2 storageDrawers.drawers.description=Holds %d stacks per drawer storageDrawers.upgrade.description=Increases storage to %d times base value +# Integration storageDrawers.waila.empty=Empty storageDrawers.waila.level=Upgrade Level: %s -storageDrawers.waila.drawer=Drawer #%s: %s \ No newline at end of file +storageDrawers.waila.drawer=Drawer #%s: %s + +# Configuration +storageDrawers.config.title=Storage Drawers Configuration + +storageDrawers.config.general=General Settings +storageDrawers.config.general.tooltip=This and that. + +storageDrawers.config.blocks=Block Settings +storageDrawers.config.blocks.tooltip=Configure individual storage blocks. + +storageDrawers.config.blocks.fullDrawers2=Drawers 1x2 +storageDrawers.config.blocks.fullDrawers4=Drawers 2x2 +storageDrawers.config.blocks.halfDrawers2=Compact Drawers 1x2 +storageDrawers.config.blocks.halfDrawers4=Compact Drawers 2x2 + +storageDrawers.config.upgrades=Upgrade Settings +storageDrawers.config.upgrades.tooltip=Configure individual storage upgrades. \ No newline at end of file diff --git a/src/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java index 402ac20..a1e6997 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java @@ -1,7 +1,10 @@ package com.jaquadro.minecraft.storagedrawers; +import com.jaquadro.minecraft.storagedrawers.config.ConfigManager; import com.jaquadro.minecraft.storagedrawers.core.*; import com.jaquadro.minecraft.storagedrawers.network.BlockClickMessage; +import cpw.mods.fml.client.event.ConfigChangedEvent; +import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.SidedProxy; @@ -9,12 +12,15 @@ import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLInterModComms; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; import cpw.mods.fml.relauncher.Side; import net.minecraftforge.common.MinecraftForge; -@Mod(modid = StorageDrawers.MOD_ID, name = StorageDrawers.MOD_NAME, version = StorageDrawers.MOD_VERSION, dependencies = "after:waila;") +import java.io.File; + +@Mod(modid = StorageDrawers.MOD_ID, name = StorageDrawers.MOD_NAME, version = StorageDrawers.MOD_VERSION, dependencies = "after:waila;", guiFactory = StorageDrawers.SOURCE_PATH + "core.ModGuiFactory") public class StorageDrawers { public static final String MOD_ID = "StorageDrawers"; @@ -27,6 +33,7 @@ public class StorageDrawers public static final ModRecipes recipes = new ModRecipes(); public static SimpleNetworkWrapper network; + public static ConfigManager config; @Mod.Instance(MOD_ID) public static StorageDrawers instance; @@ -36,6 +43,8 @@ public class StorageDrawers @Mod.EventHandler public void preInit (FMLPreInitializationEvent event) { + config = new ConfigManager(new File(event.getModConfigurationDirectory(), MOD_ID + ".cfg")); + network = NetworkRegistry.INSTANCE.newSimpleChannel(MOD_ID); network.registerMessage(BlockClickMessage.Handler.class, BlockClickMessage.class, 0, Side.SERVER); @@ -51,6 +60,7 @@ public class StorageDrawers public void init (FMLInitializationEvent event) { proxy.registerRenderers(); + FMLCommonHandler.instance().bus().register(instance); MinecraftForge.EVENT_BUS.register(new ForgeEventHandler()); } @@ -58,4 +68,10 @@ public class StorageDrawers public void postInit (FMLPostInitializationEvent event) { recipes.init(); } + + @SubscribeEvent + public void onConfigChanged (ConfigChangedEvent.OnConfigChangedEvent event) { + if (event.modID.equals(MOD_ID)) + config.syncConfig(); + } } diff --git a/src/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java b/src/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java new file mode 100644 index 0000000..8876ff9 --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java @@ -0,0 +1,115 @@ +package com.jaquadro.minecraft.storagedrawers.config; + +import net.minecraft.block.Block; +import net.minecraftforge.common.config.ConfigCategory; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class ConfigManager +{ + public class ConfigSection { + public final ConfigSection parent; + public final String name; + public final String lang; + + private ConfigCategory category; + + public ConfigSection (List list, ConfigSection parent, String name, String lang) { + this.parent = parent; + this.name = name; + this.lang = lang; + + list.add(this); + } + + public ConfigSection (List list, String name, String lang) { + this(list, null, name, lang); + } + + public ConfigCategory getCategory () { + if (category != null) + return category; + + if (parent != null) + category = config.getCategory(parent.getCategory().getQualifiedName() + "." + name.toLowerCase()); + else + category = config.getCategory(name.toLowerCase()); + + category.setLanguageKey(LANG_PREFIX + lang); + return category; + } + + public String getQualifiedName () { + return getCategory().getQualifiedName(); + } + } + + private static final String LANG_PREFIX = "storageDrawers.config."; + + private final Configuration config; + + public final List sections = new ArrayList(); + public final ConfigSection sectionGeneral = new ConfigSection(sections, "general", "general"); + public final ConfigSection sectionBlocks = new ConfigSection(sections, "blocks", "blocks"); + public final ConfigSection sectionUpgrades = new ConfigSection(sections, "upgrades", "upgrades"); + + public final List blockSections = new ArrayList(); + public final ConfigSection sectionBlocksFullDrawers1x2 = new ConfigSection(blockSections, sectionBlocks, "fulldrawers2", "blocks.fullDrawers2"); + public final ConfigSection sectionBlocksFullDrawers2x2 = new ConfigSection(blockSections, sectionBlocks, "fulldrawers4", "blocks.fullDrawers4"); + public final ConfigSection sectionBlocksHalfDrawers1x2 = new ConfigSection(blockSections, sectionBlocks, "halfdrawers2", "blocks.halfDrawers2"); + public final ConfigSection sectionBlocksHalfDrawers2x2 = new ConfigSection(blockSections, sectionBlocks, "halfdrawers4", "blocks.halfDrawers4"); + + public Map blockSubcategories; + + private Property itemRenderType; + + public ConfigManager (File file) { + config = new Configuration(file); + + for (ConfigSection section : sections) + section.getCategory(); + + for (ConfigSection section : blockSections) + section.getCategory(); + + syncConfig(); + } + + public void syncConfig () { + itemRenderType = config.get(Configuration.CATEGORY_GENERAL, "Item Render Type", "fancy", null, new String[] { "fancy", "fast" }); + + config.get(sectionBlocksFullDrawers1x2.getQualifiedName(), "enabled", true); + config.get(sectionBlocksFullDrawers1x2.getQualifiedName(), "baseStorage", 8); + + config.get(sectionBlocksFullDrawers2x2.getQualifiedName(), "enabled", true); + config.get(sectionBlocksFullDrawers2x2.getQualifiedName(), "baseStorage", 4); + + config.get(sectionBlocksHalfDrawers1x2.getQualifiedName(), "enabled", true); + config.get(sectionBlocksHalfDrawers1x2.getQualifiedName(), "baseStorage", 4); + + config.get(sectionBlocksHalfDrawers2x2.getQualifiedName(), "enabled", true); + config.get(sectionBlocksHalfDrawers2x2.getQualifiedName(), "baseStorage", 2); + + if (config.hasChanged()) + config.save(); + } + + public boolean fancyItemRenderEnabled () { + if (itemRenderType.getString().equals("fancy")) + return true; + return false; + } + + public String getPath () { + return config.toString(); + } + + private String getBlockName (Block block) { + return block.getUnlocalizedName().replace("tile.", ""); + } +} diff --git a/src/com/jaquadro/minecraft/storagedrawers/config/ModConfigGui.java b/src/com/jaquadro/minecraft/storagedrawers/config/ModConfigGui.java new file mode 100644 index 0000000..4c00976 --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/config/ModConfigGui.java @@ -0,0 +1,27 @@ +package com.jaquadro.minecraft.storagedrawers.config; + +import com.jaquadro.minecraft.storagedrawers.StorageDrawers; +import cpw.mods.fml.client.config.GuiConfig; +import cpw.mods.fml.client.config.IConfigElement; +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.common.config.ConfigElement; + +import java.util.ArrayList; +import java.util.List; + +public class ModConfigGui extends GuiConfig +{ + public ModConfigGui (GuiScreen parent) { + super(parent, getConfigElements(), StorageDrawers.MOD_ID, false, false, "Storage Drawers Configuration"); + } + + private static List getConfigElements () { + List list = new ArrayList(); + + for (ConfigManager.ConfigSection section : StorageDrawers.config.sections) + list.add(new ConfigElement(section.getCategory())); + + return list; + } + +} diff --git a/src/com/jaquadro/minecraft/storagedrawers/core/ModGuiFactory.java b/src/com/jaquadro/minecraft/storagedrawers/core/ModGuiFactory.java new file mode 100644 index 0000000..2153166 --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/core/ModGuiFactory.java @@ -0,0 +1,29 @@ +package com.jaquadro.minecraft.storagedrawers.core; + +import com.jaquadro.minecraft.storagedrawers.config.ModConfigGui; +import cpw.mods.fml.client.IModGuiFactory; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; + +import java.util.Set; + +public class ModGuiFactory implements IModGuiFactory +{ + @Override + public void initialize (Minecraft minecraftInstance) { } + + @Override + public Class mainConfigGuiClass () { + return ModConfigGui.class; + } + + @Override + public Set runtimeGuiCategories () { + return null; + } + + @Override + public RuntimeOptionGuiHandler getHandlerFor (RuntimeOptionCategoryElement element) { + return null; + } +}