diff --git a/src/main/java/club/sk1er/patcher/mixins/performance/RenderChunkMixin_OptimizeSpecialTileEntities.java b/src/main/java/club/sk1er/patcher/mixins/performance/RenderChunkMixin_OptimizeSpecialTileEntities.java index 7589ba8b..d3ebae69 100644 --- a/src/main/java/club/sk1er/patcher/mixins/performance/RenderChunkMixin_OptimizeSpecialTileEntities.java +++ b/src/main/java/club/sk1er/patcher/mixins/performance/RenderChunkMixin_OptimizeSpecialTileEntities.java @@ -6,12 +6,23 @@ import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(RenderChunk.class) public class RenderChunkMixin_OptimizeSpecialTileEntities { -//#if MC==10809 + + //#if MC==10809 + @Unique private TileEntitySpecialRenderer patcher$tileEntitySpecialRenderer; + + @ModifyVariable(method = "rebuildChunk", at = @At("STORE"), ordinal = 0) + private TileEntitySpecialRenderer patcher$renderSpecialTileEntitiesOnce(TileEntitySpecialRenderer tileEntitySpecialRenderer) { + patcher$tileEntitySpecialRenderer = tileEntitySpecialRenderer; + return tileEntitySpecialRenderer; + } + /** * Minecraft typically renders special tile entities twice per frame. This is noticeable by comparing the opacity * of a beacon beam when the beacon is in view versus when it's out of view (fly 50 blocks above, for instance). @@ -21,9 +32,8 @@ public class RenderChunkMixin_OptimizeSpecialTileEntities { */ @Redirect(method = "rebuildChunk", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/chunk/CompiledChunk;addTileEntity(Lnet/minecraft/tileentity/TileEntity;)V")) private void patcher$renderSpecialTileEntitiesOnce(CompiledChunk instance, TileEntity tileEntityIn) { - TileEntitySpecialRenderer tileentityspecialrenderer = TileEntityRendererDispatcher.instance.getSpecialRenderer(tileEntityIn); - if (!tileentityspecialrenderer.forceTileEntityRender()) instance.addTileEntity(tileEntityIn); + if (!patcher$tileEntitySpecialRenderer.forceTileEntityRender()) instance.addTileEntity(tileEntityIn); } -//#endif + //#endif } diff --git a/src/main/java/club/sk1er/patcher/mixins/performance/TileEntityRendererDispatcherMixin_RemoveInvalidEntities.java b/src/main/java/club/sk1er/patcher/mixins/performance/TileEntityRendererDispatcherMixin_RemoveInvalidEntities.java index aec90f3b..011bf85b 100644 --- a/src/main/java/club/sk1er/patcher/mixins/performance/TileEntityRendererDispatcherMixin_RemoveInvalidEntities.java +++ b/src/main/java/club/sk1er/patcher/mixins/performance/TileEntityRendererDispatcherMixin_RemoveInvalidEntities.java @@ -4,18 +4,23 @@ import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; 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 org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(value = TileEntityRendererDispatcher.class, priority = 100) +public abstract class TileEntityRendererDispatcherMixin_RemoveInvalidEntities { -@Mixin(TileEntityRendererDispatcher.class) -public class TileEntityRendererDispatcherMixin_RemoveInvalidEntities { //#if MC==10809 - @Inject(method = "getSpecialRenderer", at = @At("HEAD"), cancellable = true) - private void patcher$returnNullIfInvalid(TileEntity tileEntityIn, CallbackInfoReturnable> cir) { - if (tileEntityIn == null || tileEntityIn.isInvalid()) { - cir.setReturnValue(null); - } + @Shadow + public abstract TileEntitySpecialRenderer getSpecialRendererByClass(Class teClass); + + /** + * @author MicrocontrollersDev and Wyvest + * @reason Remove invalid tile entities from being rendered + */ + @Overwrite + private TileEntitySpecialRenderer getSpecialRenderer(TileEntity tileEntityIn) { + return tileEntityIn != null && !tileEntityIn.isInvalid() ? this.getSpecialRendererByClass(tileEntityIn.getClass()) : null; } //#endif }