Skip to content

Commit

Permalink
Merge pull request #1 from GTNewHorizons/refactor
Browse files Browse the repository at this point in the history
Refactor #1
  • Loading branch information
Caedis authored Jun 5, 2023
2 parents 99c5da2 + 60e3e11 commit 85eebea
Show file tree
Hide file tree
Showing 19 changed files with 497 additions and 393 deletions.
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A mod to add durability/charge percentages to items
14 changes: 8 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//version: 1684218858
//version: 1685785062
/*
DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available.
Expand Down Expand Up @@ -1276,12 +1276,14 @@ tasks.register('faq') {
description = 'Prints frequently asked questions about building a project'

doLast {
print("If your build fails to fetch dependencies, they might have been deleted and replaced by newer " +
"versions.\nCheck if the versions you try to fetch are still on the distributing sites.\n" +
"The links can be found in repositories.gradle and build.gradle:repositories, " +
"not build.gradle:buildscript.repositories - this one is for gradle plugin metadata.\n\n" +
print("If your build fails to fetch dependencies, run './gradlew updateDependencies'. " +
"Or you can manually check if the versions are still on the distributing sites - " +
"the links can be found in repositories.gradle and build.gradle:repositories, " +
"but not build.gradle:buildscript.repositories - those ones are for gradle plugin metadata.\n\n" +
"If your build fails to recognize the syntax of new Java versions, enable Jabel in your " +
"gradle.properties. See how it's done in GTNH ExampleMod/gradle.properties.")
"gradle.properties. See how it's done in GTNH ExampleMod/gradle.properties. " +
"However, keep in mind that Jabel enables only syntax features, but not APIs that were introduced in " +
"Java 9 or later.")
}
}

Expand Down
6 changes: 3 additions & 3 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
* For more details, see https://docs.gradle.org/8.0.1/userguide/java_library_plugin.html#sec:java_library_configurations_graph
*/
dependencies {
api('com.github.GTNewHorizons:GT5-Unofficial:5.09.43.63:dev')
api('com.github.GTNewHorizons:GT5-Unofficial:5.09.43.65:dev')
api("net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev")
api("com.github.GTNewHorizons:EnderIO:2.4.16:dev")
api("com.github.GTNewHorizons:EnderIO:2.4.18:dev")

runtimeOnlyNonPublishable("com.github.GTNewHorizons:TinkersConstruct:1.9.32-GTNH:dev")
runtimeOnlyNonPublishable("com.github.GTNewHorizons:TinkersConstruct:1.9.36-GTNH:dev")
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mixinsPackage = mixins
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
# This parameter is for legacy compatibility only
# Example value: coreModClass = asm.FMLPlugin + modGroup = com.caedis.duradisplay -> com.caedis.duradisplay.asm.FMLPlugin
coreModClass =
coreModClass = core.DuraDisplayCore
# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class
# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false!
containsMixinsAndOrCoreModOnly = false
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/caedis/duradisplay/ClientEvents.java
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();
}
}
}
12 changes: 7 additions & 5 deletions src/main/java/com/caedis/duradisplay/ClientProxy.java
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();
}

}
4 changes: 3 additions & 1 deletion src/main/java/com/caedis/duradisplay/DuraDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
version = Tags.VERSION,
name = Tags.MODNAME,
acceptedMinecraftVersions = "[1.7.10]",
dependencies = "required-after:gregtech@[5.09.43.63,);" + " required-after:EnderIO;")
guiFactory = "com.caedis.duradisplay.config.GuiFactory",
dependencies = "required-after:gregtech@[5.09.43.63,);" + " required-after:EnderIO@[2.4.18,);")
public class DuraDisplay {

public static final Logger LOG = LogManager.getLogger(Tags.MODID);
Expand All @@ -33,4 +34,5 @@ public void preInit(FMLPreInitializationEvent event) {
public void postInit(FMLPostInitializationEvent event) {
proxy.postInit(event);
}

}
34 changes: 0 additions & 34 deletions src/main/java/com/caedis/duradisplay/DuraDisplayConfig.java

This file was deleted.

107 changes: 107 additions & 0 deletions src/main/java/com/caedis/duradisplay/config/DuraDisplayConfig.java
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);
}
}
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 src/main/java/com/caedis/duradisplay/config/GuiFactory.java
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;
}
}
Loading

0 comments on commit 85eebea

Please sign in to comment.