package com.jozufozu.flywheel.mixin; import java.util.ArrayList; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import com.google.common.collect.Lists; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; import com.jozufozu.flywheel.util.ClientLevelExtension; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.entity.LevelEntityGetter; @Mixin(ClientLevel.class) public abstract class ClientLevelMixin implements ClientLevelExtension { @Shadow protected abstract LevelEntityGetter getEntities(); @Override public Iterable flywheel$getAllLoadedEntities() { return getEntities().getAll(); } @Inject(method = "entitiesForRendering", at = @At("RETURN"), cancellable = true) private void filterEntities(CallbackInfoReturnable> cir) { if (Backend.isOn()) { Iterable entities = cir.getReturnValue(); ArrayList filtered = Lists.newArrayList(entities); filtered.removeIf(InstancedRenderRegistry::shouldSkipRender); cir.setReturnValue(filtered); } } }