diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 1c5db0a1d..ae340d909 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -60,6 +60,8 @@ body: description: The version of the mod you were using when the bug occured options: - "0.7.0" + - "0.6.4" + - "0.6.3" - "0.6.2" - "0.6.1" - "0.6.0" diff --git a/LICENCE.md b/LICENSE.md similarity index 100% rename from LICENCE.md rename to LICENSE.md diff --git a/build.gradle b/build.gradle index b8364464a..10988a0ef 100644 --- a/build.gradle +++ b/build.gradle @@ -11,10 +11,10 @@ buildscript { classpath "org.parchmentmc:librarian:${librarian_version}" } } + plugins { id 'com.matthewprenger.cursegradle' version "${cursegradle_version}" } - apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.parchmentmc.librarian.forgegradle' apply plugin: 'eclipse' @@ -24,11 +24,10 @@ apply plugin: 'org.spongepowered.mixin' boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equalsIgnoreCase('false'); ext.buildNumber = System.getenv('BUILD_NUMBER') -if (buildNumber == null) buildNumber = 'custom' -version = "${mc_update_version}-${mod_version}" + (dev ? ".${buildNumber}" : '') group = 'com.jozufozu.flywheel' -archivesBaseName = 'flywheel-forge' +archivesBaseName = "flywheel-forge-${artifact_minecraft_version}" +version = mod_version + (dev && buildNumber != null ? "-${buildNumber}" : '') java.toolchain.languageVersion = JavaLanguageVersion.of(17) @@ -43,6 +42,8 @@ minecraft { property 'forge.logging.markers', '' property 'forge.logging.console.level', 'debug' property 'mixin.debug.export', 'true' + property 'mixin.env.remapRefMap', 'true' + property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg" property 'flw.dumpShaderSource', 'true' arg '-mixin.config=flywheel.mixins.json' @@ -87,10 +88,6 @@ minecraft { } } -mixin { - add sourceSets.main, 'flywheel.refmap.json' -} - repositories { maven { url 'https://www.cursemaven.com' @@ -102,12 +99,23 @@ repositories { name 'tterrag maven' url 'https://maven.tterrag.com/' } + maven { + name = "Modrinth" + url = "https://api.modrinth.com/maven" + content { + includeGroup "maven.modrinth" + } + } } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" - compileOnly fg.deobf("curse.maven:starlight-526854:3706539") + // switch to implementation for debugging + compileOnly fg.deobf("maven.modrinth:starlight-forge:1.0.2+1.18.2") + + compileOnly fg.deobf("maven.modrinth:rubidium:0.5.2a") + compileOnly fg.deobf("curse.maven:oculus-581495:3821406") // https://discord.com/channels/313125603924639766/725850371834118214/910619168821354497 // Prevent Mixin annotation processor from getting into IntelliJ's annotation processor settings @@ -117,23 +125,18 @@ dependencies { } } -// Example for how to get properties into the manifest for reading by the runtime.. -jar { - manifest { - attributes([ - 'Specification-Title' : 'flywheel', - //'Specification-Vendor': 'flywheel authors', - 'Specification-Version' : '1', // We are version 1 of ourselves - 'Implementation-Title' : project.name, - 'Implementation-Version' : project.version, - //'Implementation-Vendor': 'flywheel authors', - 'MixinConfigs' : 'flywheel.mixins.json', - 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") - ]) - } +mixin { + add sourceSets.main, 'flywheel.refmap.json' } -jar.finalizedBy('reobfJar') +// Workaround for SpongePowered/MixinGradle#38 +afterEvaluate { + tasks.configureReobfTaskForReobfJar.mustRunAfter(tasks.compileJava) +} + +tasks.withType(JavaCompile).configureEach { + options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation +} javadoc { source = [sourceSets.main.allJava] @@ -141,29 +144,42 @@ javadoc { options.addStringOption('Xdoclint:none', '-quiet') } -task sourcesJar(type: Jar) { - from sourceSets.main.allSource - archiveBaseName.set(project.archivesBaseName) - archiveVersion.set("${project.version}") - archiveClassifier.set('sources') +jar { + manifest { + attributes([ + 'Specification-Title' : 'flywheel', + //'Specification-Vendor': 'flywheel authors', + 'Specification-Version' : '1', // We are version 1 of ourselves + 'Implementation-Title' : project.jar.baseName, + 'Implementation-Version' : project.jar.archiveVersion, + //'Implementation-Vendor': 'flywheel authors', + 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), + 'MixinConfigs' : 'flywheel.mixins.json' + ]) + } } -task javadocJar(type: Jar, dependsOn: javadoc) { - from javadoc.destinationDir - archiveClassifier.set('javadoc') +java { + withSourcesJar() + withJavadocJar() } -artifacts { - archives jar, sourcesJar, javadocJar +void addLicense(jarTask) { + jarTask.from('LICENSE.md') { + rename '(.*)\\.(.*)', '$1_' + archivesBaseName + '.$2' + } } +jar.finalizedBy('reobfJar') +addLicense(jar) + publishing { - tasks.publish.dependsOn 'build' publications { mavenJava(MavenPublication) { - artifact jar - artifact sourcesJar - artifact javadocJar + artifactId = archivesBaseName + + from components.java + fg.component(it) } } diff --git a/changelog.txt b/changelog.txt index 89197f6e0..c7781fb32 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,16 @@ +0.6.4: +Fixes + - Fix shader detection with oculus +Technical/API + - LightUpdater is simplified to increase reliability and reflect how it is actually used + - ModelUtil is superseded by model builders, to be improved more in 0.7.0 + - VertexLists now copy input buffers to reduce memory usage + +0.6.3: +Technical/API + - Light updates are now processed in parallel. + - The light updater is now more selective of the levels it processes, fixing a memory leak. + 0.6.2: Update to 1.18.2 diff --git a/gradle.properties b/gradle.properties index e527cf99e..95019e8cf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,9 +3,10 @@ org.gradle.daemon = false # mod version info mod_version = 0.7.0 -mc_update_version = 1.18 +artifact_minecraft_version = 1.18.2 + minecraft_version = 1.18.2 -forge_version = 40.1.0 +forge_version = 40.1.68 # build dependency versions forgegradle_version = 5.1.+ @@ -13,7 +14,7 @@ mixingradle_version = 0.7-SNAPSHOT mixin_version = 0.8.5 librarian_version = 1.+ cursegradle_version = 1.4.0 -parchment_version = 2022.03.13 +parchment_version = 2022.07.10 # curseforge info projectId = 486392 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180f2..41d9927a4 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 84d1f85fd..aa991fcea 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index c53aefaa5..1b6c78733 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -32,10 +32,10 @@ # Busybox and similar reduced shells will NOT work, because this script # requires all of these POSIX shell features: # * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». # # Important for patching: # diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/AxisAngle4d.java b/joml/AxisAngle4d.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/AxisAngle4d.java rename to joml/AxisAngle4d.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/AxisAngle4f.java b/joml/AxisAngle4f.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/AxisAngle4f.java rename to joml/AxisAngle4f.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/ConfigurationException.java b/joml/ConfigurationException.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/ConfigurationException.java rename to joml/ConfigurationException.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/FrustumIntersection.java b/joml/FrustumIntersection.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/FrustumIntersection.java rename to joml/FrustumIntersection.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/FrustumRayBuilder.java b/joml/FrustumRayBuilder.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/FrustumRayBuilder.java rename to joml/FrustumRayBuilder.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/GeometryUtils.java b/joml/GeometryUtils.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/GeometryUtils.java rename to joml/GeometryUtils.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Interpolationd.java b/joml/Interpolationd.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Interpolationd.java rename to joml/Interpolationd.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Interpolationf.java b/joml/Interpolationf.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Interpolationf.java rename to joml/Interpolationf.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Intersectiond.java b/joml/Intersectiond.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Intersectiond.java rename to joml/Intersectiond.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Intersectionf.java b/joml/Intersectionf.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Intersectionf.java rename to joml/Intersectionf.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Math.java b/joml/Math.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Math.java rename to joml/Math.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix2d.java b/joml/Matrix2d.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix2d.java rename to joml/Matrix2d.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix2dc.java b/joml/Matrix2dc.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix2dc.java rename to joml/Matrix2dc.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix2f.java b/joml/Matrix2f.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix2f.java rename to joml/Matrix2f.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix2fc.java b/joml/Matrix2fc.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix2fc.java rename to joml/Matrix2fc.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3d.java b/joml/Matrix3d.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3d.java rename to joml/Matrix3d.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3dStack.java b/joml/Matrix3dStack.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3dStack.java rename to joml/Matrix3dStack.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3dc.java b/joml/Matrix3dc.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3dc.java rename to joml/Matrix3dc.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3f.java b/joml/Matrix3f.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3f.java rename to joml/Matrix3f.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3fStack.java b/joml/Matrix3fStack.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3fStack.java rename to joml/Matrix3fStack.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3fc.java b/joml/Matrix3fc.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3fc.java rename to joml/Matrix3fc.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3x2d.java b/joml/Matrix3x2d.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3x2d.java rename to joml/Matrix3x2d.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3x2dStack.java b/joml/Matrix3x2dStack.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3x2dStack.java rename to joml/Matrix3x2dStack.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3x2dc.java b/joml/Matrix3x2dc.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3x2dc.java rename to joml/Matrix3x2dc.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3x2f.java b/joml/Matrix3x2f.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3x2f.java rename to joml/Matrix3x2f.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3x2fStack.java b/joml/Matrix3x2fStack.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3x2fStack.java rename to joml/Matrix3x2fStack.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3x2fc.java b/joml/Matrix3x2fc.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix3x2fc.java rename to joml/Matrix3x2fc.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4d.java b/joml/Matrix4d.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4d.java rename to joml/Matrix4d.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4dStack.java b/joml/Matrix4dStack.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4dStack.java rename to joml/Matrix4dStack.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4dc.java b/joml/Matrix4dc.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4dc.java rename to joml/Matrix4dc.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4f.java b/joml/Matrix4f.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4f.java rename to joml/Matrix4f.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4fStack.java b/joml/Matrix4fStack.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4fStack.java rename to joml/Matrix4fStack.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4fc.java b/joml/Matrix4fc.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4fc.java rename to joml/Matrix4fc.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4x3d.java b/joml/Matrix4x3d.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4x3d.java rename to joml/Matrix4x3d.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4x3dStack.java b/joml/Matrix4x3dStack.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4x3dStack.java rename to joml/Matrix4x3dStack.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4x3dc.java b/joml/Matrix4x3dc.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4x3dc.java rename to joml/Matrix4x3dc.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4x3f.java b/joml/Matrix4x3f.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4x3f.java rename to joml/Matrix4x3f.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4x3fStack.java b/joml/Matrix4x3fStack.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4x3fStack.java rename to joml/Matrix4x3fStack.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4x3fc.java b/joml/Matrix4x3fc.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Matrix4x3fc.java rename to joml/Matrix4x3fc.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/MemUtil.java b/joml/MemUtil.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/MemUtil.java rename to joml/MemUtil.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Options.java b/joml/Options.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Options.java rename to joml/Options.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/PolygonsIntersection.java b/joml/PolygonsIntersection.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/PolygonsIntersection.java rename to joml/PolygonsIntersection.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Quaterniond.java b/joml/Quaterniond.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Quaterniond.java rename to joml/Quaterniond.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/QuaterniondInterpolator.java b/joml/QuaterniondInterpolator.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/QuaterniondInterpolator.java rename to joml/QuaterniondInterpolator.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Quaterniondc.java b/joml/Quaterniondc.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Quaterniondc.java rename to joml/Quaterniondc.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Quaternionf.java b/joml/Quaternionf.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Quaternionf.java rename to joml/Quaternionf.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/QuaternionfInterpolator.java b/joml/QuaternionfInterpolator.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/QuaternionfInterpolator.java rename to joml/QuaternionfInterpolator.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Quaternionfc.java b/joml/Quaternionfc.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Quaternionfc.java rename to joml/Quaternionfc.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Random.java b/joml/Random.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Random.java rename to joml/Random.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/RayAabIntersection.java b/joml/RayAabIntersection.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/RayAabIntersection.java rename to joml/RayAabIntersection.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/RoundingMode.java b/joml/RoundingMode.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/RoundingMode.java rename to joml/RoundingMode.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Runtime.java b/joml/Runtime.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Runtime.java rename to joml/Runtime.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/SimplexNoise.java b/joml/SimplexNoise.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/SimplexNoise.java rename to joml/SimplexNoise.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Vector2d.java b/joml/Vector2d.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Vector2d.java rename to joml/Vector2d.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Vector2dc.java b/joml/Vector2dc.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Vector2dc.java rename to joml/Vector2dc.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Vector2f.java b/joml/Vector2f.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Vector2f.java rename to joml/Vector2f.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Vector2fc.java b/joml/Vector2fc.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Vector2fc.java rename to joml/Vector2fc.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Vector2i.java b/joml/Vector2i.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Vector2i.java rename to joml/Vector2i.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Vector2ic.java b/joml/Vector2ic.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Vector2ic.java rename to joml/Vector2ic.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Vector3d.java b/joml/Vector3d.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Vector3d.java rename to joml/Vector3d.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Vector3dc.java b/joml/Vector3dc.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Vector3dc.java rename to joml/Vector3dc.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Vector3f.java b/joml/Vector3f.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Vector3f.java rename to joml/Vector3f.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Vector3fc.java b/joml/Vector3fc.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Vector3fc.java rename to joml/Vector3fc.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Vector3i.java b/joml/Vector3i.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Vector3i.java rename to joml/Vector3i.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Vector3ic.java b/joml/Vector3ic.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Vector3ic.java rename to joml/Vector3ic.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Vector4d.java b/joml/Vector4d.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Vector4d.java rename to joml/Vector4d.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Vector4dc.java b/joml/Vector4dc.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Vector4dc.java rename to joml/Vector4dc.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Vector4f.java b/joml/Vector4f.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Vector4f.java rename to joml/Vector4f.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Vector4fc.java b/joml/Vector4fc.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Vector4fc.java rename to joml/Vector4fc.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Vector4i.java b/joml/Vector4i.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Vector4i.java rename to joml/Vector4i.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/Vector4ic.java b/joml/Vector4ic.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/Vector4ic.java rename to joml/Vector4ic.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/package.html b/joml/package.html similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/package.html rename to joml/package.html diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/sampling/BestCandidateSampling.java b/joml/sampling/BestCandidateSampling.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/sampling/BestCandidateSampling.java rename to joml/sampling/BestCandidateSampling.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/sampling/Callback2d.java b/joml/sampling/Callback2d.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/sampling/Callback2d.java rename to joml/sampling/Callback2d.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/sampling/Callback3d.java b/joml/sampling/Callback3d.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/sampling/Callback3d.java rename to joml/sampling/Callback3d.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/sampling/Convolution.java b/joml/sampling/Convolution.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/sampling/Convolution.java rename to joml/sampling/Convolution.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/sampling/Math.java b/joml/sampling/Math.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/sampling/Math.java rename to joml/sampling/Math.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/sampling/PoissonSampling.java b/joml/sampling/PoissonSampling.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/sampling/PoissonSampling.java rename to joml/sampling/PoissonSampling.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/sampling/SpiralSampling.java b/joml/sampling/SpiralSampling.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/sampling/SpiralSampling.java rename to joml/sampling/SpiralSampling.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/sampling/StratifiedSampling.java b/joml/sampling/StratifiedSampling.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/sampling/StratifiedSampling.java rename to joml/sampling/StratifiedSampling.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/sampling/UniformSampling.java b/joml/sampling/UniformSampling.java similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/sampling/UniformSampling.java rename to joml/sampling/UniformSampling.java diff --git a/src/main/java/com/jozufozu/flywheel/repack/joml/sampling/package.html b/joml/sampling/package.html similarity index 100% rename from src/main/java/com/jozufozu/flywheel/repack/joml/sampling/package.html rename to joml/sampling/package.html diff --git a/src/main/java/com/jozufozu/flywheel/Flywheel.java b/src/main/java/com/jozufozu/flywheel/Flywheel.java index 1c8c1d90d..7d7465897 100644 --- a/src/main/java/com/jozufozu/flywheel/Flywheel.java +++ b/src/main/java/com/jozufozu/flywheel/Flywheel.java @@ -4,7 +4,7 @@ import org.apache.maven.artifact.versioning.ArtifactVersion; import org.slf4j.Logger; import com.jozufozu.flywheel.backend.Backend; -import com.jozufozu.flywheel.backend.OptifineHandler; +import com.jozufozu.flywheel.backend.ShadersModHandler; import com.jozufozu.flywheel.backend.RenderWork; import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; import com.jozufozu.flywheel.backend.model.MeshPool; @@ -80,7 +80,7 @@ public class Flywheel { private static void clientInit(IEventBus forgeEventBus, IEventBus modEventBus) { CrashReportCallables.registerCrashCallable("Flywheel Backend", Backend::getBackendDescriptor); - OptifineHandler.init(); + ShadersModHandler.init(); Backend.init(); forgeEventBus.addListener(FlwCommands::registerClientCommands); diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/backend/Backend.java index 5ef696741..a9e826e70 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/Backend.java +++ b/src/main/java/com/jozufozu/flywheel/backend/Backend.java @@ -90,7 +90,7 @@ public class Backend { BackendType preferredChoice = FlwConfig.get() .getBackendType(); - boolean usingShaders = OptifineHandler.isUsingShaders(); + boolean usingShaders = ShadersModHandler.isShaderPackInUse(); boolean canUseEngine = switch (preferredChoice) { case OFF -> true; case BATCHING -> !usingShaders; diff --git a/src/main/java/com/jozufozu/flywheel/backend/OptifineHandler.java b/src/main/java/com/jozufozu/flywheel/backend/OptifineHandler.java deleted file mode 100644 index 06c60498f..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/OptifineHandler.java +++ /dev/null @@ -1,117 +0,0 @@ -package com.jozufozu.flywheel.backend; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.function.BooleanSupplier; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.client.Camera; -import net.minecraft.client.renderer.culling.Frustum; - -public final class OptifineHandler { - public static final String OPTIFINE_ROOT_PACKAGE = "net.optifine"; - public static final String SHADER_PACKAGE = "net.optifine.shaders"; - - private static boolean isOptifineInstalled; - private static BooleanSupplier shadersEnabledSupplier; - private static BooleanSupplier shadowPassSupplier; - private static FrustumConstructor shadowFrustumConstructor; - - private OptifineHandler() { - } - - private static FrustumConstructor createShadowFrustumConstructor() { - try { - Class ofShaders = Class.forName("net.optifine.shaders.ShadersRender"); - Method method = ofShaders.getDeclaredMethod("makeShadowFrustum", Camera.class, Float.TYPE); - method.setAccessible(true); - return (cam, pt) -> { - try { - return (Frustum) method.invoke(null, cam, pt); - } catch (Exception ignored) { - return null; - } - }; - } catch (Exception ignored) { - return ($, $$) -> null; - } - } - - private static BooleanSupplier createShadowPassSupplier() { - try { - Class ofShaders = Class.forName("net.optifine.shaders.Shaders"); - Field field = ofShaders.getDeclaredField("isShadowPass"); - field.setAccessible(true); - return () -> { - try { - return field.getBoolean(null); - } catch (IllegalAccessException ignored) { - return false; - } - }; - } catch (Exception ignored) { - return () -> false; - } - } - - private static BooleanSupplier createShadersEnabledSupplier() { - try { - Class ofShaders = Class.forName("net.optifine.shaders.Shaders"); - Field field = ofShaders.getDeclaredField("shaderPackLoaded"); - field.setAccessible(true); - return () -> { - try { - return field.getBoolean(null); - } catch (IllegalAccessException ignored) { - return false; - } - }; - } catch (Exception ignored) { - return () -> false; - } - } - - public static void init() { - Package optifinePackage = Package.getPackage(OPTIFINE_ROOT_PACKAGE); - isOptifineInstalled = optifinePackage != null; - - if (isOptifineInstalled) { - Backend.LOGGER.info("Optifine detected."); - } else { - Backend.LOGGER.info("Optifine not detected."); - } - - shadersEnabledSupplier = createShadersEnabledSupplier(); - shadowPassSupplier = createShadowPassSupplier(); - shadowFrustumConstructor = createShadowFrustumConstructor(); - } - - public static boolean isOptifineInstalled() { - return isOptifineInstalled; - } - - public static boolean isUsingShaders() { - return shadersEnabledSupplier.getAsBoolean(); - } - - public static boolean isShadowPass() { - return shadowPassSupplier.getAsBoolean(); - } - - @Nullable - public static Frustum createShadowFrustum(Camera camera, float partialTicks) { - var frustum = shadowFrustumConstructor.create(camera, partialTicks); - if (frustum != null) { - var position = camera.getPosition(); - frustum.prepare(position.x, position.y, position.z); - } - return frustum; - } - - @FunctionalInterface - public interface FrustumConstructor { - @Nullable - Frustum create(Camera camera, float partialTicks); - } -} diff --git a/src/main/java/com/jozufozu/flywheel/backend/ShadersModHandler.java b/src/main/java/com/jozufozu/flywheel/backend/ShadersModHandler.java new file mode 100644 index 000000000..d96eef8a0 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/ShadersModHandler.java @@ -0,0 +1,179 @@ +package com.jozufozu.flywheel.backend; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.function.BooleanSupplier; + +import javax.annotation.Nullable; + +import net.irisshaders.iris.api.v0.IrisApi; +import net.minecraft.client.Camera; +import net.minecraft.client.renderer.culling.Frustum; +import net.minecraftforge.fml.ModList; + +public final class ShadersModHandler { + public static final String OPTIFINE_ROOT_PACKAGE = "net.optifine"; + public static final String SHADER_PACKAGE = "net.optifine.shaders"; + + private static final boolean isOculusLoaded; + private static final boolean isOptifineInstalled; + private static final InternalHandler internalHandler; + + static { + Package optifinePackage = Package.getPackage(OPTIFINE_ROOT_PACKAGE); + isOptifineInstalled = optifinePackage != null; + isOculusLoaded = ModList.get() + .isLoaded("oculus"); + + // optfine and oculus are assumed to be mutually exclusive + + if (isOptifineInstalled) { + Backend.LOGGER.info("Optifine detected."); + internalHandler = new Optifine(); + } else if (isOculusLoaded) { + Backend.LOGGER.info("Oculus detected."); + internalHandler = new Oculus(); + } else { + Backend.LOGGER.info("No shaders mod detected."); + internalHandler = new InternalHandler() {}; + } + } + + private ShadersModHandler() { + } + + public static void init() { + // noop, load statics + } + + public static boolean isOptifineInstalled() { + return isOptifineInstalled; + } + + public static boolean isOculusLoaded() { + return isOculusLoaded; + } + + public static boolean isShaderPackInUse() { + return internalHandler.isShaderPackInUse(); + } + + public static boolean isRenderingShadowPass() { + return internalHandler.isRenderingShadowPass(); + } + + private interface InternalHandler { + default boolean isShaderPackInUse() { + return false; + }; + + default boolean isRenderingShadowPass() { + return false; + }; + } + + // simple, lovely api calls + private static class Oculus implements InternalHandler { + @Override + public boolean isShaderPackInUse() { + return IrisApi.getInstance() + .isShaderPackInUse(); + } + + @Override + public boolean isRenderingShadowPass() { + return IrisApi.getInstance() + .isRenderingShadowPass(); + } + } + + // evil reflection + private static class Optifine implements InternalHandler { + private final BooleanSupplier shadersEnabledSupplier; + private final BooleanSupplier shadowPassSupplier; + private final FrustumConstructor shadowFrustumConstructor; + + Optifine() { + shadersEnabledSupplier = createShadersEnabledSupplier(); + shadowPassSupplier = createShadowPassSupplier(); + shadowFrustumConstructor = createShadowFrustumConstructor(); + } + + @Override + public boolean isShaderPackInUse() { + return shadersEnabledSupplier.getAsBoolean(); + } + + @Override + public boolean isRenderingShadowPass() { + return shadowPassSupplier.getAsBoolean(); + } + + @Nullable + public Frustum createShadowFrustum(Camera camera, float partialTicks) { + var frustum = shadowFrustumConstructor.create(camera, partialTicks); + if (frustum != null) { + var position = camera.getPosition(); + frustum.prepare(position.x, position.y, position.z); + } + return frustum; + } + + private static FrustumConstructor createShadowFrustumConstructor() { + try { + Class ofShaders = Class.forName("net.optifine.shaders.ShadersRender"); + Method method = ofShaders.getDeclaredMethod("makeShadowFrustum", Camera.class, Float.TYPE); + method.setAccessible(true); + return (cam, pt) -> { + try { + return (Frustum) method.invoke(null, cam, pt); + } catch (Exception ignored) { + return null; + } + }; + } catch (Exception ignored) { + return ($, $$) -> null; + } + } + + private static BooleanSupplier createShadowPassSupplier() { + try { + Class ofShaders = Class.forName("net.optifine.shaders.Shaders"); + Field field = ofShaders.getDeclaredField("isShadowPass"); + field.setAccessible(true); + return () -> { + try { + return field.getBoolean(null); + } catch (IllegalAccessException ignored) { + return false; + } + }; + } catch (Exception ignored) { + return () -> false; + } + } + + private static BooleanSupplier createShadersEnabledSupplier() { + try { + Class ofShaders = Class.forName("net.optifine.shaders.Shaders"); + Field field = ofShaders.getDeclaredField("shaderPackLoaded"); + field.setAccessible(true); + return () -> { + try { + return field.getBoolean(null); + } catch (IllegalAccessException ignored) { + return false; + } + }; + } catch (Exception ignored) { + return () -> false; + } + } + + @FunctionalInterface + public interface FrustumConstructor { + @Nullable + Frustum create(Camera camera, float partialTicks); + } + } +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstance.java index b66ef4617..d75ec3a2d 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstance.java @@ -10,8 +10,6 @@ import com.jozufozu.flywheel.api.instance.TickableInstance; import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstanceManager; import com.jozufozu.flywheel.core.structs.FlatLit; import com.jozufozu.flywheel.light.LightListener; -import com.jozufozu.flywheel.light.LightProvider; -import com.jozufozu.flywheel.light.ListenerStatus; import com.jozufozu.flywheel.util.box.ImmutableBox; import net.minecraft.core.BlockPos; @@ -26,6 +24,7 @@ public abstract class AbstractInstance implements Instance, LightListener { protected final InstancerManager instancerManager; public final Level level; + protected boolean removed = false; public AbstractInstance(InstancerManager instancerManager, Level level) { this.instancerManager = instancerManager; @@ -39,10 +38,19 @@ public abstract class AbstractInstance implements Instance, LightListener { } + public final void removeAndMark() { + if (removed) { + return; + } + + remove(); + removed = true; + } + /** * Free any acquired resources. */ - public abstract void remove(); + protected abstract void remove(); /** * Update instance data here. Good for when data doesn't change very often and when animations are GPU based. @@ -78,12 +86,12 @@ public abstract class AbstractInstance implements Instance, LightListener { } @Override - public ListenerStatus status() { - return ListenerStatus.OKAY; + public boolean isListenerInvalid() { + return removed; } @Override - public void onLightUpdate(LightProvider world, LightLayer type, ImmutableBox changed) { + public void onLightUpdate(LightLayer type, ImmutableBox changed) { updateLight(); } @@ -103,4 +111,5 @@ public abstract class AbstractInstance implements Instance, LightListener { models.forEach(model -> model.setBlockLight(block) .setSkyLight(sky)); } + } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterialGroup.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterialGroup.java new file mode 100644 index 000000000..e69de29bb diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingEngine.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingEngine.java index b0a932af6..585015cb0 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingEngine.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingEngine.java @@ -7,7 +7,7 @@ import java.util.Map; import com.jozufozu.flywheel.api.InstancedPart; import com.jozufozu.flywheel.api.struct.StructType; -import com.jozufozu.flywheel.backend.OptifineHandler; +import com.jozufozu.flywheel.backend.ShadersModHandler; import com.jozufozu.flywheel.backend.instancing.*; import com.jozufozu.flywheel.core.RenderContext; import com.jozufozu.flywheel.util.FlwUtil; @@ -55,7 +55,7 @@ public class BatchingEngine implements Engine { var consumer = batchTracker.getDirectConsumer(renderType, vertices); consumer.memSetZero(); - var outputColorDiffuse = !consumer.hasOverlay() && !OptifineHandler.isUsingShaders(); + var outputColorDiffuse = !consumer.hasOverlay() && !ShadersModHandler.isShaderPackInUse(); for (var transformSet : renderList) { transformSet.setOutputColorDiffuse(outputColorDiffuse); diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/effect/EffectInstanceManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/effect/EffectInstanceManager.java index 14f686f1e..e6f4b544b 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/effect/EffectInstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/effect/EffectInstanceManager.java @@ -69,7 +69,7 @@ public class EffectInstanceManager extends InstanceManager { @Override public void invalidate() { - instances.values().forEach(AbstractInstance::remove); + instances.values().forEach(AbstractInstance::removeAndMark); instances.clear(); tickableInstances.clear(); dynamicInstances.clear(); @@ -115,7 +115,7 @@ public class EffectInstanceManager extends InstanceManager { public void recreateAll() { this.dynamicInstances.clear(); this.tickableInstances.clear(); - this.instances.values().forEach(AbstractInstance::remove); + this.instances.values().forEach(AbstractInstance::removeAndMark); var backup = new ArrayList<>(this.instances.keySet()); this.instances.clear(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstance.java index 29115a43a..aed1461a1 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstance.java @@ -6,8 +6,7 @@ import com.jozufozu.flywheel.api.instance.TickableInstance; import com.jozufozu.flywheel.backend.instancing.AbstractInstance; import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstanceManager; import com.jozufozu.flywheel.light.LightListener; -import com.jozufozu.flywheel.light.LightProvider; -import com.jozufozu.flywheel.light.MovingListener; +import com.jozufozu.flywheel.light.TickingLightListener; import com.jozufozu.flywheel.util.box.GridAlignedBB; import com.mojang.math.Vector3f; @@ -34,7 +33,7 @@ import net.minecraft.world.phys.Vec3; * * @param The type of {@link Entity} your class is an instance of. */ -public abstract class EntityInstance extends AbstractInstance implements LightListener, MovingListener { +public abstract class EntityInstance extends AbstractInstance implements LightListener, TickingLightListener { protected final E entity; protected final GridAlignedBB bounds; @@ -51,7 +50,7 @@ public abstract class EntityInstance extends AbstractInstance } @Override - public boolean update(LightProvider provider) { + public boolean tickLightListener() { AABB boundsNow = entity.getBoundingBox(); if (bounds.sameAs(boundsNow)) return false; diff --git a/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java b/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java index 18e487b4d..c9365b451 100644 --- a/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java +++ b/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java @@ -23,7 +23,6 @@ import net.minecraft.network.chat.TextComponent; import net.minecraft.world.entity.Entity; import net.minecraftforge.client.event.RegisterClientCommandsEvent; import net.minecraftforge.common.ForgeConfigSpec.ConfigValue; -import net.minecraftforge.fml.ModList; public class FlwCommands { public static void registerClientCommands(RegisterClientCommandsEvent event) { @@ -141,17 +140,7 @@ public class FlwCommands { return switch (type) { case OFF -> new TextComponent("Disabled Flywheel").withStyle(ChatFormatting.RED); case INSTANCING -> new TextComponent("Using Instancing Engine").withStyle(ChatFormatting.GREEN); - case BATCHING -> { - MutableComponent msg = new TextComponent("Using Batching Engine").withStyle(ChatFormatting.GREEN); - - if (ModList.get() - .isLoaded("create")) { - // FIXME: batching engine contraption lighting issues - msg.append(new TextComponent("\nWARNING: May cause issues with Create Contraptions").withStyle(ChatFormatting.RED)); - } - - yield msg; - } + case BATCHING -> new TextComponent("Using Batching Engine").withStyle(ChatFormatting.GREEN); }; } diff --git a/src/main/java/com/jozufozu/flywheel/core/CoreShaderInfoMap.java b/src/main/java/com/jozufozu/flywheel/core/CoreShaderInfoMap.java index e69a856c5..9e6e16ffb 100644 --- a/src/main/java/com/jozufozu/flywheel/core/CoreShaderInfoMap.java +++ b/src/main/java/com/jozufozu/flywheel/core/CoreShaderInfoMap.java @@ -9,7 +9,7 @@ import java.util.Map; import org.jetbrains.annotations.Nullable; -import com.jozufozu.flywheel.backend.OptifineHandler; +import com.jozufozu.flywheel.backend.ShadersModHandler; import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.renderer.ShaderInstance; @@ -31,7 +31,7 @@ public class CoreShaderInfoMap { registerInfo("position_tex_color_normal", new CoreShaderInfo(0.1f, false, COLOR_FOG)); registerInfo("position_tex_lightmap_color", new CoreShaderInfo(0.1f, false, NO_FOG)); registerInfo("rendertype_solid", new CoreShaderInfo(-1, false, COLOR_FOG)); - registerInfo("rendertype_cutout_mipped", new CoreShaderInfo(OptifineHandler.isOptifineInstalled() ? 0.1f : 0.5f, false, COLOR_FOG)); + registerInfo("rendertype_cutout_mipped", new CoreShaderInfo(ShadersModHandler.isShaderPackInUse() ? 0.1f : 0.5f, false, COLOR_FOG)); registerInfo("rendertype_cutout", new CoreShaderInfo(0.1f, false, COLOR_FOG)); registerInfo("rendertype_translucent", new CoreShaderInfo(-1, false, COLOR_FOG)); registerInfo("rendertype_translucent_moving_block", new CoreShaderInfo(-1, false, NO_FOG)); diff --git a/src/main/java/com/jozufozu/flywheel/core/model/WorldModelBuilder.java b/src/main/java/com/jozufozu/flywheel/core/model/WorldModelBuilder.java index 80f4f8470..03cee1d30 100644 --- a/src/main/java/com/jozufozu/flywheel/core/model/WorldModelBuilder.java +++ b/src/main/java/com/jozufozu/flywheel/core/model/WorldModelBuilder.java @@ -57,6 +57,9 @@ public final class WorldModelBuilder implements Bufferable { ForgeHooksClient.setRenderType(null); } + /** + * It is expected that {@code renderWorld.getShade(...)} returns a constant. + */ public WorldModelBuilder withRenderWorld(BlockAndTintGetter renderWorld) { this.renderWorld = renderWorld; return this; diff --git a/src/main/java/com/jozufozu/flywheel/core/vertex/AbstractVertexList.java b/src/main/java/com/jozufozu/flywheel/core/vertex/AbstractVertexList.java new file mode 100644 index 000000000..a68e0c943 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/core/vertex/AbstractVertexList.java @@ -0,0 +1,49 @@ +package com.jozufozu.flywheel.core.vertex; + +import java.nio.Buffer; +import java.nio.ByteBuffer; + +import org.lwjgl.system.MemoryUtil; + +import com.jozufozu.flywheel.api.vertex.VertexList; +import com.mojang.blaze3d.platform.MemoryTracker; +import com.mojang.blaze3d.vertex.BufferBuilder; + +public abstract class AbstractVertexList implements VertexList, AutoCloseable { + + protected final ByteBuffer contents; + protected final long base; + protected final int vertexCount; + + protected AbstractVertexList(ByteBuffer copyFrom, int vertexCount) { + this.contents = MemoryTracker.create(copyFrom.capacity()); + this.vertexCount = vertexCount; + this.base = MemoryUtil.memAddress(this.contents); + init(copyFrom); + } + + public AbstractVertexList(BufferBuilder builder) { + var pair = builder.popNextBuffer(); + ByteBuffer copyFrom = pair.getSecond(); + this.contents = MemoryTracker.create(copyFrom.capacity()); + this.vertexCount = pair.getFirst().vertexCount(); + this.base = MemoryUtil.memAddress(this.contents); + init(copyFrom); + } + + private void init(ByteBuffer copyFrom) { + this.contents.order(copyFrom.order()); + this.contents.put(copyFrom); + ((Buffer) this.contents).flip(); + } + + @Override + public void close() { + MemoryUtil.memFree(contents); + } + + @Override + public int getVertexCount() { + return vertexCount; + } +} diff --git a/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexList.java b/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexList.java index 8c856b94f..f595d4c1b 100644 --- a/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexList.java +++ b/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexList.java @@ -1,31 +1,20 @@ package com.jozufozu.flywheel.core.vertex; -import java.nio.ByteBuffer; - import com.jozufozu.flywheel.api.vertex.ShadedVertexList; import com.jozufozu.flywheel.api.vertex.VertexList; import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.core.model.ShadeSeparatedBufferBuilder; import com.jozufozu.flywheel.util.RenderMath; import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.datafixers.util.Pair; -public class BlockVertexList implements VertexList { +public class BlockVertexList extends AbstractVertexList { - private final ByteBuffer buffer; - private final int vertexCount; private final int stride; public BlockVertexList(BufferBuilder builder) { - Pair data = builder.popNextBuffer(); - buffer = data.getSecond(); - - stride = builder.getVertexFormat() + super(builder); + this.stride = builder.getVertexFormat() .getVertexSize(); - - vertexCount = data.getFirst() - .vertexCount(); - } @Override @@ -39,72 +28,67 @@ public class BlockVertexList implements VertexList { @Override public float getX(int index) { - return buffer.getFloat(vertIdx(index)); + return contents.getFloat(vertIdx(index)); } @Override public float getY(int index) { - return buffer.getFloat(vertIdx(index) + 4); + return contents.getFloat(vertIdx(index) + 4); } @Override public float getZ(int index) { - return buffer.getFloat(vertIdx(index) + 8); + return contents.getFloat(vertIdx(index) + 8); } @Override public byte getR(int index) { - return buffer.get(vertIdx(index) + 12); + return contents.get(vertIdx(index) + 12); } @Override public byte getG(int index) { - return buffer.get(vertIdx(index) + 13); + return contents.get(vertIdx(index) + 13); } @Override public byte getB(int index) { - return buffer.get(vertIdx(index) + 14); + return contents.get(vertIdx(index) + 14); } @Override public byte getA(int index) { - return buffer.get(vertIdx(index) + 15); + return contents.get(vertIdx(index) + 15); } @Override public float getU(int index) { - return buffer.getFloat(vertIdx(index) + 16); + return contents.getFloat(vertIdx(index) + 16); } @Override public float getV(int index) { - return buffer.getFloat(vertIdx(index) + 20); + return contents.getFloat(vertIdx(index) + 20); } @Override public int getLight(int index) { - return buffer.getInt(vertIdx(index) + 24); + return contents.getInt(vertIdx(index) + 24); } @Override public float getNX(int index) { - return RenderMath.f(buffer.get(vertIdx(index) + 28)); + return RenderMath.f(contents.get(vertIdx(index) + 28)); } @Override public float getNY(int index) { - return RenderMath.f(buffer.get(vertIdx(index) + 29)); + return RenderMath.f(contents.get(vertIdx(index) + 29)); } @Override public float getNZ(int index) { - return RenderMath.f(buffer.get(vertIdx(index) + 30)); - } - - @Override - public int getVertexCount() { - return vertexCount; + return RenderMath.f(contents.get(vertIdx(index) + 30)); } @Override diff --git a/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexListUnsafe.java b/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexListUnsafe.java index a3d6e5930..7b1065899 100644 --- a/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexListUnsafe.java +++ b/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexListUnsafe.java @@ -9,10 +9,10 @@ import com.jozufozu.flywheel.api.vertex.ShadedVertexList; import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.util.RenderMath; -public class BlockVertexListUnsafe extends TrackedVertexList { +public class BlockVertexListUnsafe extends AbstractVertexList { - public BlockVertexListUnsafe(ByteBuffer buffer, int vertexCount) { - super(buffer, vertexCount); + public BlockVertexListUnsafe(ByteBuffer copyFrom, int vertexCount) { + super(copyFrom, vertexCount); } private long ptr(long index) { diff --git a/src/main/java/com/jozufozu/flywheel/core/vertex/PosTexNormalVertexListUnsafe.java b/src/main/java/com/jozufozu/flywheel/core/vertex/PosTexNormalVertexListUnsafe.java index d01249a64..dbae103b0 100644 --- a/src/main/java/com/jozufozu/flywheel/core/vertex/PosTexNormalVertexListUnsafe.java +++ b/src/main/java/com/jozufozu/flywheel/core/vertex/PosTexNormalVertexListUnsafe.java @@ -1,6 +1,5 @@ package com.jozufozu.flywheel.core.vertex; -import java.lang.ref.Cleaner; import java.nio.ByteBuffer; import org.lwjgl.system.MemoryUtil; @@ -9,12 +8,11 @@ import com.jozufozu.flywheel.api.vertex.VertexList; import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.backend.FlywheelMemory; import com.jozufozu.flywheel.util.RenderMath; -import com.mojang.blaze3d.platform.MemoryTracker; -public class PosTexNormalVertexListUnsafe extends TrackedVertexList { +public class PosTexNormalVertexListUnsafe extends AbstractVertexList { - public PosTexNormalVertexListUnsafe(ByteBuffer buffer, int vertexCount) { - super(buffer, vertexCount); + public PosTexNormalVertexListUnsafe(ByteBuffer copyFrom, int vertexCount) { + super(copyFrom, vertexCount); } private long ptr(long idx) { diff --git a/src/main/java/com/jozufozu/flywheel/light/BasicProvider.java b/src/main/java/com/jozufozu/flywheel/light/BasicProvider.java deleted file mode 100644 index fb5d3b189..000000000 --- a/src/main/java/com/jozufozu/flywheel/light/BasicProvider.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.jozufozu.flywheel.light; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.LightLayer; - -/** - * Wraps a world and minimally lowers the interface. - */ -public class BasicProvider implements LightProvider { - - private final BlockAndTintGetter reader; - private final BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(); - - public BasicProvider(BlockAndTintGetter reader) { - this.reader = reader; - } - - @Override - public int getLight(LightLayer type, int x, int y, int z) { - return reader.getBrightness(type, pos.set(x, y, z)); - } -} diff --git a/src/main/java/com/jozufozu/flywheel/light/DummyLightUpdater.java b/src/main/java/com/jozufozu/flywheel/light/DummyLightUpdater.java new file mode 100644 index 000000000..0cb04f944 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/light/DummyLightUpdater.java @@ -0,0 +1,50 @@ +package com.jozufozu.flywheel.light; + +import java.util.stream.Stream; + +import com.jozufozu.flywheel.util.box.ImmutableBox; + +import net.minecraft.world.level.LightLayer; + +public class DummyLightUpdater extends LightUpdater { + public static final DummyLightUpdater INSTANCE = new DummyLightUpdater(); + + private DummyLightUpdater() { + super(null); + } + + @Override + public void tick() { + // noop + } + + @Override + public void addListener(LightListener listener) { + // noop + } + + @Override + public void removeListener(LightListener listener) { + // noop + } + + @Override + public void onLightUpdate(LightLayer type, long sectionPos) { + // noop + } + + @Override + public void onLightPacket(int chunkX, int chunkZ) { + // noop + } + + @Override + public Stream getAllBoxes() { + return Stream.empty(); + } + + @Override + public boolean isEmpty() { + return true; + } +} diff --git a/src/main/java/com/jozufozu/flywheel/light/GPULightVolume.java b/src/main/java/com/jozufozu/flywheel/light/GPULightVolume.java index fee086071..673670973 100644 --- a/src/main/java/com/jozufozu/flywheel/light/GPULightVolume.java +++ b/src/main/java/com/jozufozu/flywheel/light/GPULightVolume.java @@ -26,7 +26,7 @@ import com.jozufozu.flywheel.backend.gl.GlTextureUnit; import com.jozufozu.flywheel.util.box.GridAlignedBB; import com.jozufozu.flywheel.util.box.ImmutableBox; -import net.minecraft.world.level.LightLayer; +import net.minecraft.world.level.BlockAndTintGetter; public class GPULightVolume extends LightVolume { @@ -36,8 +36,8 @@ public class GPULightVolume extends LightVolume { private final GlTextureUnit textureUnit = GlTextureUnit.T4; protected boolean bufferDirty; - public GPULightVolume(ImmutableBox sampleVolume) { - super(sampleVolume); + public GPULightVolume(BlockAndTintGetter level, ImmutableBox sampleVolume) { + super(level, sampleVolume); this.sampleVolume.assign(sampleVolume); glTexture = new GlTexture(GL_TEXTURE_3D); @@ -110,38 +110,24 @@ public class GPULightVolume extends LightVolume { glTexture.delete(); } - public void move(LightProvider world, ImmutableBox newSampleVolume) { + public void move(ImmutableBox newSampleVolume) { if (lightData == null) return; if (box.contains(newSampleVolume)) { sampleVolume.assign(newSampleVolume); - initialize(world); + initialize(); } else { - super.move(world, newSampleVolume); + super.move(newSampleVolume); } } - public void onLightUpdate(LightProvider world, LightLayer type, ImmutableBox changedVolume) { - super.onLightUpdate(world, type, changedVolume); - bufferDirty = true; - } - - public void onLightPacket(LightProvider world, int chunkX, int chunkZ) { - super.onLightPacket(world, chunkX, chunkZ); - bufferDirty = true; - } - - /** - * Completely (re)populate this volume with block and sky lighting data. - * This is expensive and should be avoided. - */ - public void initialize(LightProvider world) { - super.initialize(world); - bufferDirty = true; - } - @Override public ImmutableBox getVolume() { return sampleVolume; } + + @Override + protected void markDirty() { + this.bufferDirty = true; + } } diff --git a/src/main/java/com/jozufozu/flywheel/light/LightListener.java b/src/main/java/com/jozufozu/flywheel/light/LightListener.java index 396ae6bbd..55a1e8020 100644 --- a/src/main/java/com/jozufozu/flywheel/light/LightListener.java +++ b/src/main/java/com/jozufozu/flywheel/light/LightListener.java @@ -5,26 +5,37 @@ import com.jozufozu.flywheel.util.box.ImmutableBox; import net.minecraft.world.level.LightLayer; +/** + * Implementors of this interface may choose to subscribe to light updates by calling + * {@link LightUpdater#addListener(LightListener)}.

