diff --git a/build.gradle b/build.gradle index 48d33b3cd..218cef6cd 100644 --- a/build.gradle +++ b/build.gradle @@ -58,6 +58,7 @@ dependencies { modCompileOnly 'curse.maven:starlight-521783:3554912' modCompileOnly 'maven.modrinth:iris:1.18.x-v1.1.4' + modCompileOnly 'maven.modrinth:sodium:mc1.18.1-0.4.0-alpha6' implementation 'com.google.code.findbugs:jsr305:3.0.2' modCompileOnly 'maven.modrinth:indium:1.0.2-alpha1+mc1.18' diff --git a/src/main/java/com/jozufozu/flywheel/fabric/mixin/sodium/ChunkRenderRebuildTaskMixin.java b/src/main/java/com/jozufozu/flywheel/fabric/mixin/sodium/ChunkRenderRebuildTaskMixin.java new file mode 100644 index 000000000..941ea2948 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/fabric/mixin/sodium/ChunkRenderRebuildTaskMixin.java @@ -0,0 +1,29 @@ +package com.jozufozu.flywheel.fabric.mixin.sodium; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import com.jozufozu.flywheel.backend.Backend; +import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; +import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; + +import me.jellysquid.mods.sodium.client.render.chunk.tasks.ChunkRenderRebuildTask; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.world.level.block.entity.BlockEntity; + +@Mixin(value = ChunkRenderRebuildTask.class, remap = false) +public class ChunkRenderRebuildTaskMixin { + @Redirect(method = "performBuild", 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;")) + private BlockEntityRenderer redirectGetRenderer(BlockEntityRenderDispatcher dispatcher, BlockEntity blockEntity) { + if (Backend.canUseInstancing(blockEntity.getLevel())) { + if (InstancedRenderRegistry.canInstance(blockEntity.getType())) + InstancedRenderDispatcher.getBlockEntities(blockEntity.getLevel()).queueAdd(blockEntity); + + if (InstancedRenderRegistry.shouldSkipRender(blockEntity)) + return null; + } + return dispatcher.getRenderer(blockEntity); + } +} diff --git a/src/main/java/com/jozufozu/flywheel/fabric/mixin/sodium/SodiumMixinPlugin.java b/src/main/java/com/jozufozu/flywheel/fabric/mixin/sodium/SodiumMixinPlugin.java new file mode 100644 index 000000000..8ff59f73b --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/fabric/mixin/sodium/SodiumMixinPlugin.java @@ -0,0 +1,42 @@ +package com.jozufozu.flywheel.fabric.mixin.sodium; + +import net.fabricmc.loader.api.FabricLoader; +import org.objectweb.asm.tree.ClassNode; +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import java.util.List; +import java.util.Set; + +public class SodiumMixinPlugin implements IMixinConfigPlugin { + @Override + public void onLoad(String mixinPackage) { + } + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + return FabricLoader.getInstance().isModLoaded("sodium"); + } + + @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/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index ee0570f12..7d70f7eb2 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -26,7 +26,8 @@ }, "mixins": [ "flywheel.mixins.json", - "flywheel.fabric.mixins.json" + "flywheel.fabric.mixins.json", + "flywheel.sodium.mixins.json" ], "depends": { diff --git a/src/main/resources/flywheel.sodium.mixins.json b/src/main/resources/flywheel.sodium.mixins.json new file mode 100644 index 000000000..05d85410f --- /dev/null +++ b/src/main/resources/flywheel.sodium.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "com.jozufozu.flywheel.fabric.mixin.sodium", + "plugin": "com.jozufozu.flywheel.fabric.mixin.sodium.SodiumMixinPlugin", + "compatibilityLevel": "JAVA_17", + "client": [ + "ChunkRenderRebuildTaskMixin" + ], + "injectors": { + "defaultRequire": 1 + } +}