diff --git a/buildSrc/src/main/kotlin/dev/engine_room/gradle/subproject/SubprojectPlugin.kt b/buildSrc/src/main/kotlin/dev/engine_room/gradle/subproject/SubprojectPlugin.kt index 8eda2f418..8fea37a9c 100644 --- a/buildSrc/src/main/kotlin/dev/engine_room/gradle/subproject/SubprojectPlugin.kt +++ b/buildSrc/src/main/kotlin/dev/engine_room/gradle/subproject/SubprojectPlugin.kt @@ -89,6 +89,9 @@ class SubprojectPlugin: Plugin { includeGroup("maven.modrinth") } } + flatDir { + dirs = setOf(project.rootProject.file("libs")) + } } } diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 23d1f23b4..3f9247a3f 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -72,6 +72,8 @@ jarSets { dependencies { modCompileOnly("net.fabricmc:fabric-loader:${property("fabric_loader_version")}") + modCompileOnly(":sodium-fabric-0.6.0-beta.2+mc1.21.1") + testImplementation("org.junit.jupiter:junit-jupiter:5.8.1") } diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/compat/CompatMods.java b/common/src/main/java/dev/engine_room/flywheel/impl/compat/CompatMods.java new file mode 100644 index 000000000..612316dc3 --- /dev/null +++ b/common/src/main/java/dev/engine_room/flywheel/impl/compat/CompatMods.java @@ -0,0 +1,22 @@ +package dev.engine_room.flywheel.impl.compat; + +import java.util.function.Supplier; + +import com.google.common.base.Suppliers; + +import net.fabricmc.loader.api.FabricLoader; + +public enum CompatMods { + SODIUM, + EMBEDDIUM; + + private final Supplier isLoaded; + + CompatMods() { + isLoaded = Suppliers.memoize(() -> FabricLoader.getInstance().isModLoaded(name())); + } + + public boolean isLoaded() { + return isLoaded.get(); + } +} diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/compat/SodiumCompat.java b/common/src/main/java/dev/engine_room/flywheel/impl/compat/SodiumCompat.java new file mode 100644 index 000000000..7b39a062b --- /dev/null +++ b/common/src/main/java/dev/engine_room/flywheel/impl/compat/SodiumCompat.java @@ -0,0 +1,19 @@ +package dev.engine_room.flywheel.impl.compat; + +import dev.engine_room.flywheel.lib.visualization.VisualizationHelper; +import net.caffeinemc.mods.sodium.api.blockentity.BlockEntityRenderHandler; +import net.caffeinemc.mods.sodium.api.blockentity.BlockEntityRenderPredicate; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; + +public class SodiumCompat { + public static Object forBlockEntityType(BlockEntityType type) { + BlockEntityRenderPredicate predicate = (getter, pos, be) -> VisualizationHelper.tryAddBlockEntity(be); + BlockEntityRenderHandler.instance().addRenderPredicate(type, predicate); + return predicate; + } + + public static void removePredicate(BlockEntityType type, Object predicate) { + BlockEntityRenderHandler.instance().removeRenderPredicate(type, (BlockEntityRenderPredicate) predicate); + } +} diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/BlockEntityTypeMixin.java b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/BlockEntityTypeMixin.java index 93c660d8d..ab9ef91f2 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/BlockEntityTypeMixin.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/BlockEntityTypeMixin.java @@ -5,6 +5,8 @@ import org.spongepowered.asm.mixin.Unique; import dev.engine_room.flywheel.api.visualization.BlockEntityVisualizer; +import dev.engine_room.flywheel.impl.compat.CompatMods; +import dev.engine_room.flywheel.impl.compat.SodiumCompat; import dev.engine_room.flywheel.impl.extension.BlockEntityTypeExtension; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; @@ -12,8 +14,13 @@ @Mixin(BlockEntityType.class) abstract class BlockEntityTypeMixin implements BlockEntityTypeExtension { @Unique + @Nullable private BlockEntityVisualizer flywheel$visualizer; + @Unique + @Nullable + private Object flywheel$sodiumPredicate; + @Override @Nullable public BlockEntityVisualizer flywheel$getVisualizer() { @@ -22,6 +29,13 @@ abstract class BlockEntityTypeMixin implements BlockEntit @Override public void flywheel$setVisualizer(@Nullable BlockEntityVisualizer visualizer) { + if (CompatMods.SODIUM.isLoaded() && !CompatMods.EMBEDDIUM.isLoaded()) { + if (flywheel$visualizer == null && visualizer != null) { + flywheel$sodiumPredicate = SodiumCompat.forBlockEntityType((BlockEntityType) (Object) this); + } else if (flywheel$visualizer != null && visualizer == null && flywheel$sodiumPredicate != null) { + SodiumCompat.removePredicate((BlockEntityType) (Object) this, flywheel$sodiumPredicate); + } + } this.flywheel$visualizer = visualizer; } } diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index 0e6bc0621..3fb91957c 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -72,7 +72,7 @@ dependencies { modImplementation("net.fabricmc:fabric-loader:${property("fabric_loader_version")}") modApi("net.fabricmc.fabric-api:fabric-api:${property("fabric_api_version")}") - modCompileOnly("maven.modrinth:sodium:${property("sodium_version")}-fabric") + modCompileOnly(":sodium-fabric-0.6.0-beta.2+mc1.21.1") modCompileOnly("maven.modrinth:iris:${property("iris_version")}-fabric") "forApi"(project(path = ":common", configuration = "commonApiOnly")) diff --git a/fabric/src/main/java/dev/engine_room/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java b/fabric/src/main/java/dev/engine_room/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java deleted file mode 100644 index 865ba1978..000000000 --- a/fabric/src/main/java/dev/engine_room/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java +++ /dev/null @@ -1,22 +0,0 @@ -package dev.engine_room.flywheel.impl.mixin.sodium; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import dev.engine_room.flywheel.lib.visualization.VisualizationHelper; -import net.caffeinemc.mods.sodium.client.render.chunk.compile.tasks.ChunkBuilderMeshingTask; -import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; -import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; -import net.minecraft.world.level.block.entity.BlockEntity; - -@Mixin(value = ChunkBuilderMeshingTask.class, remap = false) -abstract class ChunkBuilderMeshingTaskMixin { - @Redirect(method = "execute(Lnet/caffeinemc/mods/sodium/client/render/chunk/compile/ChunkBuildContext;Lnet/caffeinemc/mods/sodium/client/util/task/CancellationToken;)Lnet/caffeinemc/mods/sodium/client/render/chunk/compile/ChunkBuildOutput;", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/blockentity/BlockEntityRenderDispatcher;getRenderer(Lnet/minecraft/world/level/block/entity/BlockEntity;)Lnet/minecraft/client/renderer/blockentity/BlockEntityRenderer;", remap = true)) - private BlockEntityRenderer flywheel$redirectGetRenderer(BlockEntityRenderDispatcher dispatcher, BlockEntity blockEntity) { - if (VisualizationHelper.tryAddBlockEntity(blockEntity)) { - return null; - } - return dispatcher.getRenderer(blockEntity); - } -} diff --git a/fabric/src/main/java/dev/engine_room/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java b/fabric/src/main/java/dev/engine_room/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java deleted file mode 100644 index 0eda36012..000000000 --- a/fabric/src/main/java/dev/engine_room/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java +++ /dev/null @@ -1,48 +0,0 @@ -package dev.engine_room.flywheel.impl.mixin.sodium; - -import java.util.List; -import java.util.Set; -import java.util.function.Supplier; - -import org.objectweb.asm.tree.ClassNode; -import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; -import org.spongepowered.asm.mixin.extensibility.IMixinInfo; - -import com.google.common.base.Suppliers; - -import net.fabricmc.loader.api.FabricLoader; - -public class SodiumMixinPlugin implements IMixinConfigPlugin { - private static final Supplier IS_SODIUM_LOADED = Suppliers.memoize(() -> FabricLoader.getInstance().isModLoaded("sodium")); - - @Override - public void onLoad(String mixinPackage) { - } - - @Override - public String getRefMapperConfig() { - return null; - } - - @Override - public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - return IS_SODIUM_LOADED.get(); - } - - @Override - public void acceptTargets(Set myTargets, Set otherTargets) { - } - - @Override - public List getMixins() { - return null; - } - - @Override - public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - } - - @Override - public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - } -} diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 7bfb5a37f..995855618 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -24,7 +24,6 @@ "mixins": [ "flywheel.backend.mixins.json", "flywheel.impl.mixins.json", - "flywheel.impl.sodium.mixins.json", "flywheel.impl.fabric.mixins.json" ], "depends": { @@ -32,6 +31,6 @@ "fabric-api": "${fabric_api_version_range}" }, "breaks": { - "sodium": "<0.5.0" + "sodium": ["<0.6.0-beta.2"] } } diff --git a/fabric/src/main/resources/flywheel.impl.sodium.mixins.json b/fabric/src/main/resources/flywheel.impl.sodium.mixins.json deleted file mode 100644 index 0fd5cf55f..000000000 --- a/fabric/src/main/resources/flywheel.impl.sodium.mixins.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "dev.engine_room.flywheel.impl.mixin.sodium", - "compatibilityLevel": "JAVA_21", - "refmap": "flywheel.refmap.json", - "plugin": "dev.engine_room.flywheel.impl.mixin.sodium.SodiumMixinPlugin", - "client": [ - "ChunkBuilderMeshingTaskMixin" - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index 3ee25ef3c..2bdcad863 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -67,12 +67,6 @@ loom { add(backend, "backend-flywheel.refmap.json") } - forge { - mixinConfig("flywheel.backend.mixins.json") - mixinConfig("flywheel.impl.mixins.json") - mixinConfig("flywheel.impl.sodium.mixins.json") - } - runs { configureEach { property("forge.logging.markers", "") @@ -88,7 +82,7 @@ repositories { dependencies { neoForge("net.neoforged:neoforge:${property("neoforge_version")}") - modCompileOnly("maven.modrinth:sodium:${property("sodium_version")}-neoforge") + modCompileOnly(":sodium-neoforge-0.6.0-beta.2+mc1.21.1") modCompileOnly("maven.modrinth:iris:${property("iris_version")}-neoforge") //modCompileOnly("maven.modrinth:embeddium:${property("embeddium_version")}") diff --git a/forge/src/main/java/dev/engine_room/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java b/forge/src/main/java/dev/engine_room/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java deleted file mode 100644 index 865ba1978..000000000 --- a/forge/src/main/java/dev/engine_room/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java +++ /dev/null @@ -1,22 +0,0 @@ -package dev.engine_room.flywheel.impl.mixin.sodium; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import dev.engine_room.flywheel.lib.visualization.VisualizationHelper; -import net.caffeinemc.mods.sodium.client.render.chunk.compile.tasks.ChunkBuilderMeshingTask; -import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; -import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; -import net.minecraft.world.level.block.entity.BlockEntity; - -@Mixin(value = ChunkBuilderMeshingTask.class, remap = false) -abstract class ChunkBuilderMeshingTaskMixin { - @Redirect(method = "execute(Lnet/caffeinemc/mods/sodium/client/render/chunk/compile/ChunkBuildContext;Lnet/caffeinemc/mods/sodium/client/util/task/CancellationToken;)Lnet/caffeinemc/mods/sodium/client/render/chunk/compile/ChunkBuildOutput;", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/blockentity/BlockEntityRenderDispatcher;getRenderer(Lnet/minecraft/world/level/block/entity/BlockEntity;)Lnet/minecraft/client/renderer/blockentity/BlockEntityRenderer;", remap = true)) - private BlockEntityRenderer flywheel$redirectGetRenderer(BlockEntityRenderDispatcher dispatcher, BlockEntity blockEntity) { - if (VisualizationHelper.tryAddBlockEntity(blockEntity)) { - return null; - } - return dispatcher.getRenderer(blockEntity); - } -} diff --git a/forge/src/main/java/dev/engine_room/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java b/forge/src/main/java/dev/engine_room/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java deleted file mode 100644 index 94d5d560f..000000000 --- a/forge/src/main/java/dev/engine_room/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java +++ /dev/null @@ -1,48 +0,0 @@ -package dev.engine_room.flywheel.impl.mixin.sodium; - -import java.util.List; -import java.util.Set; -import java.util.function.Supplier; - -import org.objectweb.asm.tree.ClassNode; -import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; -import org.spongepowered.asm.mixin.extensibility.IMixinInfo; - -import com.google.common.base.Suppliers; - -import net.neoforged.fml.loading.LoadingModList; - -public class SodiumMixinPlugin implements IMixinConfigPlugin { - private static final Supplier IS_SODIUM_LOADED = Suppliers.memoize(() -> LoadingModList.get().getModFileById("sodium") != null); - - @Override - public void onLoad(String mixinPackage) { - } - - @Override - public String getRefMapperConfig() { - return null; - } - - @Override - public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - return IS_SODIUM_LOADED.get(); - } - - @Override - public void acceptTargets(Set myTargets, Set otherTargets) { - } - - @Override - public List getMixins() { - return null; - } - - @Override - public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - } - - @Override - public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - } -} diff --git a/forge/src/main/resources/META-INF/neoforge.mods.toml b/forge/src/main/resources/META-INF/neoforge.mods.toml index 0fe5ee7c5..4256c62e6 100644 --- a/forge/src/main/resources/META-INF/neoforge.mods.toml +++ b/forge/src/main/resources/META-INF/neoforge.mods.toml @@ -18,8 +18,6 @@ displayTest = "IGNORE_ALL_VERSION" config = "flywheel.backend.mixins.json" [[mixins]] config = "flywheel.impl.mixins.json" -[[mixins]] -config = "flywheel.impl.sodium.mixins.json" [[dependencies.${mod_id}]] modId = "minecraft" diff --git a/forge/src/main/resources/flywheel.impl.sodium.mixins.json b/forge/src/main/resources/flywheel.impl.sodium.mixins.json deleted file mode 100644 index 0fd5cf55f..000000000 --- a/forge/src/main/resources/flywheel.impl.sodium.mixins.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "dev.engine_room.flywheel.impl.mixin.sodium", - "compatibilityLevel": "JAVA_21", - "refmap": "flywheel.refmap.json", - "plugin": "dev.engine_room.flywheel.impl.mixin.sodium.SodiumMixinPlugin", - "client": [ - "ChunkBuilderMeshingTaskMixin" - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/gradle.properties b/gradle.properties index 336e9a4a6..2be244cd0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,7 +20,6 @@ neoforge_version_range = [21.0.167,) # General build dependency versions java_version = 21 arch_loom_version=1.7.412 -cursegradle_version = 1.4.0 parchment_version = 2024.07.07 # Minecraft build dependency versions diff --git a/libs/sodium-fabric-0.6.0-beta.2+mc1.21.1.jar b/libs/sodium-fabric-0.6.0-beta.2+mc1.21.1.jar new file mode 100644 index 000000000..537f16846 Binary files /dev/null and b/libs/sodium-fabric-0.6.0-beta.2+mc1.21.1.jar differ diff --git a/libs/sodium-neoforge-0.6.0-beta.2+mc1.21.1.jar b/libs/sodium-neoforge-0.6.0-beta.2+mc1.21.1.jar new file mode 100644 index 000000000..0dd80d861 Binary files /dev/null and b/libs/sodium-neoforge-0.6.0-beta.2+mc1.21.1.jar differ