mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-29 08:26:37 +01:00
Better Block Entity filtering
- Assumes IInstanceRendered#shouldRenderNormally does not change over a BE's life
This commit is contained in:
parent
57b67cddcf
commit
fe700b8be5
3 changed files with 31 additions and 36 deletions
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,7 +6,7 @@
|
||||||
"refmap": "flywheel.refmap.json",
|
"refmap": "flywheel.refmap.json",
|
||||||
"client": [
|
"client": [
|
||||||
"CancelEntityRenderMixin",
|
"CancelEntityRenderMixin",
|
||||||
"CancelTileEntityRenderMixin",
|
"ChunkRebuildHooksMixin",
|
||||||
"FixFabulousDepthMixin",
|
"FixFabulousDepthMixin",
|
||||||
"RenderHooksMixin",
|
"RenderHooksMixin",
|
||||||
"ShaderCloseMixin",
|
"ShaderCloseMixin",
|
||||||
|
|
Loading…
Reference in a new issue