Better Block Entity filtering

- Assumes IInstanceRendered#shouldRenderNormally does not change over a BE's life
This commit is contained in:
Jozufozu 2021-09-26 22:17:14 -07:00
parent 57b67cddcf
commit fe700b8be5
3 changed files with 31 additions and 36 deletions

View file

@ -1,35 +0,0 @@
package com.jozufozu.flywheel.mixin;
import java.util.List;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry;
import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher;
import net.minecraft.world.level.block.entity.BlockEntity;
@Mixin(ChunkRenderDispatcher.CompiledChunk.class)
public class CancelTileEntityRenderMixin {
/**
* JUSTIFICATION: when instanced rendering is enabled, many tile entities no longer need
* to be processed by the normal game renderer. This method is only called to retrieve the
* list of tile entities to render. By filtering the output here, we prevent the game from
* doing unnecessary light lookups and frustum checks.
*/
@Inject(at = @At("RETURN"), method = "getRenderableBlockEntities", cancellable = true)
private void noRenderInstancedTiles(CallbackInfoReturnable<List<BlockEntity>> cir) {
if (Backend.getInstance()
.canUseInstancing()) {
List<BlockEntity> tiles = cir.getReturnValue();
InstancedRenderRegistry r = InstancedRenderRegistry.getInstance();
tiles.removeIf(r::shouldSkipRender);
}
}
}

View file

@ -0,0 +1,30 @@
package com.jozufozu.flywheel.mixin;
import java.util.Set;
import org.spongepowered.asm.mixin.Mixin;
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.backend.Backend;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry;
import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
@Mixin(targets = "net.minecraft.client.renderer.chunk.ChunkRenderDispatcher$RenderChunk$RebuildTask")
public class ChunkRebuildHooksMixin {
@Inject(method = "handleBlockEntity", at = @At("HEAD"), cancellable = true)
private <E extends BlockEntity> void filterBlockEntity(ChunkRenderDispatcher.CompiledChunk compiledChunk, Set<BlockEntity> set, E be, CallbackInfo ci) {
if (Backend.getInstance().canUseInstancing() && Backend.isFlywheelWorld(be.getLevel()) && InstancedRenderRegistry.getInstance()
.shouldSkipRender(be)) {
ci.cancel();
}
}
}

View file

@ -6,7 +6,7 @@
"refmap": "flywheel.refmap.json",
"client": [
"CancelEntityRenderMixin",
"CancelTileEntityRenderMixin",
"ChunkRebuildHooksMixin",
"FixFabulousDepthMixin",
"RenderHooksMixin",
"ShaderCloseMixin",