Skip to content

Commit

Permalink
Restore Flywheel compat
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt committed Sep 15, 2024
1 parent 3801871 commit 324ad26
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ dependencies {

// Mods
"modCompatCompileOnly"("curse.maven:codechickenlib-242818:${"codechicken_fileid"()}")
"modCompatCompileOnly"("curse.maven:flywheel-486392:3535459")

modLocalRuntime("curse.maven:lazydfu-460819:3249059")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package me.jellysquid.mods.sodium.client.compat;

import java.util.Collection;

import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry;
import me.jellysquid.mods.sodium.client.SodiumClientMod;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.common.Mod;
import org.embeddedt.embeddium.api.ChunkDataBuiltEvent;

@Mod.EventBusSubscriber(modid = SodiumClientMod.MODID, value = Dist.CLIENT)
public class FlywheelCompat {
private static final boolean flywheelLoaded = ModList.get().isLoaded("flywheel");

/**
* Filters a collection of TileEntities to avoid rendering conflicts with Flywheel.
*
* @param blockEntities The collection to be filtered.
*/
public static void filterBlockEntityList(Collection<BlockEntity> blockEntities) {
if (flywheelLoaded && Backend.getInstance().canUseInstancing()) {
InstancedRenderRegistry r = InstancedRenderRegistry.getInstance();
blockEntities.removeIf(r::shouldSkipRender);
}
}

public static boolean isSkipped(BlockEntity be) {
if(!flywheelLoaded)
return false;
if(!Backend.getInstance().canUseInstancing())
return false;
return InstancedRenderRegistry.getInstance().shouldSkipRender(be);
}

@SubscribeEvent
public static void onChunkDataBuilt(ChunkDataBuiltEvent event) {
if(flywheelLoaded) {
event.getDataBuilder().removeBlockEntitiesIf(FlywheelCompat::isSkipped);
}
}
}

0 comments on commit 324ad26

Please sign in to comment.