diff --git a/.editorconfig b/.editorconfig index 6319172a3..038bc765e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,14 +4,12 @@ root = true [*] indent_style = space indent_size = 4 -ij_continuation_indent_size = 8 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.json] -indent_style = space indent_size = 2 max_line_length = 500 ij_json_keep_blank_lines_in_code = 0 @@ -27,12 +25,12 @@ ij_json_wrap_long_lines = false [*.java] indent_style = tab +ij_continuation_indent_size = 8 ij_java_blank_lines_before_class_end = 0 ij_java_blank_lines_after_anonymous_class_header = 0 ij_java_blank_lines_after_class_header = 0 ij_java_blank_lines_before_method_body = 0 ij_java_else_on_new_line = false -ij_continuation_indent_size = 8 ij_java_class_count_to_use_import_on_demand = 99 ij_java_names_count_to_use_import_on_demand = 99 ij_java_imports_layout = $*, |, java.**, |, javax.**, |, org.**, |, com.**, |, * diff --git a/build.gradle b/build.gradle index 4b5257b3b..2a823f262 100644 --- a/build.gradle +++ b/build.gradle @@ -1,98 +1,26 @@ plugins { - id 'eclipse' id 'idea' // make sure gradle loads the same arch plugin across all subprojects id 'dev.architectury.loom' apply false } -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')}") -subprojects { - apply plugin: "dev.architectury.loom" +allprojects { + // Need to setup the java plugin for all projects so that our subprojects can find an output directory + apply plugin: 'java' + apply plugin: 'maven-publish' - base { - archivesName = "flywheel-${name}-${artifact_minecraft_version}" - } - - boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equalsIgnoreCase('false'); - - ext.buildNumber = System.getenv('BUILD_NUMBER') + boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equalsIgnoreCase('false') + String buildNumber = System.getenv('BUILD_NUMBER') group = 'com.jozufozu.flywheel' version = mod_version + (dev && buildNumber != null ? "-${buildNumber}" : '') - loom { - silentMojangMappingsLicense() + base { + archivesName = "flywheel-${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") - }) - - implementation "com.google.code.findbugs:jsr305:3.0.2" - } - - processResources { - 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, - mod_id : mod_id, - mod_name : mod_name, - mod_description : mod_description, - mod_license : mod_license, - mod_sources : mod_sources, - mod_issues : mod_issues, - mod_homepage : mod_homepage, - ] - inputs.properties replaceProperties - - filesMatching(['pack.mcmeta', 'fabric.mod.json', 'META-INF/mods.toml', 'META-INF/neoforge.mods.toml']) { - expand replaceProperties + [project: project] - } - } - - apply from: rootProject.file('gradle/package-infos.gradle') - - ideaSyncTask.finalizedBy(generatePackageInfos) -} - -// Need to setup the java plugin for all projects so that our subprojects can find an output directory -allprojects { - apply plugin: "java" - apply plugin: "maven-publish" - java { JavaVersion javaVersion = JavaVersion.toVersion(java_version) sourceCompatibility = javaVersion @@ -123,12 +51,10 @@ allprojects { tasks.named('jar', Jar).configure { Jar jar -> archiveClassifier = '' - addManifest(jar) addLicense(jar) } tasks.named('sourcesJar', Jar).configure { Jar jar -> - addManifest(jar) addLicense(jar) } @@ -139,8 +65,89 @@ allprojects { } } +subprojects { + apply plugin: 'dev.architectury.loom' + + loom { + silentMojangMappingsLicense() + } + + repositories { + mavenCentral() + maven { + name = 'ParchmentMC' + url = 'https://maven.parchmentmc.org' + } + maven { + name 'tterrag maven' + url 'https://maven.tterrag.com/' + } + maven { + url 'https://www.cursemaven.com' + content { + includeGroup "curse.maven" + } + } + maven { + name = "Modrinth" + url = "https://api.modrinth.com/maven" + content { + includeGroup "maven.modrinth" + } + } + } + + dependencies { + minecraft "com.mojang:minecraft:${minecraft_version}" + mappings(loom.layered() { + officialMojangMappings() + parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip") + }) + + api 'com.google.code.findbugs:jsr305:3.0.2' + } + + processResources { + var replaceProperties = [ + mod_id : mod_id, + mod_name : mod_name, + mod_description : mod_description, + mod_license : mod_license, + mod_sources : mod_sources, + mod_issues : mod_issues, + mod_homepage : mod_homepage, + mod_version : mod_version, + minecraft_semver_version_range: minecraft_semver_version_range, + minecraft_maven_version_range : minecraft_maven_version_range, + fabric_api_version_range : fabric_api_version_range, + forge_version_range : forge_version_range, + ] + inputs.properties replaceProperties + + filesMatching(['pack.mcmeta', 'fabric.mod.json', 'META-INF/mods.toml']) { + expand replaceProperties + } + } + + publishing { + repositories { + maven { + url "file://${rootProject.projectDir}/mcmodsrepo" + } + + if (project.hasProperty('mavendir')) { + maven { url rootProject.file(property('mavendir')) } + } + } + } + + apply from: rootProject.file('gradle/package-infos.gradle') + + ideaSyncTask.finalizedBy(generatePackageInfos) +} + // Common configuration for platform dependent subprojects. -for (final def subprojectName in [":fabric", ":forge"]) { +for (final String subprojectName in [':fabric', ':forge']) { project(subprojectName) { evaluationDependsOn(':common') @@ -148,6 +155,7 @@ for (final def subprojectName in [":fabric", ":forge"]) { runs { client { ideConfigGenerated true + // Turn on our own debug flags property 'flw.dumpShaderSource', 'true' property 'flw.debugMemorySafety', 'true' @@ -187,7 +195,7 @@ for (final def subprojectName in [":fabric", ":forge"]) { } tasks.named('sourcesJar', Jar).configure { Jar jar -> - def commonSources = project(":common").tasks.named('sourcesJar', Jar) + def commonSources = project(':common').tasks.named('sourcesJar', Jar) dependsOn commonSources jar.from zipTree(commonSources.flatMap { it.archiveFile }) @@ -202,20 +210,6 @@ static void addLicense(Jar jarTask) { } } -static void addManifest(Jar 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"), - ]) - } -} - // We have duplicate packages between the common and platform dependent subprojects. // In theory the package-info.java files should be identical, so just take the first one we find. static void excludeDuplicatePackageInfos(AbstractCopyTask copyTask) { diff --git a/common/build.gradle b/common/build.gradle index aacd3633c..9b27890cf 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,5 +1,5 @@ dependencies { - modCompileOnly "net.fabricmc:fabric-loader:$fabric_loader_version" + modCompileOnly "net.fabricmc:fabric-loader:${fabric_loader_version}" testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1' } @@ -11,7 +11,7 @@ test { publishing { publications { register('mavenJava', MavenPublication) { - from(components["java"]) + from(components['java']) artifactId = "flywheel-${project.name}-intermediary-${artifact_minecraft_version}" } register('mojmapJava', MavenPublication) { @@ -20,13 +20,4 @@ publishing { artifactId = "flywheel-${project.name}-mojmap-${artifact_minecraft_version}" } } - repositories { - maven { - url "file://${rootProject.projectDir}/mcmodsrepo" - } - - if (project.hasProperty('mavendir')) { - maven { url rootProject.file(property('mavendir')) } - } - } } diff --git a/common/src/main/java/com/jozufozu/flywheel/api/internal/DependencyInjection.java b/common/src/main/java/com/jozufozu/flywheel/api/internal/DependencyInjection.java new file mode 100644 index 000000000..72b1b0a21 --- /dev/null +++ b/common/src/main/java/com/jozufozu/flywheel/api/internal/DependencyInjection.java @@ -0,0 +1,76 @@ +package com.jozufozu.flywheel.api.internal; + +import java.lang.reflect.Constructor; + +// Adapted from https://github.com/CaffeineMC/sodium-fabric/blob/bf4fc9dab16e1cca07b2f23a1201c9bf237c8044/src/api/java/net/caffeinemc/mods/sodium/api/internal/DependencyInjection.java +public final class DependencyInjection { + private DependencyInjection() { + } + + public static T load(Class apiClass, String implClassName) { + Class implClass; + + try { + implClass = Class.forName(implClassName); + } catch (ReflectiveOperationException e) { + throw new RuntimeException("Could not find implementation", e); + } + + if (!apiClass.isAssignableFrom(implClass)) { + throw new RuntimeException("Class %s does not implement interface %s" + .formatted(implClass.getName(), apiClass.getName())); + } + + Constructor implConstructor; + + try { + implConstructor = implClass.getConstructor(); + } catch (ReflectiveOperationException e) { + throw new RuntimeException("Could not find default constructor", e); + } + + Object implInstance; + + try { + implInstance = implConstructor.newInstance(); + } catch (ReflectiveOperationException e) { + throw new RuntimeException("Could not instantiate implementation", e); + } + + return apiClass.cast(implInstance); + } + + private static InternalFlywheelApi load() { + Class apiClass = InternalFlywheelApi.class; + Class implClass; + + try { + implClass = Class.forName("com.jozufozu.flywheel.impl.InternalFlywheelImpl"); + } catch (ReflectiveOperationException e) { + throw new RuntimeException("Could not find implementation", e); + } + + if (!apiClass.isAssignableFrom(implClass)) { + throw new RuntimeException("Class %s does not implement interface %s" + .formatted(implClass.getName(), apiClass.getName())); + } + + Constructor implConstructor; + + try { + implConstructor = implClass.getConstructor(); + } catch (ReflectiveOperationException e) { + throw new RuntimeException("Could not find default constructor", e); + } + + Object implInstance; + + try { + implInstance = implConstructor.newInstance(); + } catch (ReflectiveOperationException e) { + throw new RuntimeException("Could not instantiate implementation", e); + } + + return apiClass.cast(implInstance); + } +} diff --git a/common/src/main/java/com/jozufozu/flywheel/api/internal/InternalFlywheelApi.java b/common/src/main/java/com/jozufozu/flywheel/api/internal/InternalFlywheelApi.java index cb88d5f63..46737afa2 100644 --- a/common/src/main/java/com/jozufozu/flywheel/api/internal/InternalFlywheelApi.java +++ b/common/src/main/java/com/jozufozu/flywheel/api/internal/InternalFlywheelApi.java @@ -1,7 +1,5 @@ package com.jozufozu.flywheel.api.internal; -import java.lang.reflect.Constructor; - import org.jetbrains.annotations.Nullable; import com.jozufozu.flywheel.api.backend.Backend; @@ -12,6 +10,8 @@ import com.jozufozu.flywheel.api.vertex.VertexViewProvider; import com.jozufozu.flywheel.api.visualization.BlockEntityVisualizer; import com.jozufozu.flywheel.api.visualization.EntityVisualizer; import com.jozufozu.flywheel.api.visualization.VisualizationManager; +import com.jozufozu.flywheel.lib.transform.PoseTransformStack; +import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexFormat; import net.minecraft.world.entity.Entity; @@ -21,42 +21,7 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; public interface InternalFlywheelApi { - InternalFlywheelApi INSTANCE = load(); - - // Adapted from https://github.com/CaffeineMC/sodium-fabric/blob/bf4fc9dab16e1cca07b2f23a1201c9bf237c8044/src/api/java/net/caffeinemc/mods/sodium/api/internal/DependencyInjection.java - private static InternalFlywheelApi load() { - Class apiClass = InternalFlywheelApi.class; - Class implClass; - - try { - implClass = Class.forName("com.jozufozu.flywheel.impl.InternalFlywheelImpl"); - } catch (ReflectiveOperationException e) { - throw new RuntimeException("Could not find implementation", e); - } - - if (!apiClass.isAssignableFrom(implClass)) { - throw new RuntimeException("Class %s does not implement interface %s" - .formatted(implClass.getName(), apiClass.getName())); - } - - Constructor implConstructor; - - try { - implConstructor = implClass.getConstructor(); - } catch (ReflectiveOperationException e) { - throw new RuntimeException("Could not find default constructor", e); - } - - Object implInstance; - - try { - implInstance = implConstructor.newInstance(); - } catch (ReflectiveOperationException e) { - throw new RuntimeException("Could not instantiate implementation", e); - } - - return apiClass.cast(implInstance); - } + InternalFlywheelApi INSTANCE = DependencyInjection.load(InternalFlywheelApi.class, "com.jozufozu.flywheel.impl.InternalFlywheelImpl"); Registry createRegistry(); @@ -92,4 +57,6 @@ public interface InternalFlywheelApi { void setVisualizer(BlockEntityType type, BlockEntityVisualizer visualizer); void setVisualizer(EntityType type, EntityVisualizer visualizer); + + PoseTransformStack getPoseTransformStackOf(PoseStack stack); } diff --git a/common/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/PlayerUniforms.java b/common/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/PlayerUniforms.java index 02e14a5da..ca5b4b6d6 100644 --- a/common/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/PlayerUniforms.java +++ b/common/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/PlayerUniforms.java @@ -92,9 +92,9 @@ public final class PlayerUniforms extends UniformWriter { for (InteractionHand hand : InteractionHand.values()) { Item handItem = player.getItemInHand(hand).getItem(); - if (handItem instanceof BlockItem bitem) { - Block block = bitem.getBlock(); - int blockLight = ClientPlatform.getInstance() + if (handItem instanceof BlockItem blockItem) { + Block block = blockItem.getBlock(); + int blockLight = ClientPlatform.INSTANCE .getLightEmission(block.defaultBlockState(), player.clientLevel, player.blockPosition()); if (heldLight < blockLight) { heldLight = blockLight; diff --git a/common/src/main/java/com/jozufozu/flywheel/config/FlwConfig.java b/common/src/main/java/com/jozufozu/flywheel/config/FlwConfig.java index 4ec3356aa..a6e751595 100644 --- a/common/src/main/java/com/jozufozu/flywheel/config/FlwConfig.java +++ b/common/src/main/java/com/jozufozu/flywheel/config/FlwConfig.java @@ -4,12 +4,12 @@ import com.jozufozu.flywheel.api.backend.Backend; import com.jozufozu.flywheel.platform.ClientPlatform; public interface FlwConfig { - FlwConfig INSTANCE = ClientPlatform.getInstance().getConfigInstance(); + FlwConfig INSTANCE = ClientPlatform.INSTANCE.getConfigInstance(); static FlwConfig get() { return INSTANCE; } - Backend getBackend(); + Backend backend(); boolean limitUpdates(); diff --git a/common/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java b/common/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java index 0f4d10f85..550d13003 100644 --- a/common/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java +++ b/common/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java @@ -1,5 +1,6 @@ package com.jozufozu.flywheel.impl; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import com.jozufozu.flywheel.Flywheel; @@ -44,8 +45,8 @@ public final class BackendManagerImpl { return Backends.INDIRECT; } - public static void chooseBackend() { - var preferred = FlwConfig.get().getBackend(); + private static void chooseBackend() { + var preferred = FlwConfig.get().backend(); var actual = preferred.findFallback(); if (preferred != actual) { @@ -65,4 +66,21 @@ public final class BackendManagerImpl { public static void init() { } + + public static void onEndClientResourceReload(boolean didError) { + if (didError) { + return; + } + + chooseBackend(); + VisualizationManagerImpl.resetAll(); + } + + public static void onReloadLevelRenderer(@Nullable ClientLevel level) { + chooseBackend(); + + if (level != null) { + VisualizationManagerImpl.reset(level); + } + } } diff --git a/common/src/main/java/com/jozufozu/flywheel/impl/InternalFlywheelImpl.java b/common/src/main/java/com/jozufozu/flywheel/impl/InternalFlywheelImpl.java index 4dd9829f0..c32738e52 100644 --- a/common/src/main/java/com/jozufozu/flywheel/impl/InternalFlywheelImpl.java +++ b/common/src/main/java/com/jozufozu/flywheel/impl/InternalFlywheelImpl.java @@ -111,4 +111,9 @@ public final class InternalFlywheelImpl implements InternalFlywheelApi { public void setVisualizer(EntityType type, EntityVisualizer visualizer) { VisualizerRegistryImpl.setVisualizer(type, visualizer); } + + @Override + public PoseTransformStack getPoseTransformStackOf(PoseStack stack) { + return ((PoseStackExtension) stack).flywheel$transformStack(); + } } diff --git a/common/src/main/java/com/jozufozu/flywheel/impl/mixin/LevelRendererMixin.java b/common/src/main/java/com/jozufozu/flywheel/impl/mixin/LevelRendererMixin.java index ff11b3bea..ea28763c3 100644 --- a/common/src/main/java/com/jozufozu/flywheel/impl/mixin/LevelRendererMixin.java +++ b/common/src/main/java/com/jozufozu/flywheel/impl/mixin/LevelRendererMixin.java @@ -51,7 +51,7 @@ abstract class LevelRendererMixin { private void flywheel$beginRender(PoseStack poseStack, float partialTick, long finishNanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci) { flywheel$renderContext = RenderContextImpl.create((LevelRenderer) (Object) this, level, renderBuffers, poseStack, projectionMatrix, camera, partialTick); - ClientPlatform.getInstance().dispatchBeginFrame(flywheel$renderContext); + ClientPlatform.INSTANCE.dispatchBeginFrame(flywheel$renderContext); } @Inject(method = "renderLevel", at = @At("RETURN")) @@ -61,7 +61,7 @@ abstract class LevelRendererMixin { @Inject(method = "allChanged", at = @At("RETURN")) private void flywheel$refresh(CallbackInfo ci) { - ClientPlatform.getInstance().dispatchReloadLevelRenderer(level); + ClientPlatform.INSTANCE.dispatchReloadLevelRenderer(level); } @Inject(method = "renderLevel", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V", args = "ldc=destroyProgress")) @@ -81,7 +81,7 @@ abstract class LevelRendererMixin { @Unique private void flywheel$dispatch(RenderStage stage) { if (flywheel$renderContext != null) { - ClientPlatform.getInstance().dispatchRenderStage(flywheel$renderContext, stage); + ClientPlatform.INSTANCE.dispatchRenderStage(flywheel$renderContext, stage); } } diff --git a/common/src/main/java/com/jozufozu/flywheel/lib/internal/FlywheelLibPlatform.java b/common/src/main/java/com/jozufozu/flywheel/lib/internal/FlywheelLibPlatform.java deleted file mode 100644 index 9413c94b9..000000000 --- a/common/src/main/java/com/jozufozu/flywheel/lib/internal/FlywheelLibPlatform.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.jozufozu.flywheel.lib.internal; - -import java.lang.reflect.Constructor; - -import com.jozufozu.flywheel.lib.model.baked.BakedModelBuilder; -import com.jozufozu.flywheel.lib.model.baked.BlockModelBuilder; -import com.jozufozu.flywheel.lib.model.baked.MultiBlockModelBuilder; -import com.jozufozu.flywheel.lib.transform.PoseTransformStack; -import com.mojang.blaze3d.vertex.PoseStack; - -import net.minecraft.client.renderer.block.BlockRenderDispatcher; -import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.block.state.BlockState; - -public interface FlywheelLibPlatform { - FlywheelLibPlatform INSTANCE = load(); - - // Adapted from https://github.com/CaffeineMC/sodium-fabric/blob/bf4fc9dab16e1cca07b2f23a1201c9bf237c8044/src/api/java/net/caffeinemc/mods/sodium/api/internal/DependencyInjection.java - private static FlywheelLibPlatform load() { - Class apiClass = FlywheelLibPlatform.class; - Class implClass; - - try { - implClass = Class.forName("com.jozufozu.flywheel.impl.FlywheelLibPlatformImpl"); - } catch (ReflectiveOperationException e) { - throw new RuntimeException("Could not find implementation", e); - } - - if (!apiClass.isAssignableFrom(implClass)) { - throw new RuntimeException("Class %s does not implement interface %s" - .formatted(implClass.getName(), apiClass.getName())); - } - - Constructor implConstructor; - - try { - implConstructor = implClass.getConstructor(); - } catch (ReflectiveOperationException e) { - throw new RuntimeException("Could not find default constructor", e); - } - - Object implInstance; - - try { - implInstance = implConstructor.newInstance(); - } catch (ReflectiveOperationException e) { - throw new RuntimeException("Could not instantiate implementation", e); - } - - return apiClass.cast(implInstance); - } - - PoseTransformStack getPoseTransformStackOf(PoseStack stack); - - BlockRenderDispatcher createVanillaRenderer(); - - BakedModelBuilder bakedModelBuilder(BakedModel bakedModel); - - BlockModelBuilder blockModelBuilder(BlockState state); - - MultiBlockModelBuilder multiBlockModelBuilder(BlockAndTintGetter level, Iterable positions); -} diff --git a/common/src/main/java/com/jozufozu/flywheel/lib/internal/package-info.java b/common/src/main/java/com/jozufozu/flywheel/lib/internal/package-info.java deleted file mode 100644 index b4efe3fa3..000000000 --- a/common/src/main/java/com/jozufozu/flywheel/lib/internal/package-info.java +++ /dev/null @@ -1,12 +0,0 @@ -@ApiStatus.Internal -@ParametersAreNonnullByDefault -@FieldsAreNonnullByDefault -@MethodsReturnNonnullByDefault -package com.jozufozu.flywheel.lib.internal; - -import javax.annotation.ParametersAreNonnullByDefault; - -import org.jetbrains.annotations.ApiStatus; - -import net.minecraft.FieldsAreNonnullByDefault; -import net.minecraft.MethodsReturnNonnullByDefault; diff --git a/common/src/main/java/com/jozufozu/flywheel/lib/model/ModelUtil.java b/common/src/main/java/com/jozufozu/flywheel/lib/model/ModelUtil.java index 8a5797343..0eea8d801 100644 --- a/common/src/main/java/com/jozufozu/flywheel/lib/model/ModelUtil.java +++ b/common/src/main/java/com/jozufozu/flywheel/lib/model/ModelUtil.java @@ -8,7 +8,6 @@ import org.joml.Vector3f; import org.joml.Vector4f; import org.lwjgl.system.MemoryUtil; -import com.jozufozu.flywheel.lib.internal.FlywheelLibPlatform; import com.jozufozu.flywheel.api.material.Material; import com.jozufozu.flywheel.api.model.Mesh; import com.jozufozu.flywheel.api.model.Model; @@ -18,6 +17,7 @@ import com.jozufozu.flywheel.api.vertex.VertexViewProviderRegistry; import com.jozufozu.flywheel.lib.material.Materials; import com.jozufozu.flywheel.lib.memory.MemoryBlock; import com.jozufozu.flywheel.lib.vertex.PosVertexView; +import com.jozufozu.flywheel.platform.ClientPlatform; import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.BufferBuilder.DrawState; import com.mojang.blaze3d.vertex.VertexFormat; @@ -30,7 +30,7 @@ public final class ModelUtil { * An alternative BlockRenderDispatcher that circumvents the Forge rendering pipeline to ensure consistency. * Meant to be used for virtual rendering. */ - public static final BlockRenderDispatcher VANILLA_RENDERER = FlywheelLibPlatform.INSTANCE.createVanillaRenderer(); + public static final BlockRenderDispatcher VANILLA_RENDERER = ClientPlatform.INSTANCE.createVanillaRenderer(); private static final float BOUNDING_SPHERE_EPSILON = 1e-4f; private ModelUtil() { diff --git a/common/src/main/java/com/jozufozu/flywheel/lib/model/baked/BakedModelBuilder.java b/common/src/main/java/com/jozufozu/flywheel/lib/model/baked/BakedModelBuilder.java index 238aedd9e..0eeb0c22b 100644 --- a/common/src/main/java/com/jozufozu/flywheel/lib/model/baked/BakedModelBuilder.java +++ b/common/src/main/java/com/jozufozu/flywheel/lib/model/baked/BakedModelBuilder.java @@ -4,23 +4,14 @@ import java.util.function.BiFunction; import org.jetbrains.annotations.Nullable; -import com.google.common.collect.ImmutableList; import com.jozufozu.flywheel.api.material.Material; -import com.jozufozu.flywheel.api.model.Model; -import com.jozufozu.flywheel.api.vertex.VertexView; -import com.jozufozu.flywheel.lib.internal.FlywheelLibPlatform; -import com.jozufozu.flywheel.lib.memory.MemoryBlock; -import com.jozufozu.flywheel.lib.model.ModelUtil; -import com.jozufozu.flywheel.lib.model.SimpleMesh; import com.jozufozu.flywheel.lib.model.SimpleModel; -import com.jozufozu.flywheel.lib.model.baked.MeshEmitter.ResultConsumer; -import com.jozufozu.flywheel.lib.vertex.NoOverlayVertexView; +import com.jozufozu.flywheel.platform.ClientPlatform; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; public abstract class BakedModelBuilder { @@ -35,7 +26,7 @@ public abstract class BakedModelBuilder { protected BiFunction materialFunc; public static BakedModelBuilder create(BakedModel bakedModel) { - return FlywheelLibPlatform.INSTANCE.bakedModelBuilder(bakedModel); + return ClientPlatform.INSTANCE.bakedModelBuilder(bakedModel); } protected BakedModelBuilder(BakedModel bakedModel) { diff --git a/common/src/main/java/com/jozufozu/flywheel/lib/model/baked/BlockModelBuilder.java b/common/src/main/java/com/jozufozu/flywheel/lib/model/baked/BlockModelBuilder.java index 7058735d8..aeb1497b6 100644 --- a/common/src/main/java/com/jozufozu/flywheel/lib/model/baked/BlockModelBuilder.java +++ b/common/src/main/java/com/jozufozu/flywheel/lib/model/baked/BlockModelBuilder.java @@ -4,17 +4,9 @@ import java.util.function.BiFunction; import org.jetbrains.annotations.Nullable; -import com.google.common.collect.ImmutableList; import com.jozufozu.flywheel.api.material.Material; -import com.jozufozu.flywheel.api.model.Model; -import com.jozufozu.flywheel.api.vertex.VertexView; -import com.jozufozu.flywheel.lib.internal.FlywheelLibPlatform; -import com.jozufozu.flywheel.lib.memory.MemoryBlock; -import com.jozufozu.flywheel.lib.model.ModelUtil; -import com.jozufozu.flywheel.lib.model.SimpleMesh; import com.jozufozu.flywheel.lib.model.SimpleModel; -import com.jozufozu.flywheel.lib.model.baked.MeshEmitter.ResultConsumer; -import com.jozufozu.flywheel.lib.vertex.NoOverlayVertexView; +import com.jozufozu.flywheel.platform.ClientPlatform; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.renderer.RenderType; @@ -31,7 +23,7 @@ public abstract class BlockModelBuilder { protected BiFunction materialFunc; public static BlockModelBuilder create(BlockState state) { - return FlywheelLibPlatform.INSTANCE.blockModelBuilder(state); + return ClientPlatform.INSTANCE.blockModelBuilder(state); } protected BlockModelBuilder(BlockState state) { diff --git a/common/src/main/java/com/jozufozu/flywheel/lib/model/baked/MultiBlockModelBuilder.java b/common/src/main/java/com/jozufozu/flywheel/lib/model/baked/MultiBlockModelBuilder.java index 61d46ae95..2ad7a7b33 100644 --- a/common/src/main/java/com/jozufozu/flywheel/lib/model/baked/MultiBlockModelBuilder.java +++ b/common/src/main/java/com/jozufozu/flywheel/lib/model/baked/MultiBlockModelBuilder.java @@ -5,8 +5,8 @@ import java.util.function.BiFunction; import org.jetbrains.annotations.Nullable; import com.jozufozu.flywheel.api.material.Material; -import com.jozufozu.flywheel.lib.internal.FlywheelLibPlatform; import com.jozufozu.flywheel.lib.model.SimpleModel; +import com.jozufozu.flywheel.platform.ClientPlatform; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.renderer.RenderType; @@ -23,7 +23,7 @@ public abstract class MultiBlockModelBuilder { protected BiFunction materialFunc; public static MultiBlockModelBuilder create(BlockAndTintGetter level, Iterable positions) { - return FlywheelLibPlatform.INSTANCE.multiBlockModelBuilder(level, positions); + return ClientPlatform.INSTANCE.multiBlockModelBuilder(level, positions); } protected MultiBlockModelBuilder(BlockAndTintGetter level, Iterable positions) { diff --git a/common/src/main/java/com/jozufozu/flywheel/lib/transform/TransformStack.java b/common/src/main/java/com/jozufozu/flywheel/lib/transform/TransformStack.java index 2d2db3a3c..306972421 100644 --- a/common/src/main/java/com/jozufozu/flywheel/lib/transform/TransformStack.java +++ b/common/src/main/java/com/jozufozu/flywheel/lib/transform/TransformStack.java @@ -1,11 +1,11 @@ package com.jozufozu.flywheel.lib.transform; -import com.jozufozu.flywheel.lib.internal.FlywheelLibPlatform; +import com.jozufozu.flywheel.api.internal.InternalFlywheelApi; import com.mojang.blaze3d.vertex.PoseStack; public interface TransformStack> extends Transform { static PoseTransformStack of(PoseStack stack) { - return FlywheelLibPlatform.INSTANCE.getPoseTransformStackOf(stack); + return InternalFlywheelApi.INSTANCE.getPoseTransformStackOf(stack); } Self pushPose(); diff --git a/common/src/main/java/com/jozufozu/flywheel/lib/util/LevelAttached.java b/common/src/main/java/com/jozufozu/flywheel/lib/util/LevelAttached.java index b3175f781..e8817d6e1 100644 --- a/common/src/main/java/com/jozufozu/flywheel/lib/util/LevelAttached.java +++ b/common/src/main/java/com/jozufozu/flywheel/lib/util/LevelAttached.java @@ -7,8 +7,6 @@ import java.util.concurrent.ConcurrentLinkedDeque; import java.util.function.Consumer; import java.util.function.Function; -import org.jetbrains.annotations.ApiStatus; - import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; diff --git a/common/src/main/java/com/jozufozu/flywheel/lib/util/ShadersModHandler.java b/common/src/main/java/com/jozufozu/flywheel/lib/util/ShadersModHandler.java index 49ca164fe..8e1de6f37 100644 --- a/common/src/main/java/com/jozufozu/flywheel/lib/util/ShadersModHandler.java +++ b/common/src/main/java/com/jozufozu/flywheel/lib/util/ShadersModHandler.java @@ -22,7 +22,7 @@ public final class ShadersModHandler { Package optifinePackage = Package.getPackage(OPTIFINE_ROOT_PACKAGE); IS_OPTIFINE_INSTALLED = optifinePackage != null; - var irisOculusHandler = ClientPlatform.getInstance() + var irisOculusHandler = ClientPlatform.INSTANCE .createIrisOculusHandlerIfPresent(); IS_IRIS_LOADED = irisOculusHandler != null; diff --git a/common/src/main/java/com/jozufozu/flywheel/platform/ClientPlatform.java b/common/src/main/java/com/jozufozu/flywheel/platform/ClientPlatform.java index 1fc1e41cf..ac61c5e52 100644 --- a/common/src/main/java/com/jozufozu/flywheel/platform/ClientPlatform.java +++ b/common/src/main/java/com/jozufozu/flywheel/platform/ClientPlatform.java @@ -1,48 +1,47 @@ package com.jozufozu.flywheel.platform; -import java.lang.reflect.InvocationTargetException; - import org.jetbrains.annotations.Nullable; import com.jozufozu.flywheel.api.event.RenderContext; import com.jozufozu.flywheel.api.event.RenderStage; +import com.jozufozu.flywheel.api.internal.DependencyInjection; import com.jozufozu.flywheel.config.FlwConfig; +import com.jozufozu.flywheel.lib.model.baked.BakedModelBuilder; +import com.jozufozu.flywheel.lib.model.baked.BlockModelBuilder; +import com.jozufozu.flywheel.lib.model.baked.MultiBlockModelBuilder; import com.jozufozu.flywheel.lib.util.ShadersModHandler; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.renderer.block.BlockRenderDispatcher; +import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.state.BlockState; -public abstract class ClientPlatform { - private static final ClientPlatform INSTANCE; +public interface ClientPlatform { + ClientPlatform INSTANCE = DependencyInjection.load(ClientPlatform.class, "com.jozufozu.flywheel.platform.ClientPlatformImpl"); - static { - try { - INSTANCE = - (ClientPlatform) Class.forName("com.jozufozu.flywheel.platform.ClientPlatformImpl").getConstructor() - .newInstance(); - } catch (ClassNotFoundException | InvocationTargetException | InstantiationException | IllegalAccessException | - NoSuchMethodException e) { - throw new RuntimeException(e); - } - } + void dispatchReloadLevelRenderer(ClientLevel level); - public static ClientPlatform getInstance() { - return INSTANCE; - } + void dispatchBeginFrame(RenderContext context); - public abstract void dispatchReloadLevelRenderer(ClientLevel level); + void dispatchRenderStage(RenderContext context, RenderStage stage); - public abstract void dispatchBeginFrame(RenderContext context); - - public abstract void dispatchRenderStage(RenderContext context, RenderStage stage); - - public abstract boolean isModLoaded(String modid); + boolean isModLoaded(String modid); @Nullable - public abstract ShadersModHandler.InternalHandler createIrisOculusHandlerIfPresent(); + ShadersModHandler.InternalHandler createIrisOculusHandlerIfPresent(); - public abstract int getLightEmission(BlockState state, ClientLevel level, BlockPos pos); + int getLightEmission(BlockState state, BlockGetter level, BlockPos pos); - public abstract FlwConfig getConfigInstance(); + FlwConfig getConfigInstance(); + + BlockRenderDispatcher createVanillaRenderer(); + + BakedModelBuilder bakedModelBuilder(BakedModel bakedModel); + + BlockModelBuilder blockModelBuilder(BlockState state); + + MultiBlockModelBuilder multiBlockModelBuilder(BlockAndTintGetter level, Iterable positions); } diff --git a/fabric/build.gradle b/fabric/build.gradle index 86f8ea549..ec6a423a2 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -1,33 +1,18 @@ dependencies { - modCompileOnly "net.fabricmc:fabric-loader:$fabric_loader_version" - modLocalRuntime "net.fabricmc:fabric-loader:$fabric_loader_version" - - modCompileOnly "net.fabricmc.fabric-api:fabric-api:$fabric_api_version" - modLocalRuntime "net.fabricmc.fabric-api:fabric-api:$fabric_api_version" - compileOnly project(path: ':common', configuration: 'namedElements') - // switch to implementation for debugging - modCompileOnly "maven.modrinth:starlight:$starlight_version" + modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}" + modApi "net.fabricmc.fabric-api:fabric-api:${fabric_api_version}" - modCompileOnly "maven.modrinth:sodium:$sodium_version" - modCompileOnly "maven.modrinth:iris:$iris_version" + modCompileOnly "maven.modrinth:sodium:${sodium_version}" + modCompileOnly "maven.modrinth:iris:${iris_version}" } publishing { publications { register('mavenJava', MavenPublication) { - from(components["java"]) + from(components['java']) artifactId = "flywheel-${project.name}-intermediary-${artifact_minecraft_version}" } } - repositories { - maven { - url "file://${rootProject.projectDir}/mcmodsrepo" - } - - if (project.hasProperty('mavendir')) { - maven { url rootProject.file(property('mavendir')) } - } - } } diff --git a/fabric/gradle.properties b/fabric/gradle.properties new file mode 100644 index 000000000..6c5947614 --- /dev/null +++ b/fabric/gradle.properties @@ -0,0 +1 @@ +loom.platform = fabric diff --git a/fabric/src/main/java/com/jozufozu/flywheel/FlywheelFabric.java b/fabric/src/main/java/com/jozufozu/flywheel/impl/FlywheelFabric.java similarity index 81% rename from fabric/src/main/java/com/jozufozu/flywheel/FlywheelFabric.java rename to fabric/src/main/java/com/jozufozu/flywheel/impl/FlywheelFabric.java index b6353f97c..4e4c56eeb 100644 --- a/fabric/src/main/java/com/jozufozu/flywheel/FlywheelFabric.java +++ b/fabric/src/main/java/com/jozufozu/flywheel/impl/FlywheelFabric.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel; +package com.jozufozu.flywheel.impl; import net.fabricmc.api.ClientModInitializer; diff --git a/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java b/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java index b2021bdc1..0673915cb 100644 --- a/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java +++ b/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java @@ -4,12 +4,12 @@ import java.util.List; import java.util.Set; import java.util.function.Supplier; -import com.google.common.base.Suppliers; - import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; +import com.google.common.base.Suppliers; + import net.fabricmc.loader.api.FabricLoader; public class SodiumMixinPlugin implements IMixinConfigPlugin { diff --git a/fabric/src/main/java/com/jozufozu/flywheel/platform/ClientPlatformImpl.java b/fabric/src/main/java/com/jozufozu/flywheel/platform/ClientPlatformImpl.java index af277f9f9..372357310 100644 --- a/fabric/src/main/java/com/jozufozu/flywheel/platform/ClientPlatformImpl.java +++ b/fabric/src/main/java/com/jozufozu/flywheel/platform/ClientPlatformImpl.java @@ -8,15 +8,23 @@ import com.jozufozu.flywheel.api.event.RenderContext; import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.event.RenderStageCallback; import com.jozufozu.flywheel.config.FlwConfig; +import com.jozufozu.flywheel.lib.model.baked.BakedModelBuilder; +import com.jozufozu.flywheel.lib.model.baked.BlockModelBuilder; +import com.jozufozu.flywheel.lib.model.baked.MultiBlockModelBuilder; import com.jozufozu.flywheel.lib.util.ShadersModHandler; import net.fabricmc.loader.api.FabricLoader; import net.irisshaders.iris.api.v0.IrisApi; +import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.renderer.block.BlockRenderDispatcher; +import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.state.BlockState; -public class ClientPlatformImpl extends ClientPlatform { +public class ClientPlatformImpl implements ClientPlatform { @Override public void dispatchReloadLevelRenderer(ClientLevel level) { ReloadLevelRendererCallback.EVENT.invoker().onReloadLevelRenderer(level); @@ -61,7 +69,7 @@ public class ClientPlatformImpl extends ClientPlatform { } @Override - public int getLightEmission(BlockState state, ClientLevel level, BlockPos pos) { + public int getLightEmission(BlockState state, BlockGetter level, BlockPos pos) { return state.getLightEmission(); } @@ -70,4 +78,24 @@ public class ClientPlatformImpl extends ClientPlatform { // TODO: fabric config return null; } + + @Override + public BlockRenderDispatcher createVanillaRenderer() { + return Minecraft.getInstance().getBlockRenderer(); + } + + @Override + public BakedModelBuilder bakedModelBuilder(BakedModel bakedModel) { + return null; + } + + @Override + public BlockModelBuilder blockModelBuilder(BlockState state) { + return null; + } + + @Override + public MultiBlockModelBuilder multiBlockModelBuilder(BlockAndTintGetter level, Iterable positions) { + return null; + } } diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 9d1336191..35b681801 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -15,10 +15,10 @@ }, "license": "${mod_license}", "icon": "logo.png", - "environment": "*", + "environment": "client", "entrypoints": { "client": [ - "com.jozufozu.flywheel.FlywheelFabric" + "com.jozufozu.flywheel.impl.FlywheelFabric" ] }, "mixins": [ @@ -27,7 +27,10 @@ "flywheel.impl.sodium.mixins.json" ], "depends": { - "fabric": "*", - "minecraft": "${minecraft_version_range}" + "minecraft": "${minecraft_semver_version_range}", + "fabric-api": "${fabric_api_version_range}" + }, + "breaks": { + "sodium": "<0.5.0" } } diff --git a/forge/build.gradle b/forge/build.gradle index ca6f186e9..239e9ce34 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -1,9 +1,8 @@ -// Add some forge specific configurations loom { forge { - mixinConfig "flywheel.backend.mixins.json" - mixinConfig "flywheel.impl.mixins.json" - mixinConfig "flywheel.impl.sodium.mixins.json" + mixinConfig 'flywheel.backend.mixins.json' + mixinConfig 'flywheel.impl.mixins.json' + mixinConfig 'flywheel.impl.sodium.mixins.json' } runs { @@ -19,24 +18,15 @@ dependencies { compileOnly project(path: ':common', configuration: 'namedElements') - modCompileOnly "maven.modrinth:embeddium:$embeddium_version" - modCompileOnly "maven.modrinth:oculus:$oculus_version" + modCompileOnly "maven.modrinth:embeddium:${embeddium_version}" + modCompileOnly "maven.modrinth:oculus:${oculus_version}" } publishing { publications { register('mavenJava', MavenPublication) { - from(components["java"]) + from(components['java']) artifactId = "flywheel-${project.name}-intermediary-${artifact_minecraft_version}" } } - repositories { - maven { - url "file://${rootProject.projectDir}/mcmodsrepo" - } - - if (project.hasProperty('mavendir')) { - maven { url rootProject.file(property('mavendir')) } - } - } } diff --git a/forge/src/main/java/com/jozufozu/flywheel/config/FlwForgeConfig.java b/forge/src/main/java/com/jozufozu/flywheel/config/FlwForgeConfig.java index a83cf60fd..acce638f1 100644 --- a/forge/src/main/java/com/jozufozu/flywheel/config/FlwForgeConfig.java +++ b/forge/src/main/java/com/jozufozu/flywheel/config/FlwForgeConfig.java @@ -27,7 +27,7 @@ public class FlwForgeConfig implements FlwConfig { clientSpec = clientPair.getRight(); } - public Backend getBackend() { + public Backend backend() { Backend backend = parseBackend(client.backend.get()); if (backend == null) { backend = BackendManager.getDefaultBackend(); diff --git a/forge/src/main/java/com/jozufozu/flywheel/impl/BackendEventHandler.java b/forge/src/main/java/com/jozufozu/flywheel/impl/BackendEventHandler.java deleted file mode 100644 index a8254b49d..000000000 --- a/forge/src/main/java/com/jozufozu/flywheel/impl/BackendEventHandler.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.jozufozu.flywheel.impl; - -import com.jozufozu.flywheel.api.event.EndClientResourceReloadEvent; -import com.jozufozu.flywheel.api.event.ReloadLevelRendererEvent; -import com.jozufozu.flywheel.impl.visualization.VisualizationManagerImpl; - -import net.minecraft.client.multiplayer.ClientLevel; - -public class BackendEventHandler { - public static void onEndClientResourceReload(EndClientResourceReloadEvent event) { - if (event.error() - .isPresent()) { - return; - } - - BackendManagerImpl.chooseBackend(); - VisualizationManagerImpl.resetAll(); - } - - public static void onReloadLevelRenderer(ReloadLevelRendererEvent event) { - BackendManagerImpl.chooseBackend(); - - ClientLevel level = event.level(); - if (level != null) { - VisualizationManagerImpl.reset(level); - } - } -} diff --git a/forge/src/main/java/com/jozufozu/flywheel/FlywheelForge.java b/forge/src/main/java/com/jozufozu/flywheel/impl/FlywheelForge.java similarity index 85% rename from forge/src/main/java/com/jozufozu/flywheel/FlywheelForge.java rename to forge/src/main/java/com/jozufozu/flywheel/impl/FlywheelForge.java index 8905e734b..90c6cc49c 100644 --- a/forge/src/main/java/com/jozufozu/flywheel/FlywheelForge.java +++ b/forge/src/main/java/com/jozufozu/flywheel/impl/FlywheelForge.java @@ -1,9 +1,10 @@ -package com.jozufozu.flywheel; +package com.jozufozu.flywheel.impl; import java.util.ArrayList; import org.apache.maven.artifact.versioning.ArtifactVersion; +import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.event.EndClientResourceReloadEvent; import com.jozufozu.flywheel.api.event.ReloadLevelRendererEvent; import com.jozufozu.flywheel.api.visualization.VisualizationManager; @@ -13,8 +14,6 @@ import com.jozufozu.flywheel.config.BackendArgument; import com.jozufozu.flywheel.config.FlwCommands; import com.jozufozu.flywheel.config.FlwConfig; import com.jozufozu.flywheel.config.FlwForgeConfig; -import com.jozufozu.flywheel.impl.BackendEventHandler; -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; @@ -34,7 +33,6 @@ import net.minecraftforge.event.level.LevelEvent; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.CrashReportCallables; 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; @@ -64,18 +62,13 @@ public class FlywheelForge { FlwForgeConfig.INSTANCE.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(BackendEventHandler::onReloadLevelRenderer); + forgeEventBus.addListener((ReloadLevelRendererEvent e) -> BackendManagerImpl.onReloadLevelRenderer(e.level())); forgeEventBus.addListener(VisualizationEventHandler::onClientTick); forgeEventBus.addListener(VisualizationEventHandler::onBeginFrame); @@ -85,7 +78,7 @@ public class FlywheelForge { forgeEventBus.addListener(FlwCommands::registerClientCommands); - forgeEventBus.addListener($ -> Uniforms.onReloadLevelRenderer()); + forgeEventBus.addListener((EndClientResourceReloadEvent e) -> Uniforms.onReloadLevelRenderer()); forgeEventBus.addListener((LevelEvent.Unload e) -> LevelAttached.invalidateLevel(e.getLevel())); @@ -93,10 +86,10 @@ public class FlywheelForge { modEventBus.addListener(FlywheelForge::onClientSetup); modEventBus.addListener(FlywheelForge::onLoadComplete); - modEventBus.addListener(BackendEventHandler::onEndClientResourceReload); + modEventBus.addListener((EndClientResourceReloadEvent e) -> BackendManagerImpl.onEndClientResourceReload(e.error().isPresent())); - modEventBus.addListener($ -> ModelCache.onEndClientResourceReload()); - modEventBus.addListener($ -> ModelHolder.onEndClientResourceReload()); + modEventBus.addListener((EndClientResourceReloadEvent e) -> ModelCache.onEndClientResourceReload()); + modEventBus.addListener((EndClientResourceReloadEvent e) -> ModelHolder.onEndClientResourceReload()); modEventBus.addListener(PartialModelEventHandler::onModelRegistry); modEventBus.addListener(PartialModelEventHandler::onModelBake); @@ -134,7 +127,7 @@ public class FlywheelForge { ArrayList info = event.getRight(); info.add(""); - info.add("Flywheel: " + getVersion()); + info.add("Flywheel: " + version); info.add("Backend: " + BackendManagerImpl.getBackendString()); info.add("Update limiting: " + (FlwConfig.get().limitUpdates() ? "on" : "off")); @@ -149,8 +142,4 @@ public class FlywheelForge { info.add("Memory Usage: CPU: " + StringUtil.formatBytes(FlwMemoryTracker.getCPUMemory()) + ", GPU: " + StringUtil.formatBytes(FlwMemoryTracker.getGPUMemory())); } - - public static ArtifactVersion getVersion() { - return version; - } } diff --git a/forge/src/main/java/com/jozufozu/flywheel/impl/FlywheelLibPlatformImpl.java b/forge/src/main/java/com/jozufozu/flywheel/impl/FlywheelLibPlatformImpl.java deleted file mode 100644 index 547375265..000000000 --- a/forge/src/main/java/com/jozufozu/flywheel/impl/FlywheelLibPlatformImpl.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.jozufozu.flywheel.impl; - -import java.lang.reflect.Field; - -import org.slf4j.Logger; - -import com.jozufozu.flywheel.impl.extension.PoseStackExtension; -import com.jozufozu.flywheel.lib.internal.FlywheelLibPlatform; -import com.jozufozu.flywheel.lib.model.baked.BakedModelBuilder; -import com.jozufozu.flywheel.lib.model.baked.BlockModelBuilder; -import com.jozufozu.flywheel.lib.model.baked.ForgeBakedModelBuilder; -import com.jozufozu.flywheel.lib.model.baked.ForgeBlockModelBuilder; -import com.jozufozu.flywheel.lib.model.baked.ForgeMultiBlockModelBuilder; -import com.jozufozu.flywheel.lib.model.baked.MultiBlockModelBuilder; -import com.jozufozu.flywheel.lib.transform.PoseTransformStack; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.logging.LogUtils; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.block.BlockRenderDispatcher; -import net.minecraft.client.renderer.block.ModelBlockRenderer; -import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.fml.util.ObfuscationReflectionHelper; - -public class FlywheelLibPlatformImpl implements FlywheelLibPlatform { - private static final Logger LOGGER = LogUtils.getLogger(); - - @Override - public PoseTransformStack getPoseTransformStackOf(PoseStack stack) { - return ((PoseStackExtension) stack).flywheel$transformStack(); - } - - @Override - public BlockRenderDispatcher createVanillaRenderer() { - BlockRenderDispatcher defaultDispatcher = Minecraft.getInstance().getBlockRenderer(); - BlockRenderDispatcher dispatcher = new BlockRenderDispatcher(null, null, null); - try { - for (Field field : BlockRenderDispatcher.class.getDeclaredFields()) { - field.setAccessible(true); - field.set(dispatcher, field.get(defaultDispatcher)); - } - ObfuscationReflectionHelper.setPrivateValue(BlockRenderDispatcher.class, dispatcher, new ModelBlockRenderer(Minecraft.getInstance().getBlockColors()), "f_110900_"); - } catch (Exception e) { - LOGGER.error("Failed to initialize vanilla BlockRenderDispatcher!", e); - return defaultDispatcher; - } - return dispatcher; - } - - @Override - public BakedModelBuilder bakedModelBuilder(BakedModel bakedModel) { - return new ForgeBakedModelBuilder(bakedModel); - } - - @Override - public BlockModelBuilder blockModelBuilder(BlockState state) { - return new ForgeBlockModelBuilder(state); - } - - @Override - public MultiBlockModelBuilder multiBlockModelBuilder(BlockAndTintGetter level, Iterable positions) { - return new ForgeMultiBlockModelBuilder(level, positions); - } -} diff --git a/forge/src/main/java/com/jozufozu/flywheel/platform/ClientPlatformImpl.java b/forge/src/main/java/com/jozufozu/flywheel/platform/ClientPlatformImpl.java index f82da2fc8..8c2ae01a0 100644 --- a/forge/src/main/java/com/jozufozu/flywheel/platform/ClientPlatformImpl.java +++ b/forge/src/main/java/com/jozufozu/flywheel/platform/ClientPlatformImpl.java @@ -1,6 +1,9 @@ package com.jozufozu.flywheel.platform; +import java.lang.reflect.Field; + import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; import com.jozufozu.flywheel.api.event.BeginFrameEvent; import com.jozufozu.flywheel.api.event.ReloadLevelRendererEvent; @@ -9,16 +12,32 @@ import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.event.RenderStageEvent; import com.jozufozu.flywheel.config.FlwConfig; import com.jozufozu.flywheel.config.FlwForgeConfig; +import com.jozufozu.flywheel.lib.model.baked.BakedModelBuilder; +import com.jozufozu.flywheel.lib.model.baked.BlockModelBuilder; +import com.jozufozu.flywheel.lib.model.baked.ForgeBakedModelBuilder; +import com.jozufozu.flywheel.lib.model.baked.ForgeBlockModelBuilder; +import com.jozufozu.flywheel.lib.model.baked.ForgeMultiBlockModelBuilder; +import com.jozufozu.flywheel.lib.model.baked.MultiBlockModelBuilder; import com.jozufozu.flywheel.lib.util.ShadersModHandler; +import com.mojang.logging.LogUtils; import net.irisshaders.iris.api.v0.IrisApi; +import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.renderer.block.BlockRenderDispatcher; +import net.minecraft.client.renderer.block.ModelBlockRenderer; +import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.ModList; +import net.minecraftforge.fml.util.ObfuscationReflectionHelper; + +public class ClientPlatformImpl implements ClientPlatform { + private static final Logger LOGGER = LogUtils.getLogger(); -public class ClientPlatformImpl extends ClientPlatform { @Override public void dispatchReloadLevelRenderer(ClientLevel level) { MinecraftForge.EVENT_BUS.post(new ReloadLevelRendererEvent(level)); @@ -40,8 +59,8 @@ public class ClientPlatformImpl extends ClientPlatform { .isLoaded(modid); } - @Nullable @Override + @Nullable public ShadersModHandler.InternalHandler createIrisOculusHandlerIfPresent() { if (isModLoaded("oculus")) { return new ShadersModHandler.InternalHandler() { @@ -63,7 +82,7 @@ public class ClientPlatformImpl extends ClientPlatform { } @Override - public int getLightEmission(BlockState state, ClientLevel level, BlockPos pos) { + public int getLightEmission(BlockState state, BlockGetter level, BlockPos pos) { return state.getLightEmission(level, pos); } @@ -71,4 +90,36 @@ public class ClientPlatformImpl extends ClientPlatform { public FlwConfig getConfigInstance() { return FlwForgeConfig.INSTANCE; } + + @Override + public BlockRenderDispatcher createVanillaRenderer() { + BlockRenderDispatcher defaultDispatcher = Minecraft.getInstance().getBlockRenderer(); + BlockRenderDispatcher dispatcher = new BlockRenderDispatcher(null, null, null); + try { + for (Field field : BlockRenderDispatcher.class.getDeclaredFields()) { + field.setAccessible(true); + field.set(dispatcher, field.get(defaultDispatcher)); + } + ObfuscationReflectionHelper.setPrivateValue(BlockRenderDispatcher.class, dispatcher, new ModelBlockRenderer(Minecraft.getInstance().getBlockColors()), "f_110900_"); + } catch (Exception e) { + LOGGER.error("Failed to initialize vanilla BlockRenderDispatcher!", e); + return defaultDispatcher; + } + return dispatcher; + } + + @Override + public BakedModelBuilder bakedModelBuilder(BakedModel bakedModel) { + return new ForgeBakedModelBuilder(bakedModel); + } + + @Override + public BlockModelBuilder blockModelBuilder(BlockState state) { + return new ForgeBlockModelBuilder(state); + } + + @Override + public MultiBlockModelBuilder multiBlockModelBuilder(BlockAndTintGetter level, Iterable positions) { + return new ForgeMultiBlockModelBuilder(level, positions); + } } diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index 6a20ac8da..2dc330582 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -1,36 +1,35 @@ modLoader = "javafml" -loaderVersion = "${loader_version_range}" -issueTrackerURL = "${mod_issues}" +# The loader version doesn't matter. Modify the Forge and/or Minecraft version ranges instead. +loaderVersion = "[0,)" license = "${mod_license}" +issueTrackerURL = "${mod_issues}" [[mods]] modId = "${mod_id}" version = "${mod_version}" displayName = "${mod_name}" -logoFile = "logo.png" -displayURL = "${mod_homepage}" -authors = "Jozufozu, PepperCode1" description = "${mod_description}" +logoFile = "logo.png" +authors = "Jozufozu, PepperCode1" +displayURL = "${mod_homepage}" +displayTest = "IGNORE_ALL_VERSION" + +[[dependencies.${mod_id}]] +modId = "minecraft" +mandatory = true +versionRange = "${minecraft_maven_version_range}" +side = "CLIENT" [[dependencies.${mod_id}]] modId = "forge" mandatory = true versionRange = "${forge_version_range}" -ordering = "NONE" side = "CLIENT" [[dependencies.${mod_id}]] -modId = "minecraft" -mandatory = true -versionRange = "${minecraft_version_range}" -ordering = "NONE" -side = "CLIENT" - -[[dependencies.${mod_id}]] -modId = "rubidium" # This replicates a "breaks" dependency. # There's a mixin crash with Rubidium <0.7.0. +modId = "rubidium" mandatory = false versionRange = "[0.7.0,)" -ordering = "NONE" side = "CLIENT" diff --git a/common/src/main/resources/pack.mcmeta b/forge/src/main/resources/pack.mcmeta similarity index 100% rename from common/src/main/resources/pack.mcmeta rename to forge/src/main/resources/pack.mcmeta diff --git a/gradle.properties b/gradle.properties index 2bf7a0f10..b39b08802 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,42 +1,44 @@ org.gradle.jvmargs = -Xmx3G org.gradle.daemon = false -# General mod metadata +# Mod metadata mod_id = flywheel mod_name = Flywheel -mod_license = MIT +mod_version = 1.0.0-alpha mod_description = An overhauled entity and block entity rendering API. - +mod_license = MIT mod_sources = https://github.com/Jozufozu/Flywheel mod_issues = https://github.com/Jozufozu/Flywheel/issues mod_homepage = https://github.com/Jozufozu/Flywheel -# Mod version info -mod_version = 1.0.0-alpha -artifact_minecraft_version = 1.20.1 +# Mod dependency declarations +minecraft_semver_version_range = >=1.20.1 <1.20.2 +minecraft_maven_version_range = [1.20.1,1.20.2) +fabric_api_version_range = >=0.84.0 +forge_version_range = [47.0.0,) + +# General build dependency versions +java_version = 17 +arch_loom_version = 1.6-SNAPSHOT +cursegradle_version = 1.4.0 +parchment_version = 2023.09.03 + +# Minecraft build dependency versions minecraft_version = 1.20.1 forge_version = 47.2.19 fabric_loader_version = 0.15.9 fabric_api_version = 0.92.1+1.20.1 -# Version ranges for the mods.toml -minecraft_version_range = [1.20.1,1.20.2) -forge_version_range = [47,) -loader_version_range = [47,) - -# Build dependency versions -java_version = 17 -arch_loom_version = 1.6-SNAPSHOT -forgegradle_version = [6.0.16,6.2) -mixingradle_version = 0.7.+ -mixin_version = 0.8.5 -librarian_version = 1.+ -cursegradle_version = 1.4.0 -parchment_version = 2023.09.03 - -# dependency mod versions -embeddium_version = 0.3.9+mc1.20.1 -oculus_version = 1.20.1-1.6.15a +# Build dependency mod versions sodium_version = mc1.20.1-0.5.8 iris_version = 1.6.17+1.20.1 -starlight_version = 1.1.2+1.20 +embeddium_version = 0.3.9+mc1.20.1 +oculus_version = 1.20.1-1.6.15a + +# Publication info +artifact_minecraft_version = 1.20.1 + +#forgegradle_version = [6.0.16,6.2) +#mixingradle_version = 0.7.+ +#mixin_version = 0.8.5 +#librarian_version = 1.+ diff --git a/settings.gradle b/settings.gradle index db8285a90..bbbca7a35 100644 --- a/settings.gradle +++ b/settings.gradle @@ -13,6 +13,7 @@ pluginManagement { maven { url = 'https://repo.spongepowered.org/repository/maven-public' } maven { url = 'https://maven.parchmentmc.org' } } + plugins { id 'dev.architectury.loom' version arch_loom_version }