diff --git a/build.gradle b/build.gradle index 8946e50..68d7384 100644 --- a/build.gradle +++ b/build.gradle @@ -1,16 +1,16 @@ import org.jetbrains.gradle.ext.Gradle plugins { - id("java") - id("java-library") - id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.7" - id("com.gtnewhorizons.retrofuturagradle") version "1.+" - id("com.matthewprenger.cursegradle") version "1.4.0" - id("io.freefair.lombok") version "8.3" + id 'java' + id 'java-library' + id 'io.freefair.lombok' version '8.+' + id 'com.github.gmazzo.buildconfig' version '4.+' + id 'com.gtnewhorizons.retrofuturagradle' version '1.+' + id 'org.jetbrains.gradle.plugin.idea-ext' version '1.+' } // Add version to the jar name -version project.version +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 java { @@ -23,111 +23,90 @@ java { } tasks.withType(JavaCompile).configureEach { - options.encoding = "UTF-8" + options.encoding = 'UTF-8' options.fork = true } minecraft { - mcVersion = "1.12.2" - - username = "Desoroxxx" - - extraRunJvmArguments.addAll("-Xmx6G", "-Xms4G", "-Dforge.logging.console.level=debug", "-Dfml.coreMods.load=io.redstudioragnarok.redcore.asm.RedCorePlugin") - - injectedTags.put("ID", project.id) - injectedTags.put("VERSION", project.version) -} - -// Generate a my.project.Tags class with the version number as a field -tasks.injectTags.configure { - outputClassName.set("io.redstudioragnarok.${project.id}.Tags") + mcVersion = '1.12.2' + username = 'Desoroxxx' + extraRunJvmArguments.addAll('-Xmx6G', '-Xms4G', '-Dforge.logging.console.level=debug', '-Dfml.coreMods.load=dev.redstudio.redcore.RedCore') } -// Create configuration to include embedded dependencies into the jar configurations { implementation compile.extendsFrom(embed) } dependencies { - implementation "net.jafama:jafama:2.3.2" - embed "net.jafama:jafama:2.3.2" + implementation 'net.jafama:jafama:2.3.2' + embed 'net.jafama:jafama:2.3.2' } -processResources { - inputs.property "id", project.id - inputs.property "version", project.version - filesMatching("mcmod.info") { fcd -> - include "mcmod.info" - fcd.expand ( - "id": project.id, - "version": project.version - ) - } - dependsOn "compileJava" +buildConfig { + buildConfigField("String", "ID", "\"${project.id}\"") + buildConfigField("String", "VERSION", "\"${project.version}\"") } jar { manifest.attributes([ - "ModSide": "BOTH", - "FMLCorePlugin": "io.redstudioragnarok.redcore.asm.RedCorePlugin", - "FMLCorePluginContainsFMLMod": true, - "ForceLoadAsMod": true + 'ModSide': 'BOTH', + 'FMLCorePlugin': 'dev.redstudio.redcore.RedCore', + 'FMLCorePluginContainsFMLMod': true, + 'ForceLoadAsMod': true ]) - // Add all embedded dependencies into the jar - from(provider{ configurations.embed.collect {it.isDirectory() ? it : zipTree(it)} }) - - // Add ! to the name of the jar to make sure we get loaded first - jar.archiveBaseName.set("!Red-Core") + from(provider { configurations.embed.collect { it.isDirectory() ? it : zipTree(it) } }) + archiveBaseName.set('!Red-Core') } idea { module { inheritOutputDirs = true excludeDirs = [ - file(".settings"), - file(".github"), - file(".gradle"), - file("gradle"), - file(".idea"), - file("build"), - file("run"), - file("bin") + file('.settings'), + file('.github'), + file('.gradle'), + file('gradle'), + file('.idea'), + file('build'), + file('run'), + file('bin') ] } - project { settings { - runConfigurations { - "Client"(Gradle) { - taskNames = ["runClient"] - } - "Server"(Gradle) { - taskNames = ["runServer"] + project { + jdkName = '1.8' + languageLevel = '1.8' + + settings { + runConfigurations { + 'Client'(Gradle) { + taskNames = ['runClient'] + } + 'Server'(Gradle) { + taskNames = ['runServer'] + } + 'Obfuscated Client'(Gradle) { + taskNames = ['runObfClient'] + } + 'Obfuscated Server'(Gradle) { + taskNames = ['runObfServer'] + } + 'Vanilla Client'(Gradle) { + taskNames = ['runVanillaClient'] + } + 'Vanilla Server'(Gradle) { + taskNames = ['runVanillaServer'] + } } - "Obfuscated Client"(Gradle) { - taskNames = ["runObfClient"] - } - "Obfuscated Server"(Gradle) { - taskNames = ["runObfServer"] - } - "Vanilla Client"(Gradle) { - taskNames = ["runVanillaClient"] - } - "Vanilla Server"(Gradle) { - taskNames = ["runVanillaServer"] - } - } - compiler.javac { - afterEvaluate { - javacAdditionalOptions = "-encoding utf8" - moduleJavacAdditionalOptions = [ (project.id + ".main"): tasks.compileJava.options.compilerArgs.collect { """ + it + """ }.join(" ") ] + compiler.javac { + afterEvaluate { + javacAdditionalOptions = '-encoding utf8' + moduleJavacAdditionalOptions = [(project.id + '.main'): tasks.compileJava.options.compilerArgs.collect { " $it " }.join(' ')] + } } } - }} -} - -tasks.named("processIdeaSettings").configure { - dependsOn("injectTags") + } } diff --git a/src/main/java/dev/redstudio/redcore/RedCore.java b/src/main/java/dev/redstudio/redcore/RedCore.java index 51d3245..30ef22d 100644 --- a/src/main/java/dev/redstudio/redcore/RedCore.java +++ b/src/main/java/dev/redstudio/redcore/RedCore.java @@ -1,13 +1,17 @@ package dev.redstudio.redcore; -import dev.redstudio.redcore.ticking.RedClientTickEvent; -import dev.redstudio.redcore.ticking.RedClientTicker; -import dev.redstudio.redcore.utils.ModReference; -import dev.redstudio.redcore.utils.OptiNotFine; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; +import com.google.common.eventbus.EventBus; +import net.minecraftforge.fml.common.DummyModContainer; +import net.minecraftforge.fml.common.LoadController; +import net.minecraftforge.fml.common.ModMetadata; +import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; + +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; // /$$$$$$$ /$$ /$$$$$$ // | $$__ $$ | $$ /$$__ $$ @@ -17,39 +21,59 @@ // | $$ \ $$| $$_____/| $$ | $$ | $$ $$| $$ | $$| $$ | $$_____/ // | $$ | $$| $$$$$$$| $$$$$$$ | $$$$$$/| $$$$$$/| $$ | $$$$$$$ // |__/ |__/ \_______/ \_______/ \______/ \______/ |__/ \_______/ -@Mod(modid = ModReference.ID, name = ModReference.NAME, version = ModReference.VERSION, updateJSON = "https://raw.githubusercontent.com/Red-Studio-Ragnarok/Red-Core/main/update.json") -public final class RedCore { - - private static boolean clientTickerStarted = false; - private static boolean forceOptiFineFastRenderOff = false; - - /** - * Starts the client ticker. - *

- * This method registers {@link RedClientTicker} in the {@link MinecraftForge} event bus if the client ticker has not already been started. - *

- * The client ticker is responsible for ticking and thus sending the {@link RedClientTickEvent}. - * - * @author Desoroxxx - * @since 0.3 - */ - @SideOnly(Side.CLIENT) - public static void startClientTicker() { - if (clientTickerStarted) - return; - - MinecraftForge.EVENT_BUS.register(RedClientTicker.class); - clientTickerStarted = true; +@IFMLLoadingPlugin.Name(NAME) +@IFMLLoadingPlugin.MCVersion("1.12.2") +@IFMLLoadingPlugin.SortingIndex(Integer.MIN_VALUE + 2) +public final class RedCore implements IFMLLoadingPlugin { + + @Override + public String[] getASMTransformerClass() { + return new String[0]; + } + + @Override + public String getModContainerClass() { + return "dev.redstudio.redcore.RedCore$Container"; + } + + @Nullable + @Override + public String getSetupClass() { + return null; } - @SideOnly(Side.CLIENT) - public static void forceOptiFineFastRenderOff() { - if (forceOptiFineFastRenderOff) - return; + @Override + public void injectData(final Map data) { + + } + + @Override + public String getAccessTransformerClass() { + return null; + } + + public static class Container extends DummyModContainer { + + public Container() { + super(new ModMetadata()); + + final ModMetadata modMetadata = this.getMetadata(); - startClientTicker(); + modMetadata.modId = ID; + modMetadata.name = "Red Core"; + 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"; + modMetadata.logoFile = "/logo.png"; + modMetadata.version = VERSION; + modMetadata.authorList.add("Red Studio"); + modMetadata.credits = "Desoroxxx"; + } - MinecraftForge.EVENT_BUS.register(OptiNotFine.class); - forceOptiFineFastRenderOff = true; + @Override + public boolean registerBus(final EventBus eventBus, final LoadController loadController) { + eventBus.register(this); + return true; + } } } diff --git a/src/main/java/dev/redstudio/redcore/asm/RedCorePlugin.java b/src/main/java/dev/redstudio/redcore/asm/RedCorePlugin.java deleted file mode 100644 index 46a1a58..0000000 --- a/src/main/java/dev/redstudio/redcore/asm/RedCorePlugin.java +++ /dev/null @@ -1,41 +0,0 @@ -package dev.redstudio.redcore.asm; - -import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; - -import javax.annotation.Nullable; -import java.util.Map; - -import static dev.redstudio.redcore.utils.ModReference.NAME; - -@IFMLLoadingPlugin.Name(NAME) -@IFMLLoadingPlugin.MCVersion("1.12.2") -@IFMLLoadingPlugin.SortingIndex(Integer.MIN_VALUE + 2) -@IFMLLoadingPlugin.TransformerExclusions("io.redstudioragnarok.redcore.asm") -public final class RedCorePlugin implements IFMLLoadingPlugin { - - @Override - public String[] getASMTransformerClass() { - return new String[0]; - } - - @Override - public String getModContainerClass() { - return null; - } - - @Nullable - @Override - public String getSetupClass() { - return null; - } - - @Override - public void injectData(final Map data) { - - } - - @Override - public String getAccessTransformerClass() { - return null; - } -} diff --git a/src/main/java/dev/redstudio/redcore/ticking/RedClientTicker.java b/src/main/java/dev/redstudio/redcore/ticking/RedClientTicker.java index 6d17c3e..62d4249 100644 --- a/src/main/java/dev/redstudio/redcore/ticking/RedClientTicker.java +++ b/src/main/java/dev/redstudio/redcore/ticking/RedClientTicker.java @@ -16,6 +16,8 @@ @SideOnly(Side.CLIENT) public class RedClientTicker { + private static boolean clientTickerStarted = false; + private static int biTickCount, pentaTickCount, decaTickCount; @SubscribeEvent(priority = EventPriority.HIGHEST) @@ -41,4 +43,21 @@ public static void onClientTickEvent(TickEvent.ClientTickEvent clientTickEvent) } } } + + /** + * Starts the client ticker. + *

+ * This method registers {@link RedClientTicker} in the {@link MinecraftForge} event bus if the client ticker has not already been started. + *

+ * The client ticker is responsible for ticking and thus sending the {@link RedClientTickEvent}. + *

+ * For performance reasons, this should be called on any of the init methods in your mod. + * + * @author Desoroxxx + * @since 0.3 + */ + @SideOnly(Side.CLIENT) + public static void startClientTicker() { + MinecraftForge.EVENT_BUS.register(RedClientTicker.class); + } } diff --git a/src/main/java/dev/redstudio/redcore/utils/OptiNotFine.java b/src/main/java/dev/redstudio/redcore/utils/OptiNotFine.java index 50b42dc..8ceae6c 100644 --- a/src/main/java/dev/redstudio/redcore/utils/OptiNotFine.java +++ b/src/main/java/dev/redstudio/redcore/utils/OptiNotFine.java @@ -1,6 +1,8 @@ package dev.redstudio.redcore.utils; +import dev.redstudio.redcore.ticking.RedClientTicker; import net.minecraft.client.Minecraft; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import net.minecraftforge.fml.relauncher.Side; @@ -64,9 +66,21 @@ public static boolean shadersEnabled() { } } + /** + * Forces OptiFine fast render option to be disabled. + *

+ * This method starts the client ticker and registers the OptiNotFine class as an event listener which will attempt to disable OptiFine's fast render each tick. + */ + public static void forceOptiFineFastRenderOff() { + RedClientTicker.startClientTicker(); + + MinecraftForge.EVENT_BUS.register(OptiNotFine.class); + } + /** * Disable OptiFine fast renderer. */ + @SuppressWarnings("JavaReflectionMemberAccess") private static void disableFastRender() { if (!isOptiFineInstalled()) return; diff --git a/src/main/resources/logo.png b/src/main/resources/logo.png new file mode 100644 index 0000000..44d9e42 Binary files /dev/null and b/src/main/resources/logo.png differ diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info deleted file mode 100644 index fb52716..0000000 --- a/src/main/resources/mcmod.info +++ /dev/null @@ -1,11 +0,0 @@ -[ - { - "modid": "${id}", - "name": "Red Core", - "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.", - "version": "${version}", - "url": "https://www.curseforge.com/minecraft/mc-mods/red-core", - "authorList": ["Red Studio"], - "credits": "Desoroxxx" - } -]