Add sodium 0.6 compat

This commit is contained in:
IThundxr 2024-09-14 09:20:59 -04:00
parent 42290b207f
commit fc61ff1c98
Failed to generate hash of commit
18 changed files with 63 additions and 181 deletions

View file

@ -89,6 +89,9 @@ class SubprojectPlugin: Plugin<Project> {
includeGroup("maven.modrinth") includeGroup("maven.modrinth")
} }
} }
flatDir {
dirs = setOf(project.rootProject.file("libs"))
}
} }
} }

View file

@ -72,6 +72,8 @@ jarSets {
dependencies { dependencies {
modCompileOnly("net.fabricmc:fabric-loader:${property("fabric_loader_version")}") 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") testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
} }

View file

@ -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<Boolean> isLoaded;
CompatMods() {
isLoaded = Suppliers.memoize(() -> FabricLoader.getInstance().isModLoaded(name()));
}
public boolean isLoaded() {
return isLoaded.get();
}
}

View file

@ -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 <T extends BlockEntity> Object forBlockEntityType(BlockEntityType<T> type) {
BlockEntityRenderPredicate<T> predicate = (getter, pos, be) -> VisualizationHelper.tryAddBlockEntity(be);
BlockEntityRenderHandler.instance().addRenderPredicate(type, predicate);
return predicate;
}
public static <T extends BlockEntity> void removePredicate(BlockEntityType<T> type, Object predicate) {
BlockEntityRenderHandler.instance().removeRenderPredicate(type, (BlockEntityRenderPredicate<T>) predicate);
}
}

View file

@ -5,6 +5,8 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.Unique;
import dev.engine_room.flywheel.api.visualization.BlockEntityVisualizer; 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 dev.engine_room.flywheel.impl.extension.BlockEntityTypeExtension;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.BlockEntityType;
@ -12,8 +14,13 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
@Mixin(BlockEntityType.class) @Mixin(BlockEntityType.class)
abstract class BlockEntityTypeMixin<T extends BlockEntity> implements BlockEntityTypeExtension<T> { abstract class BlockEntityTypeMixin<T extends BlockEntity> implements BlockEntityTypeExtension<T> {
@Unique @Unique
@Nullable
private BlockEntityVisualizer<? super T> flywheel$visualizer; private BlockEntityVisualizer<? super T> flywheel$visualizer;
@Unique
@Nullable
private Object flywheel$sodiumPredicate;
@Override @Override
@Nullable @Nullable
public BlockEntityVisualizer<? super T> flywheel$getVisualizer() { public BlockEntityVisualizer<? super T> flywheel$getVisualizer() {
@ -22,6 +29,13 @@ abstract class BlockEntityTypeMixin<T extends BlockEntity> implements BlockEntit
@Override @Override
public void flywheel$setVisualizer(@Nullable BlockEntityVisualizer<? super T> visualizer) { public void flywheel$setVisualizer(@Nullable BlockEntityVisualizer<? super T> 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; this.flywheel$visualizer = visualizer;
} }
} }

View file

@ -72,7 +72,7 @@ dependencies {
modImplementation("net.fabricmc:fabric-loader:${property("fabric_loader_version")}") modImplementation("net.fabricmc:fabric-loader:${property("fabric_loader_version")}")
modApi("net.fabricmc.fabric-api:fabric-api:${property("fabric_api_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") modCompileOnly("maven.modrinth:iris:${property("iris_version")}-fabric")
"forApi"(project(path = ":common", configuration = "commonApiOnly")) "forApi"(project(path = ":common", configuration = "commonApiOnly"))

View file

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

View file

@ -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<Boolean> 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<String> myTargets, Set<String> otherTargets) {
}
@Override
public List<String> 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) {
}
}

View file

@ -24,7 +24,6 @@
"mixins": [ "mixins": [
"flywheel.backend.mixins.json", "flywheel.backend.mixins.json",
"flywheel.impl.mixins.json", "flywheel.impl.mixins.json",
"flywheel.impl.sodium.mixins.json",
"flywheel.impl.fabric.mixins.json" "flywheel.impl.fabric.mixins.json"
], ],
"depends": { "depends": {
@ -32,6 +31,6 @@
"fabric-api": "${fabric_api_version_range}" "fabric-api": "${fabric_api_version_range}"
}, },
"breaks": { "breaks": {
"sodium": "<0.5.0" "sodium": ["<0.6.0-beta.2"]
} }
} }

View file

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

View file

@ -67,12 +67,6 @@ loom {
add(backend, "backend-flywheel.refmap.json") add(backend, "backend-flywheel.refmap.json")
} }
forge {
mixinConfig("flywheel.backend.mixins.json")
mixinConfig("flywheel.impl.mixins.json")
mixinConfig("flywheel.impl.sodium.mixins.json")
}
runs { runs {
configureEach { configureEach {
property("forge.logging.markers", "") property("forge.logging.markers", "")
@ -88,7 +82,7 @@ repositories {
dependencies { dependencies {
neoForge("net.neoforged:neoforge:${property("neoforge_version")}") 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:iris:${property("iris_version")}-neoforge")
//modCompileOnly("maven.modrinth:embeddium:${property("embeddium_version")}") //modCompileOnly("maven.modrinth:embeddium:${property("embeddium_version")}")

View file

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

View file

@ -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<Boolean> 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<String> myTargets, Set<String> otherTargets) {
}
@Override
public List<String> 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) {
}
}

View file

@ -18,8 +18,6 @@ displayTest = "IGNORE_ALL_VERSION"
config = "flywheel.backend.mixins.json" config = "flywheel.backend.mixins.json"
[[mixins]] [[mixins]]
config = "flywheel.impl.mixins.json" config = "flywheel.impl.mixins.json"
[[mixins]]
config = "flywheel.impl.sodium.mixins.json"
[[dependencies.${mod_id}]] [[dependencies.${mod_id}]]
modId = "minecraft" modId = "minecraft"

View file

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

View file

@ -20,7 +20,6 @@ neoforge_version_range = [21.0.167,)
# General build dependency versions # General build dependency versions
java_version = 21 java_version = 21
arch_loom_version=1.7.412 arch_loom_version=1.7.412
cursegradle_version = 1.4.0
parchment_version = 2024.07.07 parchment_version = 2024.07.07
# Minecraft build dependency versions # Minecraft build dependency versions

Binary file not shown.

Binary file not shown.