diff --git a/build.gradle b/build.gradle index 6c4f927..189df1c 100644 --- a/build.gradle +++ b/build.gradle @@ -10,6 +10,7 @@ plugins { } // Add version to the jar name +group = "dev.redstudio" version = project.version // Set the toolchain version to decouple the Java we run Gradle with from the Java used to compile and run the mod @@ -44,8 +45,15 @@ dependencies { } buildConfig { + className("ProjectConstants") + packageName("dev.redstudio.redcore.utils") + buildConfigField("String", "ID", "\"${project.id}\"") + buildConfigField("String", "NAME", "\"Red Core\"") buildConfigField("String", "VERSION", "\"${project.version}\"") + buildConfigField("org.apache.logging.log4j.Logger", "LOGGER", "LogManager.getLogger(NAME)") + buildConfigField("dev.redstudio.redcore.logging.RedLogger", "RED_LOGGER", "new RedLogger(NAME, \"https://linkify.cz/RedCoreBugReport\", LOGGER)") + buildConfigField("org.apache.logging.log4j.LogManager", "DO_NOT_USE", "null") } jar { diff --git a/src/main/java/dev/redstudio/redcore/RedCore.java b/src/main/java/dev/redstudio/redcore/RedCore.java index 30ef22d..a1b9896 100644 --- a/src/main/java/dev/redstudio/redcore/RedCore.java +++ b/src/main/java/dev/redstudio/redcore/RedCore.java @@ -1,6 +1,7 @@ package dev.redstudio.redcore; import com.google.common.eventbus.EventBus; +import dev.redstudio.redcore.utils.ProjectConstants; import net.minecraftforge.fml.common.DummyModContainer; import net.minecraftforge.fml.common.LoadController; import net.minecraftforge.fml.common.ModMetadata; @@ -9,9 +10,7 @@ import javax.annotation.Nullable; import java.util.Map; -import static dev.redstudio.redcore.utils.ModReference.ID; -import static dev.redstudio.redcore.utils.ModReference.NAME; -import static dev.redstudio.redcore.utils.ModReference.VERSION; +import static dev.redstudio.redcore.utils.ProjectConstants.*; // /$$$$$$$ /$$ /$$$$$$ // | $$__ $$ | $$ /$$__ $$ @@ -60,7 +59,7 @@ public Container() { final ModMetadata modMetadata = this.getMetadata(); modMetadata.modId = ID; - modMetadata.name = "Red Core"; + modMetadata.name = NAME; modMetadata.description = "§lRed-Core§r\n\nRed-Core is the foundational framework for Red Studio projects and associated projects. It features robust development utilities, streamlined error logging, and a high-speed, clean vectors' suite.\n\n§lFeatures§r\n\n- §lRedLogger:§r This robust error logger elevates error tracking, offering a clean, user-friendly experience that demystifies complex error data.\n- §lVectors:§r Introducing a comprehensive vector suite that is sleek and speedy, continuously evolving with new features as per necessity.\n- §lMathUtil:§r A purpose-built class providing an array of mathematical methods, engineered with a steadfast focus on rapid processing and calculations.\n- §lStopwatch:§r Tailored for precise profiling, this stopwatch sets itself apart in the burgeoning roster of Java-based stopwatch solutions, by its simplicity and easy of use.\n- §lRedClientTicker:§r A useful ticker that allows you to have ticks every 2, 5 or 10 normal ticks, for things that shouldn't run 20 times a second.\n- §lOptiNotFine:§r A must-have when working with OptiFine compatibility, it allows you to know if OptiFine is installed, whether shaders are loaded, and to force fast render off.\n- §lNetworkUtil:§r Designed to streamline network coding practices, this utility makes writing cleaner, safer, and more efficient networking code effortless.\n- §lJafama:§r Red Core embeds Jafama allowing you to use it in your mods\n\n§lWhy Red-Core?§r\n\nRed-Core sits at the heart of Red Studio's Minecraft 1.12 mods, aiming to make your mod development process more efficient. By providing a set of tailored tools and libraries, we allow you to focus more on designing exciting mods and less on the intricacies of development.\n\nWhat sets us apart is our comprehensive Javadoc documentation. We believe good documentation is the cornerstone of effective development. Every method in Red-Core comes with detailed Javadoc comments, making the technical information and guidance you need just a ctrl-click away.\n\nJoin us in enhancing Red-Core! We believe in constant evolution and the power of community-driven development. Whether you're a contributor or a user in the Minecraft modding community, your experience matters. We're here to ensure it's the best it can be."; modMetadata.url = "https://www.curseforge.com/minecraft/mc-mods/red-core"; modMetadata.updateJSON = "https://raw.githubusercontent.com/Red-Studio-Ragnarok/Red-Core/main/update.json"; diff --git a/src/main/java/dev/redstudio/redcore/utils/MathUtil.java b/src/main/java/dev/redstudio/redcore/utils/MathUtil.java index a8a8c2a..e1ea403 100644 --- a/src/main/java/dev/redstudio/redcore/utils/MathUtil.java +++ b/src/main/java/dev/redstudio/redcore/utils/MathUtil.java @@ -2,7 +2,7 @@ import net.jafama.FastMath; -import static dev.redstudio.redcore.utils.ModReference.LOG; +import static dev.redstudio.redcore.utils.ProjectConstants.LOGGER; /** * A utility class that offers efficient mathematical operations such as clamping, absolute value calculation, linear interpolation, and rounding operations. @@ -62,13 +62,13 @@ public static float clampMaxFirst(final float input, final float min, final floa */ public static float clampTest(final float input, final float min, final float max) { if (input < min) { - LOG.info("Clamped to minimum"); + LOGGER.info("Clamped to minimum"); return min; } else if (input > max) { - LOG.info("Clamped to maximum"); + LOGGER.info("Clamped to maximum"); return max; } else { - LOG.info("Did not clamp"); + LOGGER.info("Did not clamp"); return input; } } @@ -121,13 +121,13 @@ public static double clampMaxFirst(final double input, final double min, final d */ public static double clampTest(final double input, final double min, final double max) { if (input < min) { - LOG.info("Clamped to minimum"); + LOGGER.info("Clamped to minimum"); return min; } else if (input > max) { - LOG.info("Clamped to maximum"); + LOGGER.info("Clamped to maximum"); return max; } else { - LOG.info("Did not clamp"); + LOGGER.info("Did not clamp"); return input; } } @@ -180,13 +180,13 @@ public static byte clampMaxFirst(final byte input, final byte min, final byte ma */ public static byte clampTest(final byte input, final byte min, final byte max) { if (input < min) { - LOG.info("Clamped to minimum"); + LOGGER.info("Clamped to minimum"); return min; } else if (input > max) { - LOG.info("Clamped to maximum"); + LOGGER.info("Clamped to maximum"); return max; } else { - LOG.info("Did not clamp"); + LOGGER.info("Did not clamp"); return input; } } @@ -239,13 +239,13 @@ public static short clampMaxFirst(final short input, final short min, final shor */ public static short clampTest(final short input, final short min, final short max) { if (input < min) { - LOG.info("Clamped to minimum"); + LOGGER.info("Clamped to minimum"); return min; } else if (input > max) { - LOG.info("Clamped to maximum"); + LOGGER.info("Clamped to maximum"); return max; } else { - LOG.info("Did not clamp"); + LOGGER.info("Did not clamp"); return input; } } @@ -298,13 +298,13 @@ public static int clampMaxFirst(final int input, final int min, final int max) { */ public static int clampTest(final int input, final int min, final int max) { if (input < min) { - LOG.info("Clamped to minimum"); + LOGGER.info("Clamped to minimum"); return min; } else if (input > max) { - LOG.info("Clamped to maximum"); + LOGGER.info("Clamped to maximum"); return max; } else { - LOG.info("Did not clamp"); + LOGGER.info("Did not clamp"); return input; } } diff --git a/src/main/java/dev/redstudio/redcore/utils/ModReference.java b/src/main/java/dev/redstudio/redcore/utils/ModReference.java deleted file mode 100644 index faf1991..0000000 --- a/src/main/java/dev/redstudio/redcore/utils/ModReference.java +++ /dev/null @@ -1,20 +0,0 @@ -package dev.redstudio.redcore.utils; - -import dev.redstudio.redcore.logging.RedLogger; -import dev.redstudio.redcore.Tags; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -/** - * This class defines constants for Red Core. - *
- * ID and VERSION are automatically updated by RFG. - */ -public class ModReference { - - public static final String ID = Tags.ID; - public static final String NAME = "Red Core"; - public static final String VERSION = Tags.VERSION; - public static final Logger LOG = LogManager.getLogger(NAME); - public static final RedLogger RED_LOG = new RedLogger(NAME, "https://linkify.cz/RedCoreBugReport", LOG); -} diff --git a/src/main/java/dev/redstudio/redcore/utils/OptiNotFine.java b/src/main/java/dev/redstudio/redcore/utils/OptiNotFine.java index 8ceae6c..94b84ab 100644 --- a/src/main/java/dev/redstudio/redcore/utils/OptiNotFine.java +++ b/src/main/java/dev/redstudio/redcore/utils/OptiNotFine.java @@ -10,7 +10,7 @@ import java.lang.reflect.Field; -import static dev.redstudio.redcore.utils.ModReference.RED_LOG; +import static dev.redstudio.redcore.utils.ProjectConstants.RED_LOGGER; /** * This class provides methods to communicate with OptiNotFine (Can you see that I hate OptiFine?) @@ -61,7 +61,7 @@ public static boolean shadersEnabled() { return (boolean) shaderPackLoadedField.get(null); } catch (IllegalAccessException | ClassNotFoundException | NoSuchFieldException exception) { - RED_LOG.printFramedError("OptiNotFine", "Could not get OptiFine shaders status.", "If shaders are enabled things might break", exception.getMessage()); + RED_LOGGER.printFramedError("OptiNotFine", "Could not get OptiFine shaders status.", "If shaders are enabled things might break", exception.getMessage()); return false; } } @@ -92,7 +92,7 @@ private static void disableFastRender() { if (fastRenderField.getBoolean(Minecraft.getMinecraft().gameSettings)) fastRenderField.set(Minecraft.getMinecraft().gameSettings, false); } catch (IllegalAccessException | ClassNotFoundException | NoSuchFieldException exception) { - RED_LOG.printFramedError("OptiNotFine", "Could not disable OptiFine fast renderer", "Things will break", exception.getMessage()); + RED_LOGGER.printFramedError("OptiNotFine", "Could not disable OptiFine fast renderer", "Things will break", exception.getMessage()); } } diff --git a/src/main/java/dev/redstudio/redcore/utils/Stopwatch.java b/src/main/java/dev/redstudio/redcore/utils/Stopwatch.java index 0e8b097..5586f46 100644 --- a/src/main/java/dev/redstudio/redcore/utils/Stopwatch.java +++ b/src/main/java/dev/redstudio/redcore/utils/Stopwatch.java @@ -4,8 +4,8 @@ import java.util.HashMap; import java.util.Map; -import static dev.redstudio.redcore.utils.ModReference.LOG; -import static dev.redstudio.redcore.utils.ModReference.RED_LOG; +import static dev.redstudio.redcore.utils.ProjectConstants.LOGGER; +import static dev.redstudio.redcore.utils.ProjectConstants.RED_LOGGER; /** * A utility class for measuring elapsed time in milliseconds between two points in the code. @@ -34,7 +34,7 @@ public static int start() { int id = nextId++; startTimes.put(id, System.nanoTime()); - LOG.info("Started chronometer with " + id); + LOGGER.info("Started chronometer with " + id); return id; } @@ -48,7 +48,7 @@ public static void stop(int id) { double elapsed = (System.nanoTime() - startTimes.get(id)) / 1_000_000.0; String elapsedFormatted = String.format("%.2f", elapsed); - LOG.info("Time elapsed for chronometer with id " + id + ": " + elapsedFormatted + "ms"); + LOGGER.info("Time elapsed for chronometer with id " + id + ": " + elapsedFormatted + "ms"); startTimes.remove(id); } @@ -62,14 +62,14 @@ public static void stopAndWriteToFile(int id, String filePath) { double elapsed = (System.nanoTime() - startTimes.get(id)) / 1_000_000.0; String elapsedFormatted = String.format("%.2f", elapsed); - LOG.info("Time elapsed for chronometer with id " + id + ": " + elapsedFormatted + "ms"); + LOGGER.info("Time elapsed for chronometer with id " + id + ": " + elapsedFormatted + "ms"); startTimes.remove(id); try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath, true))) { writer.write(elapsedFormatted); writer.newLine(); } catch (IOException ioException) { - RED_LOG.printFramedError("Stopwatch", "Failed to write file", "", ioException.getMessage(), ioException.getStackTrace()[3].toString()); + RED_LOGGER.printFramedError("Stopwatch", "Failed to write file", "", ioException.getMessage(), ioException.getStackTrace()[3].toString()); } } @@ -89,13 +89,13 @@ public static void calculateAverage(String filePath) { count++; } } catch (IOException ioException) { - RED_LOG.printFramedError("Stopwatch", "Failed to read file", "", ioException.getMessage(), ioException.getStackTrace()[3].toString()); + RED_LOGGER.printFramedError("Stopwatch", "Failed to read file", "", ioException.getMessage(), ioException.getStackTrace()[3].toString()); } if (count > 0) { String averageFormatted = String.format("%.2f", sum / count); - LOG.info("Average elapsed time between " + count + " entries: " + averageFormatted + "ms"); + LOGGER.info("Average elapsed time between " + count + " entries: " + averageFormatted + "ms"); } else - LOG.warn("No elapsed times found in file."); + LOGGER.warn("No elapsed times found in file."); } }