-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/compat/java/me/jellysquid/mods/sodium/client/compat/FlywheelCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |