Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basically rewrite the whole mod #3

Merged
merged 14 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
685 changes: 507 additions & 178 deletions build.gradle

Large diffs are not rendered by default.

Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
41 changes: 31 additions & 10 deletions src/main/java/locusway/overloadedarmorbar/ConfigurationHandler.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
package locusway.overloadedarmorbar;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.minecraftforge.common.config.Configuration;

import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import locusway.overloadedarmorbar.overlay.ArmorBarRenderer;

public class ConfigurationHandler {

public static Configuration config;
public static String[] colorValues = new String[] { "#FFFFFF", "#FF5500", "#FFC747", "#27FFE3", "#00FF00",
"#7F00FF" };
public static int[] colorValuesI;
public static boolean alwaysShowArmorBar = false;
public static boolean showEmptyArmorIcons = false;
public static boolean offset = false;

public static void init(String configDir) {
public ConfigurationHandler(File configDir) {
if (config == null) {
File path = new File(configDir + "/" + OverloadedArmorBar.MODID + ".cfg");
config = new Configuration(path);
config = new Configuration(configDir);
loadConfiguration();
}
}
Expand All @@ -32,15 +34,33 @@ private static void loadConfiguration() {
Configuration.CATEGORY_GENERAL,
new String[] { "#FFFFFF", "#FF5500", "#FFC747", "#27FFE3", "#00FF00", "#7F00FF" },
"Colors must be specified in #RRGGBB format");
offset = config.getBoolean(
"Override for Armor shift",
Configuration.CATEGORY_GENERAL,
false,
"Set to true if the armor bar display's incorrectly");
showEmptyArmorIcons = config
.getBoolean("Show empty armor icons?", Configuration.CATEGORY_GENERAL, false, "Show empty armor icons");

if (config.hasChanged()) config.save();
fillColorValuesI();

if (config.hasChanged()) {
config.save();
ArmorBarRenderer.forceUpdate();
}
}

private static void fillColorValuesI() {
colorValuesI = new int[colorValues.length];
for (int i = 0; i < colorValues.length; i++) {
colorValuesI[i] = parseColor(colorValues[i]);
}
}

private static final Pattern colorPattern = Pattern.compile("^#[0-9A-Fa-f]{6}$");

private static int parseColor(String colorValue) {
final Matcher matcher = colorPattern.matcher(colorValue);
if (matcher.matches()) {
return Integer.parseInt(colorValue.substring(1, 7), 16);
} else {
return 0xFFFFFF;
}
}

@SubscribeEvent
Expand All @@ -51,4 +71,5 @@ public void onConfigurationChangeEvent(ConfigChangedEvent.OnConfigChangedEvent e
public static Configuration getConfig() {
return config;
}

}
24 changes: 9 additions & 15 deletions src/main/java/locusway/overloadedarmorbar/OverloadedArmorBar.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package locusway.overloadedarmorbar;

import locusway.overloadedarmorbar.proxy.CommonProxy;
import net.minecraftforge.common.MinecraftForge;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.relauncher.Side;
import locusway.overloadedarmorbar.overlay.ArmorBarRenderer;

@Mod(
modid = OverloadedArmorBar.MODID,
Expand All @@ -19,20 +21,12 @@ public class OverloadedArmorBar {
public static final String VERSION = "GRADLETOKEN_VERSION";
public static final String GUI_FACTORY_CLASS = "locusway.overloadedarmorbar.client.gui.GuiFactory";

public static org.apache.logging.log4j.Logger logger;

@SidedProxy(
modId = MODID,
clientSide = "locusway.overloadedarmorbar.proxy.ClientProxy",
serverSide = "locusway.overloadedarmorbar.proxy.CommonProxy")
public static CommonProxy proxy;

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
logger = event.getModLog();
proxy.registerEvents();
String configDir = event.getModConfigurationDirectory().toString();
ConfigurationHandler.init(configDir);
FMLCommonHandler.instance().bus().register(new ConfigurationHandler());
if (event.getSide() == Side.CLIENT) {
MinecraftForge.EVENT_BUS.register(new ArmorBarRenderer());
FMLCommonHandler.instance().bus().register(new ConfigurationHandler(event.getSuggestedConfigurationFile()));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import cpw.mods.fml.client.IModGuiFactory;

@SuppressWarnings("unused")
public class GuiFactory implements IModGuiFactory {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package locusway.overloadedarmorbar.client.gui;

import static locusway.overloadedarmorbar.ConfigurationHandler.getConfig;

import locusway.overloadedarmorbar.OverloadedArmorBar;

import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Configuration;

import cpw.mods.fml.client.config.GuiConfig;
import locusway.overloadedarmorbar.ConfigurationHandler;
import locusway.overloadedarmorbar.OverloadedArmorBar;

public class ModGUIConfig extends GuiConfig {

public ModGUIConfig(GuiScreen guiScreen) {
super(
guiScreen,
new ConfigElement(getConfig().getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(),
new ConfigElement<>(ConfigurationHandler.getConfig().getCategory(Configuration.CATEGORY_GENERAL))
.getChildElements(),
OverloadedArmorBar.MODID,
false,
false,
GuiConfig.getAbridgedConfigPath(getConfig().toString()));
GuiConfig.getAbridgedConfigPath(ConfigurationHandler.getConfig().toString()));
}

}
80 changes: 0 additions & 80 deletions src/main/java/locusway/overloadedarmorbar/overlay/ArmorBar.java

This file was deleted.

Loading