diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 7976bab4b..281b66462 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -59,6 +59,8 @@ body: label: Mod Version description: The version of the mod you were using when the bug occured options: + - "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 909a37211..2345c1932 100644 --- a/build.gradle +++ b/build.gradle @@ -7,11 +7,10 @@ plugins { 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-fabric' +archivesBaseName = "flywheel-fabric-${artifact_minecraft_version}" +version = mod_version + (dev && buildNumber != null ? "-${buildNumber}" : '') sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 @@ -41,6 +40,13 @@ repositories { maven { url 'https://maven.vram.io' } + maven { + name = "Modrinth" + url = "https://api.modrinth.com/maven" + content { + includeGroup "maven.modrinth" + } + } } dependencies { @@ -57,12 +63,12 @@ dependencies { modCompileOnly 'curse.maven:starlight-521783:3667443' - modCompileOnly 'maven.modrinth:iris:1.18.x-v1.2.2' + modCompileOnly 'maven.modrinth:iris:1.18.x-v1.2.5' modCompileOnly 'maven.modrinth:sodium:mc1.18.2-0.4.1' implementation 'com.google.code.findbugs:jsr305:3.0.2' - modCompileOnly 'maven.modrinth:indium:1.0.2+mc1.18.2' - modCompileOnly 'io.vram:frex-fabric-mc118:6.0.242' + modCompileOnly 'maven.modrinth:indium:1.0.6+mc1.18.2' + modCompileOnly 'io.vram:frex-fabric-mc118:6.0.263' } processResources { @@ -76,35 +82,7 @@ processResources { tasks.withType(JavaCompile).configureEach { // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. it.options.release = 17 -} - -java { - // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task - // if it is present. - // If you remove this line, sources will not be generated. - withSourcesJar() -} - -jar { - from('LICENSE') { - rename { "${it}_${archivesBaseName}" } - } -} - -// 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") - ]) - } + options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation } javadoc { @@ -113,24 +91,40 @@ javadoc { options.addStringOption('Xdoclint:none', '-quiet') } -task javadocJar(type: Jar, dependsOn: javadoc) { - from javadoc.destinationDir - archiveClassifier.set('javadoc') +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' + ]) + } } -artifacts { - archives remapJar, sourcesJar, javadocJar +java { + withSourcesJar() + withJavadocJar() } +void addLicense(jarTask) { + jarTask.from('LICENSE.md') { + rename '(.*)\\.(.*)', '$1_' + archivesBaseName + '.$2' + } +} + +addLicense(jar) + publishing { - tasks.publish.dependsOn 'build' publications { mavenJava(MavenPublication) { - artifact remapJar - artifact(sourcesJar) { - builtBy remapSourcesJar - } - artifact javadocJar + artifactId = archivesBaseName + + from components.java } } 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 f1b2b5752..4ade0fa1f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,16 +2,17 @@ org.gradle.jvmargs = -Xmx3G org.gradle.daemon = false # mod version info -mod_version = 0.6.3 -mc_update_version = 1.18 +mod_version = 0.6.4 +artifact_minecraft_version = 1.18.2 + minecraft_version = 1.18.2 -loader_version = 0.13.3 -fabric_version = 0.48.0+1.18.2 +loader_version = 0.14.8 +fabric_version = 0.56.1+1.18.2 # build dependency versions -loom_version = 0.10-SNAPSHOT +loom_version = 0.12-SNAPSHOT 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 242615805..db60ee2c6 100644 --- a/src/main/java/com/jozufozu/flywheel/Flywheel.java +++ b/src/main/java/com/jozufozu/flywheel/Flywheel.java @@ -5,6 +5,7 @@ import org.slf4j.Logger; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.Loader; import com.jozufozu.flywheel.backend.RenderWork; +import com.jozufozu.flywheel.backend.ShadersModHandler; import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; import com.jozufozu.flywheel.config.FlwConfig; import com.jozufozu.flywheel.core.Contexts; @@ -51,6 +52,7 @@ public class Flywheel implements ClientModInitializer { FlwConfig.init(); + ShadersModHandler.init(); Backend.init(); FlywheelEvents.RELOAD_RENDERERS.register(ProgramCompiler::invalidateAll); diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/backend/Backend.java index 535933144..977ac0162 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/Backend.java +++ b/src/main/java/com/jozufozu/flywheel/backend/Backend.java @@ -7,8 +7,8 @@ import org.slf4j.Logger; import com.jozufozu.flywheel.api.FlywheelWorld; import com.jozufozu.flywheel.backend.gl.versioned.GlCompat; import com.jozufozu.flywheel.backend.instancing.ParallelTaskEngine; -import com.jozufozu.flywheel.config.FlwConfig; import com.jozufozu.flywheel.config.BackendType; +import com.jozufozu.flywheel.config.FlwConfig; import com.jozufozu.flywheel.core.shader.ProgramSpec; import com.mojang.logging.LogUtils; @@ -96,7 +96,7 @@ public class Backend { BackendType preferredChoice = FlwConfig.get() .getBackendType(); - boolean usingShaders = IrisShaderHandler.isShaderPackInUse(); + boolean usingShaders = ShadersModHandler.isShaderPackInUse(); boolean canUseEngine = switch (preferredChoice) { case OFF -> true; case BATCHING -> !usingShaders; diff --git a/src/main/java/com/jozufozu/flywheel/backend/IrisShaderHandler.java b/src/main/java/com/jozufozu/flywheel/backend/IrisShaderHandler.java deleted file mode 100644 index 2ac8a70a9..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/IrisShaderHandler.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.jozufozu.flywheel.backend; - -import net.fabricmc.loader.api.FabricLoader; -import net.irisshaders.iris.api.v0.IrisApi; - -public class IrisShaderHandler { - public static final boolean IRIS_LOADED = FabricLoader.getInstance().isModLoaded("iris"); - - private static final InternalHandler HANDLER; - - static { - if (IRIS_LOADED) { - HANDLER = new InternalHandlerImpl(); - } else { - HANDLER = new InternalHandler() {}; - } - } - - private IrisShaderHandler() { - } - - public static boolean isShaderPackInUse() { - return HANDLER.isShaderPackInUse(); - } - - public static boolean isRenderingShadowPass() { - return HANDLER.isRenderingShadowPass(); - } - - private interface InternalHandler { - default boolean isShaderPackInUse() { - return false; - }; - - default boolean isRenderingShadowPass() { - return false; - }; - } - - private static class InternalHandlerImpl implements InternalHandler { - @Override - public boolean isShaderPackInUse() { - return IrisApi.getInstance().isShaderPackInUse(); - }; - - @Override - public boolean isRenderingShadowPass() { - return IrisApi.getInstance().isRenderingShadowPass(); - }; - } -} diff --git a/src/main/java/com/jozufozu/flywheel/backend/Loader.java b/src/main/java/com/jozufozu/flywheel/backend/Loader.java index 805fe13b5..2ede985cb 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/Loader.java +++ b/src/main/java/com/jozufozu/flywheel/backend/Loader.java @@ -93,10 +93,8 @@ public class Loader { Collection programSpecs = manager.listResources(PROGRAM_DIR, s -> s.endsWith(".json")); for (ResourceLocation location : programSpecs) { - try { - Resource file = manager.getResource(location); - - String s = StringUtil.readToString(file.getInputStream()); + try (Resource resource = manager.getResource(location)) { + String s = StringUtil.readToString(resource.getInputStream()); ResourceLocation specName = ResourceUtil.trim(location, PROGRAM_DIR, ".json"); 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..3f7848370 --- /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.fabricmc.loader.api.FabricLoader; +import net.irisshaders.iris.api.v0.IrisApi; +import net.minecraft.client.Camera; +import net.minecraft.client.renderer.culling.Frustum; + +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 isIrisLoaded; + private static final boolean isOptifineInstalled; + private static final InternalHandler internalHandler; + + static { + Package optifinePackage = Package.getPackage(OPTIFINE_ROOT_PACKAGE); + isOptifineInstalled = optifinePackage != null; + isIrisLoaded = FabricLoader.getInstance() + .isModLoaded("iris"); + + // optfine and oculus are assumed to be mutually exclusive + + if (isOptifineInstalled) { + Backend.LOGGER.info("Optifine detected."); + internalHandler = new Optifine(); + } else if (isIrisLoaded) { + Backend.LOGGER.info("Iris detected."); + internalHandler = new Iris(); + } 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 isIrisLoaded() { + return isIrisLoaded; + } + + 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 Iris 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 6a3e67ba8..deb007634 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.materials.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 MaterialManager materialManager; public final Level world; + protected boolean removed = false; public AbstractInstance(MaterialManager materialManager, Level world) { this.materialManager = materialManager; @@ -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/InstanceManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java index 7f741cd8c..1f8310d1e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java @@ -260,7 +260,7 @@ public abstract class InstanceManager implements InstancingEngine.OriginShift } public void invalidate() { - instances.values().forEach(AbstractInstance::remove); + instances.values().forEach(AbstractInstance::removeAndMark); instances.clear(); dynamicInstances.clear(); tickableInstances.clear(); @@ -314,7 +314,7 @@ public abstract class InstanceManager implements InstancingEngine.OriginShift } protected void removeInternal(T obj, AbstractInstance instance) { - instance.remove(); + instance.removeAndMark(); instances.remove(obj); dynamicInstances.remove(obj); tickableInstances.remove(obj); 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 index c44826cc5..37787e7c6 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterialGroup.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterialGroup.java @@ -7,7 +7,7 @@ import com.jozufozu.flywheel.api.InstanceData; import com.jozufozu.flywheel.api.MaterialGroup; import com.jozufozu.flywheel.api.struct.Batched; import com.jozufozu.flywheel.api.struct.StructType; -import com.jozufozu.flywheel.backend.IrisShaderHandler; +import com.jozufozu.flywheel.backend.ShadersModHandler; import com.jozufozu.flywheel.backend.instancing.BatchDrawingTracker; import com.jozufozu.flywheel.backend.instancing.TaskEngine; import com.jozufozu.flywheel.backend.model.DirectVertexConsumer; @@ -56,7 +56,7 @@ public class BatchedMaterialGroup implements MaterialGroup { for (BatchedMaterial material : materials.values()) { for (CPUInstancer instancer : material.models.values()) { - instancer.sbb.context.outputColorDiffuse = !consumer.hasOverlay() && !IrisShaderHandler.isShaderPackInUse(); + instancer.sbb.context.outputColorDiffuse = !consumer.hasOverlay() && !ShadersModHandler.isShaderPackInUse(); instancer.submitTasks(stack, pool, consumer); } } 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 02e03435c..d7025fe57 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 0b3b76405..8fd568212 100644 --- a/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java +++ b/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java @@ -12,7 +12,6 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource; -import net.fabricmc.loader.api.FabricLoader; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; @@ -104,17 +103,7 @@ public final 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 (FabricLoader.getInstance() - .isModLoaded("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/model/BakedModelBuilder.java b/src/main/java/com/jozufozu/flywheel/core/model/BakedModelBuilder.java new file mode 100644 index 000000000..b8956b462 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/core/model/BakedModelBuilder.java @@ -0,0 +1,47 @@ + +package com.jozufozu.flywheel.core.model; + +import java.util.Random; + +import com.jozufozu.flywheel.core.virtual.VirtualEmptyBlockGetter; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; + +import net.minecraft.client.renderer.block.ModelBlockRenderer; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; + +public final class BakedModelBuilder implements Bufferable { + private final BakedModel model; + private BlockAndTintGetter renderWorld = VirtualEmptyBlockGetter.INSTANCE; + private BlockState referenceState = Blocks.AIR.defaultBlockState(); + private PoseStack poseStack = new PoseStack(); + + public BakedModelBuilder(BakedModel model) { + this.model = model; + } + + public BakedModelBuilder withRenderWorld(BlockAndTintGetter renderWorld) { + this.renderWorld = renderWorld; + return this; + } + + public BakedModelBuilder withReferenceState(BlockState referenceState) { + this.referenceState = referenceState; + return this; + } + + public BakedModelBuilder withPoseStack(PoseStack poseStack) { + this.poseStack = poseStack; + return this; + } + + @Override + public void bufferInto(ModelBlockRenderer blockRenderer, VertexConsumer consumer, Random random) { + blockRenderer.tesselateBlock(renderWorld, model, referenceState, BlockPos.ZERO, poseStack, consumer, false, random, 42, OverlayTexture.NO_OVERLAY); + } +} diff --git a/src/main/java/com/jozufozu/flywheel/core/model/Bufferable.java b/src/main/java/com/jozufozu/flywheel/core/model/Bufferable.java new file mode 100644 index 000000000..ee78333ad --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/core/model/Bufferable.java @@ -0,0 +1,19 @@ + +package com.jozufozu.flywheel.core.model; + +import java.util.Random; + +import com.mojang.blaze3d.vertex.VertexConsumer; + +import net.minecraft.client.renderer.block.ModelBlockRenderer; + +/** + * An interface for objects that can "rendered" into a BufferBuilder. + */ +public interface Bufferable { + void bufferInto(ModelBlockRenderer renderer, VertexConsumer consumer, Random random); + + default ShadeSeparatedBufferBuilder build() { + return ModelUtil.getBufferBuilder(this); + } +} diff --git a/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java b/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java index 34c2e05e1..550671b30 100644 --- a/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java +++ b/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java @@ -4,114 +4,61 @@ import java.util.Collection; import java.util.Random; import java.util.function.Supplier; -import com.jozufozu.flywheel.core.virtual.VirtualEmptyBlockGetter; -import com.jozufozu.flywheel.fabric.model.CullingBakedModel; -import com.jozufozu.flywheel.fabric.model.DefaultLayerFilteringBakedModel; -import com.jozufozu.flywheel.fabric.model.FabricModelUtil; -import com.jozufozu.flywheel.fabric.model.LayerFilteringBakedModel; import com.jozufozu.flywheel.util.transform.TransformStack; import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexFormat; -import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.block.BlockRenderDispatcher; import net.minecraft.client.renderer.block.ModelBlockRenderer; -import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; public class ModelUtil { - private static final ThreadLocal THREAD_LOCAL_OBJECTS = ThreadLocal.withInitial(ThreadLocalObjects::new); - public static ShadeSeparatedBufferBuilder getBufferBuilder(BakedModel model, BlockState referenceState, PoseStack poseStack) { - return getBufferBuilder(VirtualEmptyBlockGetter.INSTANCE, model, referenceState, poseStack); - } - - public static ShadeSeparatedBufferBuilder getBufferBuilder(BlockAndTintGetter renderWorld, BakedModel model, BlockState referenceState, PoseStack poseStack) { + public static ShadeSeparatedBufferBuilder getBufferBuilder(Bufferable bufferable) { ModelBlockRenderer blockRenderer = Minecraft.getInstance().getBlockRenderer().getModelRenderer(); ThreadLocalObjects objects = THREAD_LOCAL_OBJECTS.get(); - ShadeSeparatingVertexConsumer shadeSeparatingWrapper = objects.shadeSeparatingWrapper; - ShadeSeparatedBufferBuilder builder = new ShadeSeparatedBufferBuilder(512); - BufferBuilder unshadedBuilder = objects.unshadedBuilder; + objects.begin(); - builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); - unshadedBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); - shadeSeparatingWrapper.prepare(builder, unshadedBuilder); - model = DefaultLayerFilteringBakedModel.wrap(model); - model = shadeSeparatingWrapper.wrapModel(model); - blockRenderer.tesselateBlock(renderWorld, model, referenceState, BlockPos.ZERO, poseStack, shadeSeparatingWrapper, - false, objects.random, 42, OverlayTexture.NO_OVERLAY); - shadeSeparatingWrapper.clear(); - unshadedBuilder.end(); - builder.appendUnshadedVertices(unshadedBuilder); - builder.end(); + bufferable.bufferInto(blockRenderer, objects.shadeSeparatingWrapper, objects.random); - return builder; + objects.end(); + + return objects.separatedBufferBuilder; + } + + public static ShadeSeparatedBufferBuilder getBufferBuilder(BakedModel model, BlockState referenceState, PoseStack poseStack) { + return new BakedModelBuilder(model).withReferenceState(referenceState) + .withPoseStack(poseStack) + .build(); + } + + public static ShadeSeparatedBufferBuilder getBufferBuilder(BlockAndTintGetter renderWorld, BakedModel model, BlockState referenceState, PoseStack poseStack) { + return new BakedModelBuilder(model).withReferenceState(referenceState) + .withPoseStack(poseStack) + .withRenderWorld(renderWorld) + .build(); } public static ShadeSeparatedBufferBuilder getBufferBuilderFromTemplate(BlockAndTintGetter renderWorld, RenderType layer, Collection blocks) { - return getBufferBuilderFromTemplate(renderWorld, layer, blocks, new PoseStack()); + return new WorldModelBuilder(layer).withRenderWorld(renderWorld) + .withBlocks(blocks) + .build(); } public static ShadeSeparatedBufferBuilder getBufferBuilderFromTemplate(BlockAndTintGetter renderWorld, RenderType layer, Collection blocks, PoseStack poseStack) { - BlockRenderDispatcher dispatcher = Minecraft.getInstance().getBlockRenderer(); - ModelBlockRenderer modelRenderer = dispatcher.getModelRenderer(); - ThreadLocalObjects objects = THREAD_LOCAL_OBJECTS.get(); - - Random random = objects.random; - ShadeSeparatingVertexConsumer shadeSeparatingWrapper = objects.shadeSeparatingWrapper; - ShadeSeparatedBufferBuilder builder = new ShadeSeparatedBufferBuilder(512); - BufferBuilder unshadedBuilder = objects.unshadedBuilder; - - builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); - unshadedBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); - shadeSeparatingWrapper.prepare(builder, unshadedBuilder); - - ModelBlockRenderer.enableCaching(); - for (StructureTemplate.StructureBlockInfo info : blocks) { - BlockState state = info.state; - - if (state.getRenderShape() != RenderShape.MODEL) - continue; - - BakedModel model = dispatcher.getBlockModel(state); - if (((FabricBakedModel) model).isVanillaAdapter()) { - if (!FabricModelUtil.doesLayerMatch(state, layer)) { - continue; - } - } else { - model = CullingBakedModel.wrap(model); - model = LayerFilteringBakedModel.wrap(model, layer); - model = shadeSeparatingWrapper.wrapModel(model); - } - - BlockPos pos = info.pos; - - poseStack.pushPose(); - poseStack.translate(pos.getX(), pos.getY(), pos.getZ()); - modelRenderer.tesselateBlock(renderWorld, model, state, pos, poseStack, shadeSeparatingWrapper, - true, random, 42, OverlayTexture.NO_OVERLAY); - poseStack.popPose(); - } - ModelBlockRenderer.clearCache(); - - shadeSeparatingWrapper.clear(); - unshadedBuilder.end(); - builder.appendUnshadedVertices(unshadedBuilder); - builder.end(); - - return builder; + return new WorldModelBuilder(layer).withRenderWorld(renderWorld) + .withBlocks(blocks) + .withPoseStack(poseStack) + .build(); } public static Supplier rotateToFace(Direction facing) { @@ -128,6 +75,20 @@ public class ModelUtil { private static class ThreadLocalObjects { public final Random random = new Random(); public final ShadeSeparatingVertexConsumer shadeSeparatingWrapper = new ShadeSeparatingVertexConsumer(); + public final ShadeSeparatedBufferBuilder separatedBufferBuilder = new ShadeSeparatedBufferBuilder(512); public final BufferBuilder unshadedBuilder = new BufferBuilder(512); + + private void begin() { + this.separatedBufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); + this.unshadedBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); + this.shadeSeparatingWrapper.prepare(this.separatedBufferBuilder, this.unshadedBuilder); + } + + private void end() { + this.shadeSeparatingWrapper.clear(); + this.unshadedBuilder.end(); + this.separatedBufferBuilder.appendUnshadedVertices(this.unshadedBuilder); + this.separatedBufferBuilder.end(); + } } } diff --git a/src/main/java/com/jozufozu/flywheel/core/model/WorldModel.java b/src/main/java/com/jozufozu/flywheel/core/model/WorldModel.java index c350361c9..c144f43c6 100644 --- a/src/main/java/com/jozufozu/flywheel/core/model/WorldModel.java +++ b/src/main/java/com/jozufozu/flywheel/core/model/WorldModel.java @@ -1,25 +1,17 @@ package com.jozufozu.flywheel.core.model; -import java.util.Collection; - import com.jozufozu.flywheel.api.vertex.VertexList; import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.core.Formats; - -import net.minecraft.client.renderer.RenderType; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; +import com.mojang.blaze3d.vertex.BufferBuilder; public class WorldModel implements Model { private final VertexList reader; private final String name; - /** - * It is expected that {@code renderWorld.getShade(...)} returns a constant. - */ - public WorldModel(BlockAndTintGetter renderWorld, RenderType layer, Collection blocks, String name) { - reader = Formats.BLOCK.createReader(ModelUtil.getBufferBuilderFromTemplate(renderWorld, layer, blocks)); + public WorldModel(BufferBuilder bufferBuilder, String name) { + this.reader = Formats.BLOCK.createReader(bufferBuilder); this.name = name; } diff --git a/src/main/java/com/jozufozu/flywheel/core/model/WorldModelBuilder.java b/src/main/java/com/jozufozu/flywheel/core/model/WorldModelBuilder.java new file mode 100644 index 000000000..a90462e49 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/core/model/WorldModelBuilder.java @@ -0,0 +1,92 @@ +package com.jozufozu.flywheel.core.model; + +import java.util.Collection; +import java.util.Collections; +import java.util.Random; + +import com.jozufozu.flywheel.core.virtual.VirtualEmptyBlockGetter; +import com.jozufozu.flywheel.fabric.model.CullingBakedModel; +import com.jozufozu.flywheel.fabric.model.FabricModelUtil; +import com.jozufozu.flywheel.fabric.model.LayerFilteringBakedModel; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; + +import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.block.BlockRenderDispatcher; +import net.minecraft.client.renderer.block.ModelBlockRenderer; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.block.RenderShape; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; + +public final class WorldModelBuilder implements Bufferable { + private final RenderType layer; + + private PoseStack poseStack = new PoseStack(); + private BlockAndTintGetter renderWorld = VirtualEmptyBlockGetter.INSTANCE; + private Collection blocks = Collections.emptyList(); + + public WorldModelBuilder(RenderType layer) { + this.layer = layer; + } + + @Override + public void bufferInto(ModelBlockRenderer modelRenderer, VertexConsumer consumer, Random random) { + BlockRenderDispatcher dispatcher = Minecraft.getInstance().getBlockRenderer(); + + ModelBlockRenderer.enableCaching(); + for (StructureTemplate.StructureBlockInfo info : this.blocks) { + BlockState state = info.state; + + if (state.getRenderShape() != RenderShape.MODEL) continue; + + BakedModel model = dispatcher.getBlockModel(state); + if (((FabricBakedModel) model).isVanillaAdapter()) { + if (!FabricModelUtil.doesLayerMatch(state, layer)) { + continue; + } + } else { + model = CullingBakedModel.wrap(model); + model = LayerFilteringBakedModel.wrap(model, layer); + if (consumer instanceof ShadeSeparatingVertexConsumer shadeSeparatingWrapper) { + model = shadeSeparatingWrapper.wrapModel(model); + } + } + + BlockPos pos = info.pos; + + poseStack.pushPose(); + poseStack.translate(pos.getX(), pos.getY(), pos.getZ()); + modelRenderer.tesselateBlock(this.renderWorld, model, state, pos, poseStack, consumer, true, random, 42, OverlayTexture.NO_OVERLAY); + poseStack.popPose(); + } + ModelBlockRenderer.clearCache(); + } + + /** + * It is expected that {@code renderWorld.getShade(...)} returns a constant. + */ + public WorldModelBuilder withRenderWorld(BlockAndTintGetter renderWorld) { + this.renderWorld = renderWorld; + return this; + } + + public WorldModelBuilder withBlocks(Collection blocks) { + this.blocks = blocks; + return this; + } + + public WorldModelBuilder withPoseStack(PoseStack poseStack) { + this.poseStack = poseStack; + return this; + } + + public WorldModel intoMesh(String name) { + return new WorldModel(ModelUtil.getBufferBuilder(this), name); + } +} diff --git a/src/main/java/com/jozufozu/flywheel/core/source/ShaderSources.java b/src/main/java/com/jozufozu/flywheel/core/source/ShaderSources.java index b7e29c2a4..c4b42ec10 100644 --- a/src/main/java/com/jozufozu/flywheel/core/source/ShaderSources.java +++ b/src/main/java/com/jozufozu/flywheel/core/source/ShaderSources.java @@ -36,16 +36,14 @@ public class ShaderSources implements SourceFinder { }); for (ResourceLocation location : allShaders) { - try { - Resource resource = manager.getResource(location); - + try (Resource resource = manager.getResource(location)) { String source = StringUtil.readToString(resource.getInputStream()); ResourceLocation name = ResourceUtil.removePrefixUnchecked(location, SHADER_DIR); shaderSources.put(name, new SourceFile(this, name, source)); } catch (IOException e) { - + // } } 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 57e0d0c25..2955b5dc2 100644 --- a/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexList.java +++ b/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexList.java @@ -1,32 +1,19 @@ 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.core.model.ShadeSeparatedBufferBuilder; import com.jozufozu.flywheel.fabric.helper.BufferBuilderHelper; 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(); - BufferBuilderHelper.fixByteOrder(builder, buffer); - - stride = BufferBuilderHelper.getVertexFormat(builder) + super(builder); + this.stride = BufferBuilderHelper.getVertexFormat(builder) .getVertexSize(); - - vertexCount = data.getFirst() - .vertexCount(); - } @Override @@ -40,72 +27,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)); } public static class Shaded extends BlockVertexList implements ShadedVertexList { 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 0993f29e5..07dbdeb4d 100644 --- a/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexListUnsafe.java +++ b/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexListUnsafe.java @@ -5,19 +5,12 @@ import java.nio.ByteBuffer; import org.lwjgl.system.MemoryUtil; import com.jozufozu.flywheel.api.vertex.ShadedVertexList; -import com.jozufozu.flywheel.api.vertex.VertexList; import com.jozufozu.flywheel.util.RenderMath; -public class BlockVertexListUnsafe implements VertexList { +public class BlockVertexListUnsafe extends AbstractVertexList { - private final ByteBuffer buffer; - private final int vertexCount; - private final long base; - - public BlockVertexListUnsafe(ByteBuffer buffer, int vertexCount) { - this.buffer = buffer; - this.base = MemoryUtil.memAddress(buffer); - this.vertexCount = vertexCount; + public BlockVertexListUnsafe(ByteBuffer copyFrom, int vertexCount) { + super(copyFrom, vertexCount); } private long ptr(long index) { @@ -94,11 +87,6 @@ public class BlockVertexListUnsafe implements VertexList { return RenderMath.f(MemoryUtil.memGetByte(ptr(index) + 30)); } - @Override - public int getVertexCount() { - return vertexCount; - } - public static class Shaded extends BlockVertexListUnsafe implements ShadedVertexList { private final int unshadedStartVertex; 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 70d4a72ee..6b5a99305 100644 --- a/src/main/java/com/jozufozu/flywheel/core/vertex/PosTexNormalVertexListUnsafe.java +++ b/src/main/java/com/jozufozu/flywheel/core/vertex/PosTexNormalVertexListUnsafe.java @@ -4,19 +4,12 @@ import java.nio.ByteBuffer; import org.lwjgl.system.MemoryUtil; -import com.jozufozu.flywheel.api.vertex.VertexList; import com.jozufozu.flywheel.util.RenderMath; -public class PosTexNormalVertexListUnsafe implements VertexList { +public class PosTexNormalVertexListUnsafe extends AbstractVertexList { - private final ByteBuffer buffer; - private final int vertexCount; - private final long base; - - public PosTexNormalVertexListUnsafe(ByteBuffer buffer, int vertexCount) { - this.buffer = buffer; - this.vertexCount = vertexCount; - this.base = MemoryUtil.memAddress(buffer); + public PosTexNormalVertexListUnsafe(ByteBuffer copyFrom, int vertexCount) { + super(copyFrom, vertexCount); } private long ptr(long idx) { @@ -87,9 +80,4 @@ public class PosTexNormalVertexListUnsafe implements VertexList { public float getNZ(int index) { return RenderMath.f(MemoryUtil.memGetByte(ptr(index) + 22)); } - - @Override - public int getVertexCount() { - return vertexCount; - } } diff --git a/src/main/java/com/jozufozu/flywheel/fabric/model/DefaultLayerFilteringBakedModel.java b/src/main/java/com/jozufozu/flywheel/fabric/model/DefaultLayerFilteringBakedModel.java index 5626fe5ae..5816bb5ad 100644 --- a/src/main/java/com/jozufozu/flywheel/fabric/model/DefaultLayerFilteringBakedModel.java +++ b/src/main/java/com/jozufozu/flywheel/fabric/model/DefaultLayerFilteringBakedModel.java @@ -44,6 +44,6 @@ public class DefaultLayerFilteringBakedModel extends ForwardingBakedModel { } public static boolean hasDefaultBlendMode(QuadView quad) { - return FabricModelUtil.getBlendMode(quad.material()) == BlendMode.DEFAULT; + return FabricModelUtil.getBlendMode(quad) == BlendMode.DEFAULT; } } diff --git a/src/main/java/com/jozufozu/flywheel/fabric/model/FabricModelUtil.java b/src/main/java/com/jozufozu/flywheel/fabric/model/FabricModelUtil.java index 5f490517c..b81ac7569 100644 --- a/src/main/java/com/jozufozu/flywheel/fabric/model/FabricModelUtil.java +++ b/src/main/java/com/jozufozu/flywheel/fabric/model/FabricModelUtil.java @@ -5,11 +5,11 @@ import java.lang.reflect.Field; import com.jozufozu.flywheel.Flywheel; import io.vram.frex.api.material.MaterialConstants; -import io.vram.frex.fabric.compat.FabricMaterial; import io.vram.frex.fabric.compat.FabricQuadView; +import net.fabricmc.fabric.api.renderer.v1.RendererAccess; import net.fabricmc.fabric.api.renderer.v1.material.BlendMode; -import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; import net.fabricmc.fabric.api.renderer.v1.mesh.QuadView; +import net.fabricmc.fabric.impl.client.indigo.renderer.IndigoRenderer; import net.fabricmc.fabric.impl.client.indigo.renderer.RenderMaterialImpl; import net.fabricmc.fabric.impl.client.indigo.renderer.mesh.QuadViewImpl; import net.fabricmc.loader.api.FabricLoader; @@ -25,43 +25,44 @@ public class FabricModelUtil { private static final ShadedPredicate SHADED_PREDICATE = createShadedPredicate(); private static BlendModeGetter createBlendModeGetter() { - if (FREX_LOADED) { + if (FabricLoader.getInstance().isModLoaded("frex")) { try { - Field frexMaterialField = FabricMaterial.class.getDeclaredField("wrapped"); - frexMaterialField.setAccessible(true); - return material -> { + Field frexQuadField = FabricQuadView.class.getDeclaredField("wrapped"); + frexQuadField.setAccessible(true); + return quad -> { try { - io.vram.frex.api.material.RenderMaterial frexMaterial = (io.vram.frex.api.material.RenderMaterial) frexMaterialField.get(material); + io.vram.frex.api.material.RenderMaterial frexMaterial = ((io.vram.frex.api.mesh.QuadView) frexQuadField.get(quad)).material(); return switch (frexMaterial.preset()) { - case MaterialConstants.PRESET_DEFAULT -> BlendMode.DEFAULT; - case MaterialConstants.PRESET_SOLID -> BlendMode.SOLID; - case MaterialConstants.PRESET_CUTOUT_MIPPED -> BlendMode.CUTOUT_MIPPED; - case MaterialConstants.PRESET_CUTOUT -> BlendMode.CUTOUT; - case MaterialConstants.PRESET_TRANSLUCENT -> BlendMode.TRANSLUCENT; - case MaterialConstants.PRESET_NONE -> { - if (frexMaterial.transparency() != MaterialConstants.TRANSPARENCY_NONE) { - yield BlendMode.TRANSLUCENT; - } else if (frexMaterial.cutout() == MaterialConstants.CUTOUT_NONE) { - yield BlendMode.SOLID; - } else { - yield frexMaterial.unmipped() ? BlendMode.CUTOUT : BlendMode.CUTOUT_MIPPED; + case MaterialConstants.PRESET_DEFAULT -> BlendMode.DEFAULT; + case MaterialConstants.PRESET_SOLID -> BlendMode.SOLID; + case MaterialConstants.PRESET_CUTOUT_MIPPED -> BlendMode.CUTOUT_MIPPED; + case MaterialConstants.PRESET_CUTOUT -> BlendMode.CUTOUT; + case MaterialConstants.PRESET_TRANSLUCENT -> BlendMode.TRANSLUCENT; + case MaterialConstants.PRESET_NONE -> { + if (frexMaterial.transparency() != MaterialConstants.TRANSPARENCY_NONE) { + yield BlendMode.TRANSLUCENT; + } else if (frexMaterial.cutout() == MaterialConstants.CUTOUT_NONE) { + yield BlendMode.SOLID; + } else { + yield frexMaterial.unmipped() ? BlendMode.CUTOUT : BlendMode.CUTOUT_MIPPED; + } } - } - default -> BlendMode.DEFAULT; + default -> BlendMode.DEFAULT; }; } catch (Exception e) { + // } return BlendMode.DEFAULT; }; } catch (Exception e) { - Flywheel.LOGGER.error("Detected FREX but failed to load material wrapper field.", e); - return material -> BlendMode.DEFAULT; + Flywheel.LOGGER.error("Detected FREX but failed to load quad wrapper field", e); } - } else if (INDIUM_LOADED) { - return material -> ((link.infra.indium.renderer.RenderMaterialImpl) material).blendMode(0); - } else { - return material -> ((RenderMaterialImpl) material).blendMode(0); + } else if (FabricLoader.getInstance().isModLoaded("indium")) { + return quad -> ((link.infra.indium.renderer.RenderMaterialImpl) quad.material()).blendMode(0); + } else if (RendererAccess.INSTANCE.getRenderer() instanceof IndigoRenderer) { + return quad -> ((RenderMaterialImpl) quad.material()).blendMode(0); } + return quad -> BlendMode.DEFAULT; } private static ShadedPredicate createShadedPredicate() { @@ -74,22 +75,23 @@ public class FabricModelUtil { io.vram.frex.api.mesh.QuadView frexQuadView = (io.vram.frex.api.mesh.QuadView) frexQuadViewField.get(quad); return !frexQuadView.material().disableDiffuse(); } catch (Exception e) { + // } return true; }; } catch (Exception e) { Flywheel.LOGGER.error("Detected FREX but failed to load quad view wrapper field.", e); - return quad -> true; } } else if (INDIUM_LOADED) { return quad -> ((link.infra.indium.renderer.mesh.QuadViewImpl) quad).hasShade(); - } else { + } else if (RendererAccess.INSTANCE.getRenderer() instanceof IndigoRenderer) { return quad -> ((QuadViewImpl) quad).hasShade(); } + return quad -> true; } - public static BlendMode getBlendMode(RenderMaterial material) { - return BLEND_MODE_GETTER.getBlendMode(material); + public static BlendMode getBlendMode(QuadView quad) { + return BLEND_MODE_GETTER.getBlendMode(quad); } public static boolean isShaded(QuadView quad) { @@ -101,7 +103,7 @@ public class FabricModelUtil { } private interface BlendModeGetter { - BlendMode getBlendMode(RenderMaterial material); + BlendMode getBlendMode(QuadView quad); } private interface ShadedPredicate { diff --git a/src/main/java/com/jozufozu/flywheel/fabric/model/LayerFilteringBakedModel.java b/src/main/java/com/jozufozu/flywheel/fabric/model/LayerFilteringBakedModel.java index 16f9e0127..676cdfb1c 100644 --- a/src/main/java/com/jozufozu/flywheel/fabric/model/LayerFilteringBakedModel.java +++ b/src/main/java/com/jozufozu/flywheel/fabric/model/LayerFilteringBakedModel.java @@ -41,7 +41,7 @@ public class LayerFilteringBakedModel extends ForwardingBakedModel { } } else { context.pushTransform(quad -> { - RenderType quadLayer = FabricModelUtil.getBlendMode(quad.material()).blockRenderLayer; + RenderType quadLayer = FabricModelUtil.getBlendMode(quad).blockRenderLayer; if (quadLayer == null) { quadLayer = defaultLayer; } 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/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/LightUpdater.java b/src/main/java/com/jozufozu/flywheel/light/LightUpdater.java index 4958fd682..9cce9fd44 100644 --- a/src/main/java/com/jozufozu/flywheel/light/LightUpdater.java +++ b/src/main/java/com/jozufozu/flywheel/light/LightUpdater.java @@ -39,19 +39,15 @@ public class LightUpdater { } } - 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() { @@ -60,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); } } } @@ -71,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); } }) @@ -86,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(); @@ -130,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); } } @@ -151,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 adb69949e..4ce8967c3 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.IrisShaderHandler; +import com.jozufozu.flywheel.backend.ShadersModHandler; import com.jozufozu.flywheel.core.LastActiveCamera; import com.jozufozu.flywheel.event.BeginFrameEvent; import com.jozufozu.flywheel.fabric.event.FlywheelEvents; @@ -18,7 +18,7 @@ public class FrustumMixin { @Inject(method = "prepare", at = @At("TAIL")) private void onPrepare(double x, double y, double z, CallbackInfo ci) { - if (IrisShaderHandler.isRenderingShadowPass()) { + if (ShadersModHandler.isRenderingShadowPass()) { FlywheelEvents.BEGIN_FRAME.invoker().handleEvent(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 45b989f2f..2573a9a52 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; 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