Jump to content

[1.16.4 - SOLVED] How to get FPS


Th1Minecraft

Recommended Posts

I need to get debugFPS but it has private-access in class Mnecraft (net.minecraft.client.Minecraft), I'm try to using Reflection for that and It's give me an error:

 

java.lang.RuntimeException: No such field exception!
    at com.thmc.mod.events.ItemDelayEventHandler.onPreInfoRender(ItemDelayEventHandler.java:130) ~[?:1.0] {re:classloading}
    at net.minecraftforge.eventbus.ASMEventHandler_34_ItemDelayEventHandler_onPreInfoRender_Pre.invoke(.dynamic) ~[?:?] {}
    at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) ~[eventbus-3.0.5-service.jar:?] {}
    at net.minecraftforge.eventbus.EventBus.post(EventBus.java:297) ~[eventbus-3.0.5-service.jar:?] {}
    at net.minecraftforge.client.gui.ForgeIngameGui.pre(ForgeIngameGui.java:828) ~[?:?] {re:classloading}
    at net.minecraftforge.client.gui.ForgeIngameGui.func_238445_a_(ForgeIngameGui.java:121) ~[?:?] {re:classloading}
    at net.minecraft.client.renderer.GameRenderer.func_195458_a(GameRenderer.java:765) ~[?:?] {re:classloading,pl:accesstransformer:B,xf:OptiFine:default}
    at net.minecraft.client.Minecraft.func_195542_b(Minecraft.java:976) [?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:607) [?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.main.Main.main(Main.java:184) [?:?] {re:classloading,pl:runtimedistcleaner:A}
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51] {}
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_51] {}
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_51] {}
    at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_51] {}
    at net.minecraftforge.fml.loading.FMLClientLaunchProvider.lambda$launchService$0(FMLClientLaunchProvider.java:51) [forge-1.16.4-35.0.17.jar:35.0] {}
    at net.minecraftforge.fml.loading.FMLClientLaunchProvider$$Lambda$431/324579982.call(Unknown Source) [forge-1.16.4-35.0.17.jar:35.0] {}
    at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.0.6.jar:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.0.6.jar:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.0.6.jar:?] {}
    at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.0.6.jar:?] {}
    at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.0.6.jar:?] {}

 

then I'm try to try-catch Reflection and it's give me that error again?

Can anyone help me for that?

 

Here is my code

// throws NoSuchFieldException, IllegalAccessException
try {
    Field fps = Minecraft.class.getDeclaredField("debugFPS");
    if (Modifier.isPrivate(fps.getModifiers())) {
        fps.setAccessible(true);
        String text = ChatColor.WHITE + "FPS: " + RenderScreenGui.INSTANCE.translateFPSColor(fps.getInt(fps));
        this.mc.fontRenderer.drawString(matrixStack, text, ((float)(event.getWindow().getScaledWidth() / 2) + 1.0625F - (float)(this.mc.fontRenderer.getStringWidth(text) / 2)) - ((float)((event.getWindow().getScaledWidth() / 2) - (this.mc.fontRenderer.getStringWidth(text) / 2 + 5) - 1.0625F)), ((float)(event.getWindow().getScaledHeight() / 2 - 24) + (float)(9 + 1)) - ((float)(event.getWindow().getScaledHeight() / 2 - 22)), 16777215);
    }
}
catch (NoSuchFieldException e) {
    throw new RuntimeException("No such field");
}

 

Edited by Th1Minecraft
Link to comment
Share on other sites

32 minutes ago, diesieben07 said:

You need to use ObfuscationReflectionHelper with SRG names, otherwise your reflection code will not work outside of the development environment.

That's work! but idk why it's only work for an IDE runClient, the fps is showing. But when do I export the mod jar, run the game, and then the fps doesn't show.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.