From 70a72209d22407d351092eb66802c9b6dd9beef4 Mon Sep 17 00:00:00 2001 From: Kneelawk Date: Wed, 17 Apr 2024 17:26:24 -0700 Subject: [PATCH] Move Sodium mixin to platform code --- .../sodium/ChunkBuilderMeshingTaskMixin.java | 0 .../impl/mixin/sodium/SodiumMixinPlugin.java | 48 +++++++++++++++++++ .../flywheel.impl.sodium.mixins.json | 0 .../sodium/ChunkBuilderMeshingTaskMixin.java | 23 +++++++++ .../impl/mixin/sodium/SodiumMixinPlugin.java | 0 .../flywheel.impl.sodium.mixins.json | 14 ++++++ 6 files changed, 85 insertions(+) rename {common => fabric}/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java (100%) create mode 100644 fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java rename {common => fabric}/src/main/resources/flywheel.impl.sodium.mixins.json (100%) create mode 100644 forge/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java rename {common => forge}/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java (100%) create mode 100644 forge/src/main/resources/flywheel.impl.sodium.mixins.json diff --git a/common/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java b/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java similarity index 100% rename from common/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java rename to fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java diff --git a/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java b/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java new file mode 100644 index 000000000..b2021bdc1 --- /dev/null +++ b/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java @@ -0,0 +1,48 @@ +package com.jozufozu.flywheel.impl.mixin.sodium; + +import java.util.List; +import java.util.Set; +import java.util.function.Supplier; + +import com.google.common.base.Suppliers; + +import org.objectweb.asm.tree.ClassNode; +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +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/common/src/main/resources/flywheel.impl.sodium.mixins.json b/fabric/src/main/resources/flywheel.impl.sodium.mixins.json similarity index 100% rename from common/src/main/resources/flywheel.impl.sodium.mixins.json rename to fabric/src/main/resources/flywheel.impl.sodium.mixins.json diff --git a/forge/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java b/forge/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java new file mode 100644 index 000000000..71e32d0cd --- /dev/null +++ b/forge/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java @@ -0,0 +1,23 @@ +package com.jozufozu.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 com.jozufozu.flywheel.impl.visualization.VisualizationHelper; + +import me.jellysquid.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", 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/common/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java b/forge/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java similarity index 100% rename from common/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java rename to forge/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java diff --git a/forge/src/main/resources/flywheel.impl.sodium.mixins.json b/forge/src/main/resources/flywheel.impl.sodium.mixins.json new file mode 100644 index 000000000..c02f33509 --- /dev/null +++ b/forge/src/main/resources/flywheel.impl.sodium.mixins.json @@ -0,0 +1,14 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "com.jozufozu.flywheel.impl.mixin.sodium", + "compatibilityLevel": "JAVA_17", + "refmap": "flywheel.refmap.json", + "plugin": "com.jozufozu.flywheel.impl.mixin.sodium.SodiumMixinPlugin", + "client": [ + "ChunkBuilderMeshingTaskMixin" + ], + "injectors": { + "defaultRequire": 1 + } +}