Add Rubidium compatibility

- Add proper Rubidium compatibility on our side
- Overwrite methods in Rubidium's FlywheelCompat class with stubs to
prevent crashes
This commit is contained in:
PepperCode1 2023-04-13 10:16:33 -07:00
parent 993cc9d04f
commit 26cced23b4
7 changed files with 132 additions and 9 deletions

View File

@ -51,6 +51,7 @@ minecraft {
property 'flw.debugMemorySafety', 'true'
arg '-mixin.config=flywheel.mixins.json'
arg '-mixin.config=flywheel.sodium.mixins.json'
mods {
flywheel {
@ -66,6 +67,7 @@ minecraft {
property 'forge.logging.console.level', 'debug'
arg '-mixin.config=flywheel.mixins.json'
arg '-mixin.config=flywheel.sodium.mixins.json'
mods {
flywheel {
@ -188,7 +190,7 @@ jar {
'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'
'MixinConfigs' : 'flywheel.mixins.json,flywheel.sodium.mixins.json'
])
}
}

View File

@ -0,0 +1,48 @@
package com.jozufozu.flywheel.compat;
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.minecraftforge.fml.loading.LoadingModList;
public class SodiumMixinPlugin implements IMixinConfigPlugin {
private static final Supplier<Boolean> IS_SODIUM_LOADED = Suppliers.memoize(() -> LoadingModList.get().getModFileById("rubidium") != 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

@ -6,6 +6,7 @@ import com.jozufozu.flywheel.api.event.BeginFrameEvent;
import com.jozufozu.flywheel.api.event.RenderStageEvent;
import com.jozufozu.flywheel.api.visual.Effect;
import com.jozufozu.flywheel.api.visual.Visual;
import com.jozufozu.flywheel.api.visualization.BlockEntityVisualizer;
import com.jozufozu.flywheel.extension.ClientLevelExtension;
import com.jozufozu.flywheel.impl.visualization.manager.VisualManager;
import com.jozufozu.flywheel.lib.util.AnimationTickHolder;
@ -163,6 +164,22 @@ public class VisualizedRenderDispatcher {
.forEach(world.getEntities()::add);
}
public static <T extends BlockEntity> boolean tryAddBlockEntity(T blockEntity) {
Level level = blockEntity.getLevel();
if (FlwUtil.canUseVisualization(level)) {
return false;
}
BlockEntityVisualizer<? super T> visualizer = VisualizationHelper.getVisualizer(blockEntity);
if (visualizer == null) {
return false;
}
getBlockEntities(level).queueAdd(blockEntity);
return visualizer.shouldSkipRender(blockEntity);
}
public static void addDebugInfo(List<String> info) {
ClientLevel level = Minecraft.getInstance().level;
if (FlwUtil.canUseVisualization(level)) {

View File

@ -0,0 +1,23 @@
package com.jozufozu.flywheel.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.VisualizedRenderDispatcher;
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<?> flywheel$redirectGetRenderer(BlockEntityRenderDispatcher dispatcher, BlockEntity blockEntity) {
if (VisualizedRenderDispatcher.tryAddBlockEntity(blockEntity)) {
return null;
}
return dispatcher.getRenderer(blockEntity);
}
}

View File

@ -0,0 +1,24 @@
package com.jozufozu.flywheel.mixin.sodium;
import java.util.Collection;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import me.jellysquid.mods.sodium.client.compat.FlywheelCompat;
import net.minecraft.world.level.block.entity.BlockEntity;
/**
* Overwrite all methods in this class with stubs. These methods use Flywheel classes that no longer exist and would cause a NoClassDefFoundError if invoked.
*/
@Mixin(value = FlywheelCompat.class, remap = false)
public class FlywheelCompatMixin {
@Overwrite
public static boolean addAndFilterBEs(BlockEntity blockEntity) {
return true;
}
@Overwrite
public static void filterBlockEntityList(Collection<BlockEntity> blockEntities) {
}
}

View File

@ -7,9 +7,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.impl.visualization.VisualizationHelper;
import com.jozufozu.flywheel.impl.visualization.VisualizedRenderDispatcher;
import com.jozufozu.flywheel.util.FlwUtil;
import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher;
import net.minecraft.world.level.block.entity.BlockEntity;
@ -18,12 +16,8 @@ import net.minecraft.world.level.block.entity.BlockEntity;
public class ChunkRebuildHooksMixin {
@Inject(method = "handleBlockEntity", at = @At("HEAD"), cancellable = true)
private <E extends BlockEntity> void flywheel$addAndFilterBEs(ChunkRenderDispatcher.CompiledChunk compiledChunk, Set<BlockEntity> set, E be, CallbackInfo ci) {
if (FlwUtil.canUseVisualization(be.getLevel())) {
if (VisualizationHelper.canVisualize(be))
VisualizedRenderDispatcher.getBlockEntities(be.getLevel()).queueAdd(be);
if (VisualizationHelper.shouldSkipRender(be))
ci.cancel();
if (VisualizedRenderDispatcher.tryAddBlockEntity(be)) {
ci.cancel();
}
}
}

View File

@ -0,0 +1,15 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.jozufozu.flywheel.mixin.sodium",
"compatibilityLevel": "JAVA_17",
"refmap": "flywheel.refmap.json",
"plugin": "com.jozufozu.flywheel.compat.SodiumMixinConfigPlugin",
"client": [
"ChunkRenderRebuildTaskMixin",
"FlywheelCompatMixin"
],
"injectors": {
"defaultRequire": 1
}
}