Created
April 30, 2019 03:51
-
-
Save Runemoro/3e357cf19dd852080b385f49435b4acb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package vanillafix.mixin.chunkrenderprofiler; | |
import net.minecraft.client.MinecraftClient; | |
import net.minecraft.client.options.GameOptions; | |
import net.minecraft.util.profiler.DisableableProfiler; | |
import notjustmaps.PatchedMinecraftClient; | |
import notjustmaps.ProfilerStorage; | |
import org.objectweb.asm.Opcodes; | |
import org.spongepowered.asm.mixin.Final; | |
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.Redirect; | |
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | |
@Mixin(MinecraftClient.class) | |
public class MinecraftClientMixin implements PatchedMinecraftClient { | |
@Shadow @Final private DisableableProfiler profiler; | |
@Shadow public GameOptions options; | |
private DisableableProfiler visibleProfiler; | |
{ | |
visibleProfiler = profiler; | |
ProfilerStorage.register(profiler, null); | |
} | |
@Redirect(method = "drawProfilerResults", at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;profiler:Lnet/minecraft/util/profiler/DisableableProfiler;", opcode = Opcodes.GETFIELD)) | |
private DisableableProfiler getProfiler(MinecraftClient client) { | |
return visibleProfiler; | |
} | |
@Redirect(method = "render", at = @At(value = "FIELD", target = "Lnet/minecraft/client/options/GameOptions;debugProfilerEnabled:Z", opcode = Opcodes.GETFIELD)) | |
private boolean getDebugProfilerEnabled(GameOptions gameOptions) { | |
return false; | |
} | |
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gl/GlFramebuffer;endWrite()V")) | |
private void beforeEndWrite(boolean tick, CallbackInfo ci) { | |
if (options.debugEnabled && options.debugProfilerEnabled && !options.hudHidden) { | |
enableProfiler(); | |
} else { | |
disableProfiler(); | |
} | |
} | |
public void cycleProfiler() { | |
DisableableProfiler profiler = ProfilerStorage.next(visibleProfiler); | |
if (profiler == visibleProfiler) { | |
return; | |
} | |
if (visibleProfiler.getController().isEnabled()) { | |
disableProfiler(); | |
} | |
visibleProfiler = profiler; | |
if (options.debugProfilerEnabled) { | |
enableProfiler(); | |
} | |
} | |
private void enableProfiler() { | |
if (visibleProfiler == profiler) { | |
visibleProfiler.getController().enable(); | |
} else { | |
ProfilerStorage.enable(visibleProfiler); | |
} | |
} | |
private void disableProfiler() { | |
if (visibleProfiler == profiler) { | |
profiler.getController().disable(); | |
} else { | |
ProfilerStorage.disable(visibleProfiler); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment