diff --git a/build.gradle b/build.gradle index 1ec9b2791..516025ba3 100644 --- a/build.gradle +++ b/build.gradle @@ -7,14 +7,24 @@ plugins { println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" +boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equalsIgnoreCase('false'); + +ext.buildNumber = System.getenv('BUILD_NUMBER') + subprojects { - boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equalsIgnoreCase('false'); - - ext.buildNumber = System.getenv('BUILD_NUMBER') - group = 'com.jozufozu.flywheel' version = mod_version + (dev && buildNumber != null ? "-${buildNumber}" : '') + apply plugin: "maven-publish" + apply plugin: "dev.architectury.loom" + apply from: rootProject.file('gradle/package-infos.gradle') + + loom { + silentMojangMappingsLicense() + } + + ideaSyncTask.finalizedBy(generatePackageInfos) + tasks { // make builds reproducible withType(AbstractArchiveTask).configureEach { @@ -27,6 +37,110 @@ subprojects { enabled = false } } + + processResources.configure { + from(project(':common').sourceSets.main.resources) + + var replaceProperties = [ + minecraft_version : minecraft_version, + minecraft_version_range: minecraft_version_range, + forge_version : forge_version, + forge_version_range : forge_version_range, + loader_version_range : loader_version_range, + mod_version : mod_version + ] + inputs.properties replaceProperties + + filesMatching(['META-INF/mods.toml', 'META-INF/neoforge.mods.toml', 'pack.mcmeta', 'fabric.mod.json']) { + expand replaceProperties + [project: project] + } + } + + repositories { + maven { + name = 'ParchmentMC' + url = 'https://maven.parchmentmc.org' + } + maven { + url 'https://www.cursemaven.com' + content { + includeGroup "curse.maven" + } + } + maven { + name 'tterrag maven' + url 'https://maven.tterrag.com/' + } + maven { + name = "Modrinth" + url = "https://api.modrinth.com/maven" + content { + includeGroup "maven.modrinth" + } + } + mavenCentral() + } + + dependencies { + minecraft "com.mojang:minecraft:$minecraft_version" + mappings(loom.layered() { + officialMojangMappings() + parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip") + }) + } + + java { + JavaVersion javaVersion = JavaVersion.toVersion(java_version) + sourceCompatibility = javaVersion + targetCompatibility = javaVersion + + toolchain.languageVersion = JavaLanguageVersion.of(java_version) + + withSourcesJar() + withJavadocJar() + } + + tasks.withType(JavaCompile).configureEach { + options.encoding = 'UTF-8' + options.release = Integer.parseInt(java_version) + options.compilerArgs = ['-Xdiags:verbose'] + } + + jar.configure { + archiveClassifier = '' + addManifest(it) + addLicense(it) + } + + sourcesJar.configure { + addManifest(it) + addLicense(it) + } + + javadoc.configure { + // prevent java 8's strict doclint for javadocs from failing builds + options.addStringOption('Xdoclint:none', '-quiet') + } +} + +void addLicense(jarTask) { + jarTask.from('LICENSE.md') { + rename '(.*)\\.(.*)', '$1_' + jarTask.archiveBaseName + '.$2' + } +} + +void addManifest(jarTask) { + jarTask.manifest { + attributes([ + 'Specification-Title' : 'flywheel', + // 'Specification-Vendor': 'flywheel authors', + 'Specification-Version' : '1', // We are version 1 of ourselves + 'Implementation-Title' : jarTask.archiveBaseName, + 'Implementation-Version' : jarTask.archiveVersion, + // 'Implementation-Vendor': 'flywheel authors', + 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), + ]) + } } idea { diff --git a/common/build.gradle b/common/build.gradle index cd95427fe..061701ba7 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,126 +1,17 @@ -plugins { - id 'maven-publish' - id 'dev.architectury.loom' -} - base { archivesName = "flywheel-${project.name}-${artifact_minecraft_version}" } -repositories { - maven { - name = 'ParchmentMC' - url = 'https://maven.parchmentmc.org' - } - maven { - url 'https://www.cursemaven.com' - content { - includeGroup "curse.maven" - } - } - maven { - name 'tterrag maven' - url 'https://maven.tterrag.com/' - } - maven { - name = "Modrinth" - url = "https://api.modrinth.com/maven" - content { - includeGroup "maven.modrinth" - } - } - mavenCentral() -} - dependencies { - minecraft "com.mojang:minecraft:$minecraft_version" - mappings(loom.layered() { - officialMojangMappings() - parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip") - }) - modCompileOnly "net.fabricmc:fabric-loader:$fabric_loader_version" compileOnly "com.google.code.findbugs:jsr305:3.0.2" } -java { - JavaVersion javaVersion = JavaVersion.toVersion(java_version) - sourceCompatibility = javaVersion - targetCompatibility = javaVersion - - toolchain.languageVersion = JavaLanguageVersion.of(java_version) - - withSourcesJar() - withJavadocJar() -} - -processResources.configure { - from(project(':common').sourceSets.main.resources) - - var replaceProperties = [ - minecraft_version : minecraft_version, - minecraft_version_range: minecraft_version_range, - forge_version : forge_version, - forge_version_range : forge_version_range, - loader_version_range : loader_version_range, - mod_version : mod_version - ] - inputs.properties replaceProperties - - filesMatching(['META-INF/mods.toml', 'META-INF/neoforge.mods.toml', 'pack.mcmeta', 'fabric.mod.json']) { - expand replaceProperties + [project: project] - } -} - -tasks.withType(JavaCompile).configureEach { - options.encoding = 'UTF-8' - options.release = Integer.parseInt(java_version) - options.compilerArgs = ['-Xdiags:verbose'] -} - -jar.configure { - archiveClassifier = '' - addManifest(it) - addLicense(it) -} - -sourcesJar.configure { - addManifest(it) - addLicense(it) -} - -javadoc.configure { - // prevent java 8's strict doclint for javadocs from failing builds - options.addStringOption('Xdoclint:none', '-quiet') -} - test.configure { useJUnitPlatform() } -void addLicense(jarTask) { - jarTask.from('LICENSE.md') { - rename '(.*)\\.(.*)', '$1_' + archivesBaseName + '.$2' - } -} - -void addManifest(jarTask) { - jarTask.manifest { - attributes([ - 'Specification-Title' : 'flywheel', - // 'Specification-Vendor': 'flywheel authors', - 'Specification-Version' : '1', // We are version 1 of ourselves - 'Implementation-Title' : project.jar.archiveBaseName, - 'Implementation-Version' : project.jar.archiveVersion, - // 'Implementation-Vendor': 'flywheel authors', - 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), - ]) - } -} - -apply from: rootProject.file('gradle/package-infos.gradle') - publishing { publications { register('mavenJava', MavenPublication) { diff --git a/common/src/main/java/com/jozufozu/flywheel/Flywheel.java b/common/src/main/java/com/jozufozu/flywheel/Flywheel.java index 290722f23..37ab7a864 100644 --- a/common/src/main/java/com/jozufozu/flywheel/Flywheel.java +++ b/common/src/main/java/com/jozufozu/flywheel/Flywheel.java @@ -1,120 +1,30 @@ package com.jozufozu.flywheel; -import java.util.ArrayList; - -import org.apache.maven.artifact.versioning.ArtifactVersion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.jozufozu.flywheel.api.event.EndClientResourceReloadEvent; -import com.jozufozu.flywheel.api.visualization.VisualizationManager; import com.jozufozu.flywheel.backend.Backends; import com.jozufozu.flywheel.backend.ShaderIndices; -import com.jozufozu.flywheel.backend.compile.FlwPrograms; -import com.jozufozu.flywheel.backend.engine.uniform.Uniforms; -import com.jozufozu.flywheel.config.BackendArgument; -import com.jozufozu.flywheel.config.FlwCommands; -import com.jozufozu.flywheel.config.FlwConfig; import com.jozufozu.flywheel.impl.BackendManagerImpl; import com.jozufozu.flywheel.impl.registry.IdRegistryImpl; import com.jozufozu.flywheel.impl.registry.RegistryImpl; -import com.jozufozu.flywheel.impl.visualization.VisualizationEventHandler; import com.jozufozu.flywheel.lib.instance.InstanceTypes; import com.jozufozu.flywheel.lib.material.CutoutShaders; import com.jozufozu.flywheel.lib.material.FogShaders; import com.jozufozu.flywheel.lib.material.StandardMaterialShaders; -import com.jozufozu.flywheel.lib.memory.FlwMemoryTracker; -import com.jozufozu.flywheel.lib.model.ModelCache; -import com.jozufozu.flywheel.lib.model.ModelHolder; -import com.jozufozu.flywheel.lib.model.baked.PartialModel; -import com.jozufozu.flywheel.lib.util.LevelAttached; import com.jozufozu.flywheel.lib.util.ShadersModHandler; -import com.jozufozu.flywheel.lib.util.StringUtil; -import com.jozufozu.flywheel.vanilla.VanillaVisuals; -import net.minecraft.client.Minecraft; -import net.minecraft.commands.synchronization.ArgumentTypeInfos; -import net.minecraft.core.Vec3i; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.client.event.CustomizeGuiOverlayEvent; -import net.minecraftforge.client.event.RegisterClientReloadListenersEvent; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.level.LevelEvent; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.fml.DistExecutor; -import net.minecraftforge.fml.IExtensionPoint; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; -import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegisterEvent; -@Mod(Flywheel.ID) public class Flywheel { public static final String ID = "flywheel"; public static final Logger LOGGER = LoggerFactory.getLogger(ID); - private static ArtifactVersion version; - public Flywheel() { - ModLoadingContext modLoadingContext = ModLoadingContext.get(); - - version = modLoadingContext - .getActiveContainer() - .getModInfo() - .getVersion(); - - IEventBus forgeEventBus = MinecraftForge.EVENT_BUS; - IEventBus modEventBus = FMLJavaModLoadingContext.get() - .getModEventBus(); - modEventBus.addListener(Flywheel::onCommonSetup); - modEventBus.addListener(Flywheel::onRegister); - - FlwConfig.get().registerSpecs(modLoadingContext); - - modLoadingContext.registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest( - () -> "any", - (serverVersion, isNetwork) -> true - )); - - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> Flywheel.clientInit(forgeEventBus, modEventBus)); + public static ResourceLocation rl(String path) { + return new ResourceLocation(ID, path); } - private static void clientInit(IEventBus forgeEventBus, IEventBus modEventBus) { - forgeEventBus.addListener(Flywheel::addDebugInfo); - - forgeEventBus.addListener(BackendManagerImpl::onReloadLevelRenderer); - - forgeEventBus.addListener(VisualizationEventHandler::onClientTick); - forgeEventBus.addListener(VisualizationEventHandler::onBeginFrame); - forgeEventBus.addListener(VisualizationEventHandler::onRenderStage); - forgeEventBus.addListener(VisualizationEventHandler::onEntityJoinLevel); - forgeEventBus.addListener(VisualizationEventHandler::onEntityLeaveLevel); - - forgeEventBus.addListener(FlwCommands::registerClientCommands); - - forgeEventBus.addListener(Uniforms::onReloadLevelRenderer); - - forgeEventBus.addListener((LevelEvent.Unload e) -> LevelAttached.onUnloadLevel(e)); - -// forgeEventBus.addListener(ExampleEffect::tick); -// forgeEventBus.addListener(ExampleEffect::onReload); - - modEventBus.addListener(Flywheel::registerClientReloadListeners); - modEventBus.addListener(Flywheel::onClientSetup); - modEventBus.addListener(Flywheel::onLoadComplete); - - modEventBus.addListener(BackendManagerImpl::onEndClientResourceReload); - - modEventBus.addListener((EndClientResourceReloadEvent e) -> ModelCache.onEndClientResourceReload(e)); - modEventBus.addListener(ModelHolder::onEndClientResourceReload); - - modEventBus.addListener(PartialModel::onModelRegistry); - modEventBus.addListener(PartialModel::onModelBake); - + public static void earlyInit() { BackendManagerImpl.init(); ShadersModHandler.init(); @@ -122,64 +32,17 @@ public class Flywheel { Backends.init(); } - private static void registerClientReloadListeners(RegisterClientReloadListenersEvent event) { - event.registerReloadListener(FlwPrograms.ResourceReloadListener.INSTANCE); - } - - private static void onClientSetup(FMLClientSetupEvent event) { + public static void init() { InstanceTypes.init(); CutoutShaders.init(); FogShaders.init(); StandardMaterialShaders.init(); ShaderIndices.init(); - - VanillaVisuals.init(); } - private static void onLoadComplete(FMLLoadCompleteEvent event) { + public static void freeze() { RegistryImpl.freezeAll(); IdRegistryImpl.freezeAll(); } - - private static void onCommonSetup(FMLCommonSetupEvent event) { - ArgumentTypeInfos.registerByClass(BackendArgument.class, BackendArgument.INFO); - } - - private static void onRegister(RegisterEvent event) { - event.register(ForgeRegistries.Keys.COMMAND_ARGUMENT_TYPES, rl("backend"), () -> BackendArgument.INFO); - } - - private static void addDebugInfo(CustomizeGuiOverlayEvent.DebugText event) { - Minecraft mc = Minecraft.getInstance(); - - if (!mc.options.renderDebug) { - return; - } - - ArrayList info = event.getRight(); - info.add(""); - info.add("Flywheel: " + getVersion()); - info.add("Backend: " + BackendManagerImpl.getBackendString()); - info.add("Update limiting: " + (FlwConfig.get().limitUpdates() ? "on" : "off")); - - VisualizationManager manager = VisualizationManager.get(mc.level); - if (manager != null) { - info.add("B: " + manager.getBlockEntities().getVisualCount() - + ", E: " + manager.getEntities().getVisualCount() - + ", F: " + manager.getEffects().getVisualCount()); - Vec3i renderOrigin = manager.getRenderOrigin(); - info.add("Origin: " + renderOrigin.getX() + ", " + renderOrigin.getY() + ", " + renderOrigin.getZ()); - } - - info.add("Memory Usage: CPU: " + StringUtil.formatBytes(FlwMemoryTracker.getCPUMemory()) + ", GPU: " + StringUtil.formatBytes(FlwMemoryTracker.getGPUMemory())); - } - - public static ArtifactVersion getVersion() { - return version; - } - - public static ResourceLocation rl(String path) { - return new ResourceLocation(ID, path); - } } diff --git a/common/src/main/java/com/jozufozu/flywheel/backend/mixin/GlStateManagerMixin.java b/common/src/main/java/com/jozufozu/flywheel/backend/mixin/GlStateManagerMixin.java index 695e4399d..2c0b4ecdb 100644 --- a/common/src/main/java/com/jozufozu/flywheel/backend/mixin/GlStateManagerMixin.java +++ b/common/src/main/java/com/jozufozu/flywheel/backend/mixin/GlStateManagerMixin.java @@ -9,7 +9,7 @@ import com.jozufozu.flywheel.backend.gl.GlStateTracker; import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType; import com.mojang.blaze3d.platform.GlStateManager; -@Mixin(GlStateManager.class) +@Mixin(value = GlStateManager.class, remap = false) abstract class GlStateManagerMixin { @Inject(method = "_glBindBuffer(II)V", at = @At("RETURN")) private static void flywheel$onBindBuffer(int target, int buffer, CallbackInfo ci) { diff --git a/common/src/main/java/com/jozufozu/flywheel/backend/mixin/RenderSystemMixin.java b/common/src/main/java/com/jozufozu/flywheel/backend/mixin/RenderSystemMixin.java index c29da817b..fb12d286d 100644 --- a/common/src/main/java/com/jozufozu/flywheel/backend/mixin/RenderSystemMixin.java +++ b/common/src/main/java/com/jozufozu/flywheel/backend/mixin/RenderSystemMixin.java @@ -9,7 +9,7 @@ import com.jozufozu.flywheel.backend.engine.uniform.FogUniforms; import com.jozufozu.flywheel.backend.gl.GlCompat; import com.mojang.blaze3d.systems.RenderSystem; -@Mixin(RenderSystem.class) +@Mixin(value = RenderSystem.class, remap = false) abstract class RenderSystemMixin { @Inject(method = "initRenderer(IZ)V", at = @At("RETURN")) private static void flywheel$onInitRenderer(CallbackInfo ci) { diff --git a/fabric/build.gradle b/fabric/build.gradle index ab6142982..f6749b800 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -1,8 +1,3 @@ -plugins { - id 'maven-publish' - id 'dev.architectury.loom' -} - evaluationDependsOn(':common') base { @@ -30,38 +25,7 @@ loom { } } -repositories { - maven { - name = 'ParchmentMC' - url = 'https://maven.parchmentmc.org' - } - maven { - url 'https://www.cursemaven.com' - content { - includeGroup "curse.maven" - } - } - maven { - name 'tterrag maven' - url 'https://maven.tterrag.com/' - } - maven { - name = "Modrinth" - url = "https://api.modrinth.com/maven" - content { - includeGroup "maven.modrinth" - } - } - mavenCentral() -} - dependencies { - minecraft "com.mojang:minecraft:$minecraft_version" - mappings(loom.layered() { - officialMojangMappings() - parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip") - }) - modCompileOnly "net.fabricmc:fabric-loader:$fabric_loader_version" modLocalRuntime "net.fabricmc:fabric-loader:$fabric_loader_version" @@ -79,86 +43,18 @@ dependencies { compileOnly "com.google.code.findbugs:jsr305:3.0.2" } -java { - JavaVersion javaVersion = JavaVersion.toVersion(java_version) - sourceCompatibility = javaVersion - targetCompatibility = javaVersion - - toolchain.languageVersion = JavaLanguageVersion.of(java_version) - - withSourcesJar() - withJavadocJar() -} - -processResources.configure { - from(project(':common').sourceSets.main.resources) - - var replaceProperties = [ - minecraft_version : minecraft_version, - minecraft_version_range: minecraft_version_range, - forge_version : forge_version, - forge_version_range : forge_version_range, - loader_version_range : loader_version_range, - mod_version : mod_version - ] - inputs.properties replaceProperties - - filesMatching(['META-INF/mods.toml', 'META-INF/neoforge.mods.toml', 'pack.mcmeta', 'fabric.mod.json']) { - expand replaceProperties + [project: project] - } -} - tasks.withType(JavaCompile).configureEach { source(project(':common').sourceSets.main.allSource) - options.encoding = 'UTF-8' - options.release = Integer.parseInt(java_version) - options.compilerArgs = ['-Xdiags:verbose'] -} - -jar.configure { - archiveClassifier = '' - addManifest(it) - addLicense(it) } sourcesJar.configure { from(project(':common').sourceSets.main.allSource) - addManifest(it) - addLicense(it) } javadoc.configure { source(project(':common').sourceSets.main.allJava) - // prevent java 8's strict doclint for javadocs from failing builds - options.addStringOption('Xdoclint:none', '-quiet') } -test.configure { - useJUnitPlatform() -} - -void addLicense(jarTask) { - jarTask.from('LICENSE.md') { - rename '(.*)\\.(.*)', '$1_' + archivesBaseName + '.$2' - } -} - -void addManifest(jarTask) { - jarTask.manifest { - attributes([ - 'Specification-Title' : 'flywheel', - // 'Specification-Vendor': 'flywheel authors', - 'Specification-Version' : '1', // We are version 1 of ourselves - 'Implementation-Title' : project.jar.archiveBaseName, - 'Implementation-Version' : project.jar.archiveVersion, - // 'Implementation-Vendor': 'flywheel authors', - 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), - ]) - } -} - -apply from: rootProject.file('gradle/package-infos.gradle') - publishing { publications { register('mavenJava', MavenPublication) { diff --git a/fabric/src/main/java/com/jozufozu/flywheel/FlywheelFabric.java b/fabric/src/main/java/com/jozufozu/flywheel/FlywheelFabric.java new file mode 100644 index 000000000..b6353f97c --- /dev/null +++ b/fabric/src/main/java/com/jozufozu/flywheel/FlywheelFabric.java @@ -0,0 +1,10 @@ +package com.jozufozu.flywheel; + +import net.fabricmc.api.ClientModInitializer; + +public class FlywheelFabric implements ClientModInitializer { + @Override + public void onInitializeClient() { + + } +} diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..b62133644 --- /dev/null +++ b/fabric/src/main/resources/fabric.mod.json @@ -0,0 +1,32 @@ +{ + "schemaVersion": 1, + "id": "flywheel", + "version": "${version}", + "name": "Flywheel", + "description": "A modern engine for modded minecraft.", + "authors": [ + "Jozufozu", + "PepperCode1" + ], + "contact": { + "homepage": "https://fabricmc.net/", + "sources": "https://github.com/FabricMC/fabric-example-mod" + }, + "license": "MIT", + "icon": "assets/flywheel/logo.png", + "environment": "*", + "entrypoints": { + "client": [ + "com.jozufozu.flywheel.FlywheelFabric" + ] + }, + "mixins": [ + "flywheel.backend.mixins.json", + "flywheel.impl.mixins.json", + "flywheel.impl.sodium.mixins.json" + ], + "depends": { + "fabric": "*", + "minecraft": ">=1.20.1" + } +} diff --git a/forge/build.gradle b/forge/build.gradle index eb5e84009..8ec5cd047 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -1,8 +1,3 @@ -plugins { - id 'maven-publish' - id 'dev.architectury.loom' -} - evaluationDependsOn(':common') base { @@ -10,6 +5,12 @@ base { } loom { + forge { + mixinConfig "flywheel.backend.mixins.json" + mixinConfig "flywheel.impl.mixins.json" + mixinConfig "flywheel.impl.sodium.mixins.json" + } + runs { configureEach { property 'forge.logging.markers', '' @@ -30,38 +31,7 @@ loom { } } -repositories { - maven { - name = 'ParchmentMC' - url = 'https://maven.parchmentmc.org' - } - maven { - url 'https://www.cursemaven.com' - content { - includeGroup "curse.maven" - } - } - maven { - name 'tterrag maven' - url 'https://maven.tterrag.com/' - } - maven { - name = "Modrinth" - url = "https://api.modrinth.com/maven" - content { - includeGroup "maven.modrinth" - } - } - mavenCentral() -} - dependencies { - minecraft "com.mojang:minecraft:$minecraft_version" - mappings(loom.layered() { - officialMojangMappings() - parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip") - }) - forge "net.minecraftforge:forge:${minecraft_version}-${forge_version}" compileOnly project(path: ':common', configuration: 'namedElements') @@ -72,86 +42,18 @@ dependencies { compileOnly "com.google.code.findbugs:jsr305:3.0.2" } -java { - JavaVersion javaVersion = JavaVersion.toVersion(java_version) - sourceCompatibility = javaVersion - targetCompatibility = javaVersion - - toolchain.languageVersion = JavaLanguageVersion.of(java_version) - - withSourcesJar() - withJavadocJar() -} - -processResources.configure { - from(project(':common').sourceSets.main.resources) - - var replaceProperties = [ - minecraft_version : minecraft_version, - minecraft_version_range: minecraft_version_range, - forge_version : forge_version, - forge_version_range : forge_version_range, - loader_version_range : loader_version_range, - mod_version : mod_version - ] - inputs.properties replaceProperties - - filesMatching(['META-INF/mods.toml', 'META-INF/neoforge.mods.toml', 'pack.mcmeta', 'fabric.mod.json']) { - expand replaceProperties + [project: project] - } -} - tasks.withType(JavaCompile).configureEach { source(project(':common').sourceSets.main.allSource) - options.encoding = 'UTF-8' - options.release = Integer.parseInt(java_version) - options.compilerArgs = ['-Xdiags:verbose'] -} - -jar.configure { - archiveClassifier = '' - addManifest(it) - addLicense(it) } sourcesJar.configure { from(project(':common').sourceSets.main.allSource) - addManifest(it) - addLicense(it) } javadoc.configure { source(project(':common').sourceSets.main.allJava) - // prevent java 8's strict doclint for javadocs from failing builds - options.addStringOption('Xdoclint:none', '-quiet') } -test.configure { - useJUnitPlatform() -} - -void addLicense(jarTask) { - jarTask.from('LICENSE.md') { - rename '(.*)\\.(.*)', '$1_' + archivesBaseName + '.$2' - } -} - -void addManifest(jarTask) { - jarTask.manifest { - attributes([ - 'Specification-Title' : 'flywheel', - // 'Specification-Vendor': 'flywheel authors', - 'Specification-Version' : '1', // We are version 1 of ourselves - 'Implementation-Title' : project.jar.archiveBaseName, - 'Implementation-Version' : project.jar.archiveVersion, - // 'Implementation-Vendor': 'flywheel authors', - 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), - ]) - } -} - -apply from: rootProject.file('gradle/package-infos.gradle') - publishing { publications { register('mavenJava', MavenPublication) { diff --git a/forge/src/main/java/com/jozufozu/flywheel/FlywheelForge.java b/forge/src/main/java/com/jozufozu/flywheel/FlywheelForge.java new file mode 100644 index 000000000..166e30659 --- /dev/null +++ b/forge/src/main/java/com/jozufozu/flywheel/FlywheelForge.java @@ -0,0 +1,154 @@ +package com.jozufozu.flywheel; + +import java.util.ArrayList; + +import org.apache.maven.artifact.versioning.ArtifactVersion; + +import com.jozufozu.flywheel.api.event.EndClientResourceReloadEvent; +import com.jozufozu.flywheel.api.visualization.VisualizationManager; +import com.jozufozu.flywheel.backend.compile.FlwPrograms; +import com.jozufozu.flywheel.backend.engine.uniform.Uniforms; +import com.jozufozu.flywheel.config.BackendArgument; +import com.jozufozu.flywheel.config.FlwCommands; +import com.jozufozu.flywheel.config.FlwConfig; +import com.jozufozu.flywheel.impl.BackendManagerImpl; +import com.jozufozu.flywheel.impl.visualization.VisualizationEventHandler; +import com.jozufozu.flywheel.lib.memory.FlwMemoryTracker; +import com.jozufozu.flywheel.lib.model.ModelCache; +import com.jozufozu.flywheel.lib.model.ModelHolder; +import com.jozufozu.flywheel.lib.model.baked.PartialModel; +import com.jozufozu.flywheel.lib.util.LevelAttached; +import com.jozufozu.flywheel.lib.util.StringUtil; + +import net.minecraft.client.Minecraft; +import net.minecraft.commands.synchronization.ArgumentTypeInfos; +import net.minecraft.core.Vec3i; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.event.CustomizeGuiOverlayEvent; +import net.minecraftforge.client.event.RegisterClientReloadListenersEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.level.LevelEvent; +import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.fml.DistExecutor; +import net.minecraftforge.fml.IExtensionPoint; +import net.minecraftforge.fml.ModLoadingContext; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; +import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; +import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.registries.ForgeRegistries; +import net.minecraftforge.registries.RegisterEvent; + +@Mod(Flywheel.ID) +public class FlywheelForge { + private static ArtifactVersion version; + + public FlywheelForge() { + ModLoadingContext modLoadingContext = ModLoadingContext.get(); + + version = modLoadingContext + .getActiveContainer() + .getModInfo() + .getVersion(); + + IEventBus forgeEventBus = MinecraftForge.EVENT_BUS; + IEventBus modEventBus = FMLJavaModLoadingContext.get() + .getModEventBus(); + modEventBus.addListener(FlywheelForge::onCommonSetup); + modEventBus.addListener(FlywheelForge::onRegister); + + FlwConfig.get().registerSpecs(modLoadingContext); + + modLoadingContext.registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest( + () -> "any", + (serverVersion, isNetwork) -> true + )); + + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> FlywheelForge.clientInit(forgeEventBus, modEventBus)); + } + + private static void clientInit(IEventBus forgeEventBus, IEventBus modEventBus) { + forgeEventBus.addListener(FlywheelForge::addDebugInfo); + + forgeEventBus.addListener(BackendManagerImpl::onReloadLevelRenderer); + + forgeEventBus.addListener(VisualizationEventHandler::onClientTick); + forgeEventBus.addListener(VisualizationEventHandler::onBeginFrame); + forgeEventBus.addListener(VisualizationEventHandler::onRenderStage); + forgeEventBus.addListener(VisualizationEventHandler::onEntityJoinLevel); + forgeEventBus.addListener(VisualizationEventHandler::onEntityLeaveLevel); + + forgeEventBus.addListener(FlwCommands::registerClientCommands); + + forgeEventBus.addListener(Uniforms::onReloadLevelRenderer); + + forgeEventBus.addListener((LevelEvent.Unload e) -> LevelAttached.onUnloadLevel(e)); + +// forgeEventBus.addListener(ExampleEffect::tick); +// forgeEventBus.addListener(ExampleEffect::onReload); + + modEventBus.addListener(FlywheelForge::registerClientReloadListeners); + modEventBus.addListener(FlywheelForge::onClientSetup); + modEventBus.addListener(FlywheelForge::onLoadComplete); + + modEventBus.addListener(BackendManagerImpl::onEndClientResourceReload); + + modEventBus.addListener((EndClientResourceReloadEvent e) -> ModelCache.onEndClientResourceReload(e)); + modEventBus.addListener(ModelHolder::onEndClientResourceReload); + + modEventBus.addListener(PartialModel::onModelRegistry); + modEventBus.addListener(PartialModel::onModelBake); + + Flywheel.earlyInit(); + } + + private static void registerClientReloadListeners(RegisterClientReloadListenersEvent event) { + event.registerReloadListener(FlwPrograms.ResourceReloadListener.INSTANCE); + } + + private static void onClientSetup(FMLClientSetupEvent event) { + Flywheel.init(); + } + + private static void onLoadComplete(FMLLoadCompleteEvent event) { + Flywheel.freeze(); + } + + private static void onCommonSetup(FMLCommonSetupEvent event) { + ArgumentTypeInfos.registerByClass(BackendArgument.class, BackendArgument.INFO); + } + + private static void onRegister(RegisterEvent event) { + event.register(ForgeRegistries.Keys.COMMAND_ARGUMENT_TYPES, Flywheel.rl("backend"), () -> BackendArgument.INFO); + } + + private static void addDebugInfo(CustomizeGuiOverlayEvent.DebugText event) { + Minecraft mc = Minecraft.getInstance(); + + if (!mc.options.renderDebug) { + return; + } + + ArrayList info = event.getRight(); + info.add(""); + info.add("Flywheel: " + getVersion()); + info.add("Backend: " + BackendManagerImpl.getBackendString()); + info.add("Update limiting: " + (FlwConfig.get().limitUpdates() ? "on" : "off")); + + VisualizationManager manager = VisualizationManager.get(mc.level); + if (manager != null) { + info.add("B: " + manager.getBlockEntities().getVisualCount() + + ", E: " + manager.getEntities().getVisualCount() + + ", F: " + manager.getEffects().getVisualCount()); + Vec3i renderOrigin = manager.getRenderOrigin(); + info.add("Origin: " + renderOrigin.getX() + ", " + renderOrigin.getY() + ", " + renderOrigin.getZ()); + } + + info.add("Memory Usage: CPU: " + StringUtil.formatBytes(FlwMemoryTracker.getCPUMemory()) + ", GPU: " + StringUtil.formatBytes(FlwMemoryTracker.getGPUMemory())); + } + + public static ArtifactVersion getVersion() { + return version; + } +} diff --git a/common/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml similarity index 100% rename from common/src/main/resources/META-INF/mods.toml rename to forge/src/main/resources/META-INF/mods.toml