+ * + * It is the responsibility of the implementor to keep a reference to the level an object is contained in. + */ public interface LightListener { ImmutableBox getVolume(); - ListenerStatus status(); + /** + * Check the status of the light listener. + * @return {@code true} if the listener is invalid/removed/deleted, + * and should no longer receive updates. + */ + boolean isListenerInvalid(); /** * Called when a light updates in a chunk the implementor cares about. */ - void onLightUpdate(LightProvider world, LightLayer type, ImmutableBox changed); + void onLightUpdate(LightLayer type, ImmutableBox changed); /** * Called when the server sends light data to the client. * */ - default void onLightPacket(LightProvider world, int chunkX, int chunkZ) { + default void onLightPacket(int chunkX, int chunkZ) { GridAlignedBB changedVolume = GridAlignedBB.from(chunkX, chunkZ); - onLightUpdate(world, LightLayer.BLOCK, changedVolume); + onLightUpdate(LightLayer.BLOCK, changedVolume); - onLightUpdate(world, LightLayer.SKY, changedVolume); + onLightUpdate(LightLayer.SKY, changedVolume); } } diff --git a/src/main/java/com/jozufozu/flywheel/light/LightProvider.java b/src/main/java/com/jozufozu/flywheel/light/LightProvider.java deleted file mode 100644 index c95a04df7..000000000 --- a/src/main/java/com/jozufozu/flywheel/light/LightProvider.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.jozufozu.flywheel.light; - -import net.minecraft.client.renderer.LightTexture; -import net.minecraft.world.level.LightLayer; - -public interface LightProvider { - int getLight(LightLayer type, int x, int y, int z); - - default int getPackedLight(int x, int y, int z) { - return LightTexture.pack(getLight(LightLayer.BLOCK, x, y, z), getLight(LightLayer.SKY, x, y, z)); - } -} diff --git a/src/main/java/com/jozufozu/flywheel/light/LightUpdated.java b/src/main/java/com/jozufozu/flywheel/light/LightUpdated.java new file mode 100644 index 000000000..4173ef2a8 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/light/LightUpdated.java @@ -0,0 +1,32 @@ +package com.jozufozu.flywheel.light; + +import net.minecraft.client.Minecraft; +import net.minecraft.world.level.LevelAccessor; + +/** + * Marker interface for custom/fake levels to indicate that LightUpdater should bother interacting with it.

+ * + * Implement this if your custom level has light updates at all. If so, be sure to call + * {@link com.jozufozu.flywheel.util.WorldAttached#invalidateWorld} when your level in unloaded. + */ +public interface LightUpdated extends LevelAccessor { + + /** + * @return {@code true} if this level is passing light updates into LightUpdater. + */ + default boolean receivesLightUpdates() { + return true; + } + + static boolean receivesLightUpdates(LevelAccessor level) { + // The client level is guaranteed to receive updates. + if (Minecraft.getInstance().level == level) { + return true; + } + // Custom/fake levels need to indicate that LightUpdater has meaning. + if (level instanceof LightUpdated c) { + return c.receivesLightUpdates(); + } + return false; + } +} diff --git a/src/main/java/com/jozufozu/flywheel/light/LightUpdater.java b/src/main/java/com/jozufozu/flywheel/light/LightUpdater.java index c1b3b4f54..9cce9fd44 100644 --- a/src/main/java/com/jozufozu/flywheel/light/LightUpdater.java +++ b/src/main/java/com/jozufozu/flywheel/light/LightUpdater.java @@ -20,29 +20,34 @@ import net.minecraft.world.level.LightLayer; /** * Keeps track of what chunks/sections each listener is in, so we can update exactly what needs to be updated. + * + * @apiNote Custom/fake levels (that are {@code != Minecraft.getInstance.level}) need to implement + * {@link LightUpdated} for LightUpdater to work with them. */ public class LightUpdater { - private static final WorldAttached light = new WorldAttached<>(LightUpdater::new); + private static final WorldAttached LEVELS = new WorldAttached<>(LightUpdater::new); private final ParallelTaskEngine taskEngine; - public static LightUpdater get(LevelAccessor world) { - return light.get(world); + public static LightUpdater get(LevelAccessor level) { + if (LightUpdated.receivesLightUpdates(level)) { + // The level is valid, add it to the map. + return LEVELS.get(level); + } else { + // Fake light updater for a fake level. + return DummyLightUpdater.INSTANCE; + } } - private final LightProvider provider; + private final LevelAccessor level; - private final WeakHashSet movingListeners = new WeakHashSet<>(); + private final WeakHashSet tickingLightListeners = new WeakHashSet<>(); private final WeakContainmentMultiMap sections = new WeakContainmentMultiMap<>(); private final WeakContainmentMultiMap chunks = new WeakContainmentMultiMap<>(); - public LightUpdater(LevelAccessor world) { + public LightUpdater(LevelAccessor level) { taskEngine = Backend.getTaskEngine(); - provider = new BasicProvider(world); - } - - public LightProvider getProvider() { - return provider; + this.level = level; } public void tick() { @@ -51,9 +56,9 @@ public class LightUpdater { } private void tickSerial() { - for (MovingListener movingListener : movingListeners) { - if (movingListener.update(provider)) { - addListener(movingListener); + for (TickingLightListener tickingLightListener : tickingLightListeners) { + if (tickingLightListener.tickLightListener()) { + addListener(tickingLightListener); } } } @@ -62,8 +67,8 @@ public class LightUpdater { Queue listeners = new ConcurrentLinkedQueue<>(); taskEngine.group("LightUpdater") - .addTasks(movingListeners.stream(), listener -> { - if (listener.update(provider)) { + .addTasks(tickingLightListeners.stream(), listener -> { + if (listener.tickLightListener()) { listeners.add(listener); } }) @@ -77,8 +82,8 @@ public class LightUpdater { * @param listener The object that wants to receive light update notifications. */ public void addListener(LightListener listener) { - if (listener instanceof MovingListener) - movingListeners.add(((MovingListener) listener)); + if (listener instanceof TickingLightListener) + tickingLightListeners.add(((TickingLightListener) listener)); ImmutableBox box = listener.getVolume(); @@ -121,12 +126,12 @@ public class LightUpdater { if (set == null || set.isEmpty()) return; - set.removeIf(l -> l.status().shouldRemove()); + set.removeIf(LightListener::isListenerInvalid); ImmutableBox chunkBox = GridAlignedBB.from(SectionPos.of(sectionPos)); for (LightListener listener : set) { - listener.onLightUpdate(provider, type, chunkBox); + listener.onLightUpdate(type, chunkBox); } } @@ -142,10 +147,10 @@ public class LightUpdater { if (set == null || set.isEmpty()) return; - set.removeIf(l -> l.status().shouldRemove()); + set.removeIf(LightListener::isListenerInvalid); for (LightListener listener : set) { - listener.onLightPacket(provider, chunkX, chunkZ); + listener.onLightPacket(chunkX, chunkZ); } } diff --git a/src/main/java/com/jozufozu/flywheel/light/LightVolume.java b/src/main/java/com/jozufozu/flywheel/light/LightVolume.java index b5a830f86..31245dea9 100644 --- a/src/main/java/com/jozufozu/flywheel/light/LightVolume.java +++ b/src/main/java/com/jozufozu/flywheel/light/LightVolume.java @@ -8,14 +8,17 @@ import com.jozufozu.flywheel.util.box.GridAlignedBB; import com.jozufozu.flywheel.util.box.ImmutableBox; import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.LightLayer; public class LightVolume implements ImmutableBox, LightListener { + protected final BlockAndTintGetter level; protected final GridAlignedBB box = new GridAlignedBB(); protected ByteBuffer lightData; - public LightVolume(ImmutableBox sampleVolume) { + public LightVolume(BlockAndTintGetter level, ImmutableBox sampleVolume) { + this.level = level; this.setBox(sampleVolume); this.lightData = MemoryUtil.memAlloc(this.box.volume() * 2); @@ -57,7 +60,7 @@ public class LightVolume implements ImmutableBox, LightListener { return box.getMaxZ(); } - public void move(LightProvider world, ImmutableBox newSampleVolume) { + public void move(ImmutableBox newSampleVolume) { if (lightData == null) return; setBox(newSampleVolume); @@ -65,51 +68,43 @@ public class LightVolume implements ImmutableBox, LightListener { if (neededCapacity > lightData.capacity()) { lightData = MemoryUtil.memRealloc(lightData, neededCapacity); } - initialize(world); + initialize(); } @Override - public void onLightUpdate(LightProvider world, LightLayer type, ImmutableBox changedVolume) { + public void onLightUpdate(LightLayer type, ImmutableBox changedVolume) { if (lightData == null) return; GridAlignedBB vol = changedVolume.copy(); if (!vol.intersects(getVolume())) return; vol.intersectAssign(getVolume()); // compute the region contained by us that has dirty lighting data. - if (type == LightLayer.BLOCK) copyBlock(world, vol); - else if (type == LightLayer.SKY) copySky(world, vol); + if (type == LightLayer.BLOCK) copyBlock(vol); + else if (type == LightLayer.SKY) copySky(vol); + markDirty(); } @Override - public void onLightPacket(LightProvider world, int chunkX, int chunkZ) { + public void onLightPacket(int chunkX, int chunkZ) { if (lightData == null) return; GridAlignedBB changedVolume = GridAlignedBB.from(chunkX, chunkZ); if (!changedVolume.intersects(getVolume())) return; changedVolume.intersectAssign(getVolume()); // compute the region contained by us that has dirty lighting data. - copyLight(world, changedVolume); + copyLight(changedVolume); + markDirty(); } /** * Completely (re)populate this volume with block and sky lighting data. * This is expensive and should be avoided. */ - public void initialize(LightProvider world) { + public void initialize() { if (lightData == null) return; - // the volume is indexed based on the greater bounding box - int shiftX = box.getMinX(); - int shiftY = box.getMinY(); - int shiftZ = box.getMinZ(); - - // ... but we only iterate over the (potentially) smaller sample volume - getVolume().forEachContained((x, y, z) -> { - int blockLight = world.getLight(LightLayer.BLOCK, x, y, z); - int skyLight = world.getLight(LightLayer.SKY, x, y, z); - - writeLight(x - shiftX, y - shiftY, z - shiftZ, blockLight, skyLight); - }); + copyLight(getVolume()); + markDirty(); } /** @@ -117,13 +112,15 @@ public class LightVolume implements ImmutableBox, LightListener { * * @param worldVolume the region in the world to copy data from. */ - public void copyBlock(LightProvider world, ImmutableBox worldVolume) { + public void copyBlock(ImmutableBox worldVolume) { + var pos = new BlockPos.MutableBlockPos(); + int xShift = box.getMinX(); int yShift = box.getMinY(); int zShift = box.getMinZ(); worldVolume.forEachContained((x, y, z) -> { - int light = world.getLight(LightLayer.BLOCK, x, y, z); + int light = this.level.getBrightness(LightLayer.BLOCK, pos.set(x, y, z)); writeBlock(x - xShift, y - yShift, z - zShift, light); }); @@ -134,13 +131,15 @@ public class LightVolume implements ImmutableBox, LightListener { * * @param worldVolume the region in the world to copy data from. */ - public void copySky(LightProvider world, ImmutableBox worldVolume) { + public void copySky(ImmutableBox worldVolume) { + var pos = new BlockPos.MutableBlockPos(); + int xShift = box.getMinX(); int yShift = box.getMinY(); int zShift = box.getMinZ(); worldVolume.forEachContained((x, y, z) -> { - int light = world.getLight(LightLayer.SKY, x, y, z); + int light = this.level.getBrightness(LightLayer.SKY, pos.set(x, y, z)); writeSky(x - xShift, y - yShift, z - zShift, light); }); @@ -151,7 +150,7 @@ public class LightVolume implements ImmutableBox, LightListener { * * @param worldVolume the region in the world to copy data from. */ - public void copyLight(LightProvider world, ImmutableBox worldVolume) { + public void copyLight(ImmutableBox worldVolume) { BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(); int xShift = box.getMinX(); @@ -161,8 +160,8 @@ public class LightVolume implements ImmutableBox, LightListener { worldVolume.forEachContained((x, y, z) -> { pos.set(x, y, z); - int block = world.getLight(LightLayer.BLOCK, x, y, z); - int sky = world.getLight(LightLayer.SKY, x, y, z); + int block = this.level.getBrightness(LightLayer.BLOCK, pos); + int sky = this.level.getBrightness(LightLayer.SKY, pos); writeLight(x - xShift, y - yShift, z - zShift, block, sky); }); @@ -173,6 +172,10 @@ public class LightVolume implements ImmutableBox, LightListener { lightData = null; } + protected void markDirty() { + // noop + } + protected void writeLight(int x, int y, int z, int block, int sky) { byte b = (byte) ((block & 0xF) << 4); byte s = (byte) ((sky & 0xF) << 4); @@ -211,8 +214,8 @@ public class LightVolume implements ImmutableBox, LightListener { } @Override - public ListenerStatus status() { - return ListenerStatus.OKAY; + public boolean isListenerInvalid() { + return lightData == null; } } diff --git a/src/main/java/com/jozufozu/flywheel/light/ListenerStatus.java b/src/main/java/com/jozufozu/flywheel/light/ListenerStatus.java deleted file mode 100644 index e8ca36d30..000000000 --- a/src/main/java/com/jozufozu/flywheel/light/ListenerStatus.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.jozufozu.flywheel.light; - -public enum ListenerStatus { - OKAY, - REMOVE, - UPDATE, - ; - - public boolean isOk() { - return this == OKAY; - } - - public boolean shouldRemove() { - return this == REMOVE; - } -} diff --git a/src/main/java/com/jozufozu/flywheel/light/MovingListener.java b/src/main/java/com/jozufozu/flywheel/light/MovingListener.java deleted file mode 100644 index 388d6fdd7..000000000 --- a/src/main/java/com/jozufozu/flywheel/light/MovingListener.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.jozufozu.flywheel.light; - -public interface MovingListener extends LightListener { - boolean update(LightProvider provider); -} diff --git a/src/main/java/com/jozufozu/flywheel/light/TickingLightListener.java b/src/main/java/com/jozufozu/flywheel/light/TickingLightListener.java new file mode 100644 index 000000000..cd3d00b7a --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/light/TickingLightListener.java @@ -0,0 +1,9 @@ +package com.jozufozu.flywheel.light; + +public interface TickingLightListener extends LightListener { + /** + * Called every tick for active listeners. + * @return {@code true} if the listener changed. + */ + boolean tickLightListener(); +} diff --git a/src/main/java/com/jozufozu/flywheel/light/package-info.java b/src/main/java/com/jozufozu/flywheel/light/package-info.java new file mode 100644 index 000000000..da21c0a32 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/light/package-info.java @@ -0,0 +1,7 @@ + +@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault +package com.jozufozu.flywheel.light; + +import javax.annotation.ParametersAreNonnullByDefault; + +import net.minecraft.MethodsReturnNonnullByDefault; diff --git a/src/main/java/com/jozufozu/flywheel/mixin/FrustumMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/FrustumMixin.java index f42f4b86f..2da2c0e8e 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/FrustumMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/FrustumMixin.java @@ -5,7 +5,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.jozufozu.flywheel.backend.OptifineHandler; +import com.jozufozu.flywheel.backend.ShadersModHandler; import com.jozufozu.flywheel.backend.gl.GlStateTracker; import com.jozufozu.flywheel.core.LastActiveCamera; import com.jozufozu.flywheel.event.BeginFrameEvent; @@ -19,7 +19,7 @@ public class FrustumMixin { @Inject(method = "prepare", at = @At("TAIL")) private void onPrepare(double x, double y, double z, CallbackInfo ci) { - if (OptifineHandler.isShadowPass()) { + if (ShadersModHandler.isRenderingShadowPass()) { try (var restoreState = GlStateTracker.getRestoreState()) { MinecraftForge.EVENT_BUS.post(new BeginFrameEvent(Minecraft.getInstance().level, LastActiveCamera.getActiveCamera(), (Frustum) (Object) this)); } diff --git a/src/main/java/com/jozufozu/flywheel/util/WorldAttached.java b/src/main/java/com/jozufozu/flywheel/util/WorldAttached.java index 64985d178..cb41e9fd1 100644 --- a/src/main/java/com/jozufozu/flywheel/util/WorldAttached.java +++ b/src/main/java/com/jozufozu/flywheel/util/WorldAttached.java @@ -3,7 +3,6 @@ package com.jozufozu.flywheel.util; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.function.BiConsumer; @@ -28,7 +27,7 @@ public class WorldAttached { } public static void invalidateWorld(LevelAccessor world) { - Iterator>> i = allMaps.iterator(); + var i = allMaps.iterator(); while (i.hasNext()) { Map map = i.next() .get(); diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/effect/ExampleEffect.java b/src/main/java/com/jozufozu/flywheel/vanilla/effect/ExampleEffect.java index 5ec62b48e..cfbe63506 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/effect/ExampleEffect.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/effect/ExampleEffect.java @@ -15,7 +15,6 @@ import com.jozufozu.flywheel.core.Models; import com.jozufozu.flywheel.core.structs.StructTypes; import com.jozufozu.flywheel.core.structs.model.TransformedPart; import com.jozufozu.flywheel.event.ReloadRenderersEvent; -import com.jozufozu.flywheel.repack.joml.Vector3f; import com.jozufozu.flywheel.util.AnimationTickHolder; import com.jozufozu.flywheel.util.box.GridAlignedBB; import com.jozufozu.flywheel.util.box.ImmutableBox; @@ -28,6 +27,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; +import repack.joml.Vector3f; // http://www.kfish.org/boids/pseudocode.html public class ExampleEffect implements Effect { diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index a9f736a89..1ca2ff67b 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -5,10 +5,12 @@ license = "MIT" [[mods]] modId = "flywheel" +# The Implementation-Version property in the jar's MANIFEST.MF file will be used as the mod version at runtime version = "${file.jarVersion}" displayName = "Flywheel" logoFile = "logo.png" displayURL = "https://www.curseforge.com/minecraft/mc-mods/flywheel" +updateJSONURL = "https://api.modrinth.com/updates/5lpsZoRi/forge_updates.json" authors = "Jozufozu" description = ''' A modern engine for modded minecraft.''' diff --git a/src/main/resources/logo.png b/src/main/resources/logo.png index e660fbc83..1a02d5f3f 100644 Binary files a/src/main/resources/logo.png and b/src/main/resources/logo.png differ