Skip to content

Commit

Permalink
Fully switch to buildconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Desoroxxx committed Sep 19, 2023
1 parent 49b0e3d commit c983307
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 52 deletions.
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/dev/redstudio/redcore/RedCore.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.*;

// /$$$$$$$ /$$ /$$$$$$
// | $$__ $$ | $$ /$$__ $$
Expand Down Expand Up @@ -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";
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/dev/redstudio/redcore/utils/MathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
20 changes: 0 additions & 20 deletions src/main/java/dev/redstudio/redcore/utils/ModReference.java

This file was deleted.

6 changes: 3 additions & 3 deletions src/main/java/dev/redstudio/redcore/utils/OptiNotFine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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());
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/dev/redstudio/redcore/utils/Stopwatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}

Expand All @@ -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());
}
}

Expand All @@ -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.");
}
}

0 comments on commit c983307

Please sign in to comment.