Deduplication and stubs

- Move common gradle business from each subproject into the
  rootProject.subprojects closure
- Add fabric.mod.json
- Register forge mixin configs
- Make blaze3d mixins remap = false
- Separate common, forge, and fabric mod entrypoints
This commit is contained in:
Jozufozu 2024-04-18 17:12:13 -07:00
parent c027023709
commit 5e7e867bcd
11 changed files with 327 additions and 465 deletions

View file

@ -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'}" 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 { subprojects {
boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equalsIgnoreCase('false');
ext.buildNumber = System.getenv('BUILD_NUMBER')
group = 'com.jozufozu.flywheel' group = 'com.jozufozu.flywheel'
version = mod_version + (dev && buildNumber != null ? "-${buildNumber}" : '') 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 { tasks {
// make builds reproducible // make builds reproducible
withType(AbstractArchiveTask).configureEach { withType(AbstractArchiveTask).configureEach {
@ -27,6 +37,110 @@ subprojects {
enabled = false 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 { idea {

View file

@ -1,126 +1,17 @@
plugins {
id 'maven-publish'
id 'dev.architectury.loom'
}
base { base {
archivesName = "flywheel-${project.name}-${artifact_minecraft_version}" 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 { 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" modCompileOnly "net.fabricmc:fabric-loader:$fabric_loader_version"
compileOnly "com.google.code.findbugs:jsr305:3.0.2" 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 { test.configure {
useJUnitPlatform() 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 { publishing {
publications { publications {
register('mavenJava', MavenPublication) { register('mavenJava', MavenPublication) {

View file

@ -1,120 +1,30 @@
package com.jozufozu.flywheel; package com.jozufozu.flywheel;
import java.util.ArrayList;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.Backends;
import com.jozufozu.flywheel.backend.ShaderIndices; 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.BackendManagerImpl;
import com.jozufozu.flywheel.impl.registry.IdRegistryImpl; import com.jozufozu.flywheel.impl.registry.IdRegistryImpl;
import com.jozufozu.flywheel.impl.registry.RegistryImpl; 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.instance.InstanceTypes;
import com.jozufozu.flywheel.lib.material.CutoutShaders; import com.jozufozu.flywheel.lib.material.CutoutShaders;
import com.jozufozu.flywheel.lib.material.FogShaders; import com.jozufozu.flywheel.lib.material.FogShaders;
import com.jozufozu.flywheel.lib.material.StandardMaterialShaders; 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.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.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 class Flywheel {
public static final String ID = "flywheel"; public static final String ID = "flywheel";
public static final Logger LOGGER = LoggerFactory.getLogger(ID); public static final Logger LOGGER = LoggerFactory.getLogger(ID);
private static ArtifactVersion version;
public Flywheel() { public static ResourceLocation rl(String path) {
ModLoadingContext modLoadingContext = ModLoadingContext.get(); return new ResourceLocation(ID, path);
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));
} }
private static void clientInit(IEventBus forgeEventBus, IEventBus modEventBus) { public static void earlyInit() {
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);
BackendManagerImpl.init(); BackendManagerImpl.init();
ShadersModHandler.init(); ShadersModHandler.init();
@ -122,64 +32,17 @@ public class Flywheel {
Backends.init(); Backends.init();
} }
private static void registerClientReloadListeners(RegisterClientReloadListenersEvent event) { public static void init() {
event.registerReloadListener(FlwPrograms.ResourceReloadListener.INSTANCE);
}
private static void onClientSetup(FMLClientSetupEvent event) {
InstanceTypes.init(); InstanceTypes.init();
CutoutShaders.init(); CutoutShaders.init();
FogShaders.init(); FogShaders.init();
StandardMaterialShaders.init(); StandardMaterialShaders.init();
ShaderIndices.init(); ShaderIndices.init();
VanillaVisuals.init();
} }
private static void onLoadComplete(FMLLoadCompleteEvent event) { public static void freeze() {
RegistryImpl.freezeAll(); RegistryImpl.freezeAll();
IdRegistryImpl.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<String> 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);
}
} }

View file

@ -9,7 +9,7 @@ import com.jozufozu.flywheel.backend.gl.GlStateTracker;
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType; import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
@Mixin(GlStateManager.class) @Mixin(value = GlStateManager.class, remap = false)
abstract class GlStateManagerMixin { abstract class GlStateManagerMixin {
@Inject(method = "_glBindBuffer(II)V", at = @At("RETURN")) @Inject(method = "_glBindBuffer(II)V", at = @At("RETURN"))
private static void flywheel$onBindBuffer(int target, int buffer, CallbackInfo ci) { private static void flywheel$onBindBuffer(int target, int buffer, CallbackInfo ci) {

View file

@ -9,7 +9,7 @@ import com.jozufozu.flywheel.backend.engine.uniform.FogUniforms;
import com.jozufozu.flywheel.backend.gl.GlCompat; import com.jozufozu.flywheel.backend.gl.GlCompat;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
@Mixin(RenderSystem.class) @Mixin(value = RenderSystem.class, remap = false)
abstract class RenderSystemMixin { abstract class RenderSystemMixin {
@Inject(method = "initRenderer(IZ)V", at = @At("RETURN")) @Inject(method = "initRenderer(IZ)V", at = @At("RETURN"))
private static void flywheel$onInitRenderer(CallbackInfo ci) { private static void flywheel$onInitRenderer(CallbackInfo ci) {

View file

@ -1,8 +1,3 @@
plugins {
id 'maven-publish'
id 'dev.architectury.loom'
}
evaluationDependsOn(':common') evaluationDependsOn(':common')
base { 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 { 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" modCompileOnly "net.fabricmc:fabric-loader:$fabric_loader_version"
modLocalRuntime "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" 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 { tasks.withType(JavaCompile).configureEach {
source(project(':common').sourceSets.main.allSource) 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 { sourcesJar.configure {
from(project(':common').sourceSets.main.allSource) from(project(':common').sourceSets.main.allSource)
addManifest(it)
addLicense(it)
} }
javadoc.configure { javadoc.configure {
source(project(':common').sourceSets.main.allJava) 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 { publishing {
publications { publications {
register('mavenJava', MavenPublication) { register('mavenJava', MavenPublication) {

View file

@ -0,0 +1,10 @@
package com.jozufozu.flywheel;
import net.fabricmc.api.ClientModInitializer;
public class FlywheelFabric implements ClientModInitializer {
@Override
public void onInitializeClient() {
}
}

View file

@ -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"
}
}

View file

@ -1,8 +1,3 @@
plugins {
id 'maven-publish'
id 'dev.architectury.loom'
}
evaluationDependsOn(':common') evaluationDependsOn(':common')
base { base {
@ -10,6 +5,12 @@ base {
} }
loom { loom {
forge {
mixinConfig "flywheel.backend.mixins.json"
mixinConfig "flywheel.impl.mixins.json"
mixinConfig "flywheel.impl.sodium.mixins.json"
}
runs { runs {
configureEach { configureEach {
property 'forge.logging.markers', '' 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 { 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}" forge "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
compileOnly project(path: ':common', configuration: 'namedElements') compileOnly project(path: ':common', configuration: 'namedElements')
@ -72,86 +42,18 @@ dependencies {
compileOnly "com.google.code.findbugs:jsr305:3.0.2" 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 { tasks.withType(JavaCompile).configureEach {
source(project(':common').sourceSets.main.allSource) 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 { sourcesJar.configure {
from(project(':common').sourceSets.main.allSource) from(project(':common').sourceSets.main.allSource)
addManifest(it)
addLicense(it)
} }
javadoc.configure { javadoc.configure {
source(project(':common').sourceSets.main.allJava) 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 { publishing {
publications { publications {
register('mavenJava', MavenPublication) { register('mavenJava', MavenPublication) {

View file

@ -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<String> 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;
}
}