forked from Caedis/DuraDisplay
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from GTNewHorizons/refactor
Refactor #1
- Loading branch information
Showing
19 changed files
with
497 additions
and
393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
A mod to add durability/charge percentages to items |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.caedis.duradisplay; | ||
|
||
import com.caedis.duradisplay.config.DuraDisplayConfig; | ||
|
||
import cpw.mods.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent; | ||
import cpw.mods.fml.common.eventhandler.SubscribeEvent; | ||
|
||
public class ClientEvents { | ||
|
||
@SubscribeEvent | ||
public void onConfigChanged(OnConfigChangedEvent event) { | ||
if (event.modID.equals(Tags.MODID)) { | ||
DuraDisplayConfig.config.save(); | ||
DuraDisplayConfig.reloadConfigObject(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
package com.caedis.duradisplay; | ||
|
||
import com.caedis.duradisplay.config.DuraDisplayConfig; | ||
|
||
import cpw.mods.fml.common.FMLCommonHandler; | ||
import cpw.mods.fml.common.event.FMLPostInitializationEvent; | ||
import cpw.mods.fml.common.event.FMLPreInitializationEvent; | ||
import gregtech.GT_Mod; | ||
|
||
public class ClientProxy { | ||
|
||
// preInit "Run before anything else. Read your config, create blocks, items, etc, and register them with the | ||
// GameRegistry." (Remove if not needed) | ||
public void preInit(FMLPreInitializationEvent event) { | ||
DuraDisplayConfig.synchronizeConfiguration(event.getSuggestedConfigurationFile()); | ||
FMLCommonHandler.instance() | ||
.bus() | ||
.register(new ClientEvents()); | ||
} | ||
|
||
// postInit "Handle interaction with other mods, complete your setup based on this." (Remove if not needed) | ||
public void postInit(FMLPostInitializationEvent event) { | ||
// TODO: is this the proper way to override the config value? | ||
if (DuraDisplayConfig.Enable && DuraDisplayConfig.HideBars) | ||
GT_Mod.gregtechproxy.mRenderItemDurabilityBar = GT_Mod.gregtechproxy.mRenderItemChargeBar = false; | ||
DuraDisplayConfig.loadConfig(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
src/main/java/com/caedis/duradisplay/DuraDisplayConfig.java
This file was deleted.
Oops, something went wrong.
107 changes: 107 additions & 0 deletions
107
src/main/java/com/caedis/duradisplay/config/DuraDisplayConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.caedis.duradisplay.config; | ||
|
||
import java.io.File; | ||
|
||
import net.minecraft.launchwrapper.Launch; | ||
import net.minecraftforge.common.config.Configuration; | ||
|
||
import crazypants.enderio.config.Config; | ||
import gregtech.GT_Mod; | ||
|
||
public class DuraDisplayConfig { | ||
|
||
public static final String CATEGORY_CHARGE = "charge"; | ||
public static final String CATEGORY_DURABILITY = "durability"; | ||
|
||
private static boolean configLoaded = false; | ||
public static boolean Durability_Enable = true; | ||
public static boolean Charge_Enable = true; | ||
|
||
public static boolean Durability_HideBar = true; | ||
public static boolean Charge_HideBar = true; | ||
public static int Durability_PercentageLocation = 2; | ||
public static int Charge_PercentageLocation = 8; | ||
public static boolean Durability_PercentageWhenFull = false; | ||
public static boolean Charge_PercentageWhenFull = false; | ||
|
||
public static Configuration config = null; | ||
|
||
public static void loadConfig() { | ||
if (configLoaded) { | ||
return; | ||
} | ||
configLoaded = true; | ||
final File configDir = new File(Launch.minecraftHome, "config"); | ||
if (!configDir.isDirectory()) { | ||
configDir.mkdirs(); | ||
} | ||
final File configFile = new File(configDir, "duradisplay.cfg"); | ||
config = new Configuration(configFile); | ||
|
||
reloadConfigObject(); | ||
|
||
if (config.hasChanged()) { | ||
config.save(); | ||
} | ||
} | ||
|
||
public static void reloadConfigObject() { | ||
Durability_Enable = config.getBoolean( | ||
"Durability_Enable", | ||
DuraDisplayConfig.CATEGORY_DURABILITY, | ||
Durability_Enable, | ||
"Enable durability module"); | ||
|
||
Durability_HideBar = config.getBoolean( | ||
"Durability_HideBar", | ||
DuraDisplayConfig.CATEGORY_DURABILITY, | ||
Durability_HideBar, | ||
"Hide durability bar"); | ||
|
||
Charge_Enable = config | ||
.getBoolean("Charge_Enable", DuraDisplayConfig.CATEGORY_CHARGE, Charge_Enable, "Enable charge module"); | ||
|
||
Charge_HideBar = config | ||
.getBoolean("Charge_HideBar", DuraDisplayConfig.CATEGORY_CHARGE, Charge_HideBar, "Hide charge bar"); | ||
|
||
Durability_PercentageLocation = config.getInt( | ||
"Durability_PercentageLocation", | ||
DuraDisplayConfig.CATEGORY_DURABILITY, | ||
Durability_PercentageLocation, | ||
1, | ||
9, | ||
"Location in item where the durability percentage will be (numpad style)"); | ||
|
||
Charge_PercentageLocation = config.getInt( | ||
"Charge_PercentageLocation", | ||
DuraDisplayConfig.CATEGORY_CHARGE, | ||
Charge_PercentageLocation, | ||
1, | ||
9, | ||
"Location in item where the charge percentage will be (numpad style)"); | ||
|
||
Durability_PercentageWhenFull = config.getBoolean( | ||
"Durability_PercentageWhenFull", | ||
DuraDisplayConfig.CATEGORY_DURABILITY, | ||
Durability_PercentageWhenFull, | ||
"Show durability percentage when item is undamaged/full"); | ||
|
||
Charge_PercentageWhenFull = config.getBoolean( | ||
"Charge_PercentageWhenFull", | ||
DuraDisplayConfig.CATEGORY_CHARGE, | ||
Charge_PercentageWhenFull, | ||
"Show charge percentage when item is full"); | ||
|
||
if (config.hasChanged()) { | ||
config.save(); | ||
} | ||
|
||
// Gregtech Bars | ||
GT_Mod.gregtechproxy.mRenderItemDurabilityBar = !(Durability_Enable && Durability_HideBar); | ||
GT_Mod.gregtechproxy.mRenderItemChargeBar = !(Charge_Enable && Charge_HideBar); | ||
|
||
// EnderIO Bars | ||
Config.renderChargeBar = !(Charge_Enable && Charge_HideBar); | ||
Config.renderDurabilityBar = !(Durability_Enable && Durability_HideBar); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/caedis/duradisplay/config/GuiConfigDuraDisplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.caedis.duradisplay.config; | ||
|
||
import net.minecraft.client.gui.GuiScreen; | ||
import net.minecraftforge.common.config.ConfigElement; | ||
|
||
import com.caedis.duradisplay.Tags; | ||
import com.google.common.collect.Lists; | ||
|
||
import cpw.mods.fml.client.config.GuiConfig; | ||
|
||
@SuppressWarnings("unused") | ||
public class GuiConfigDuraDisplay extends GuiConfig { | ||
|
||
public GuiConfigDuraDisplay(GuiScreen parent) { | ||
super( | ||
parent, | ||
Lists.newArrayList( | ||
new ConfigElement<>(DuraDisplayConfig.config.getCategory(DuraDisplayConfig.CATEGORY_CHARGE)), | ||
new ConfigElement<>(DuraDisplayConfig.config.getCategory(DuraDisplayConfig.CATEGORY_DURABILITY))), | ||
Tags.MODID, | ||
"general", | ||
false, | ||
false, | ||
getAbridgedConfigPath(DuraDisplayConfig.config.toString())); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/caedis/duradisplay/config/GuiFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.caedis.duradisplay.config; | ||
|
||
import java.util.Set; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.GuiScreen; | ||
|
||
import cpw.mods.fml.client.IModGuiFactory; | ||
|
||
@SuppressWarnings("unused") | ||
public class GuiFactory implements IModGuiFactory { | ||
|
||
@Override | ||
public void initialize(Minecraft minecraftInstance) {} | ||
|
||
@Override | ||
public Class<? extends GuiScreen> mainConfigGuiClass() { | ||
return GuiConfigDuraDisplay.class; | ||
} | ||
|
||
@Override | ||
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.