Jump to content

[1.18.2] How to set screen on client


J3ramy

Recommended Posts

Good evening guys,

 

I want to go back to the title screen (just for test purpose) when the ServerStartingEvent gets triggered, but then it crashes and this error gets printed:

Spoiler
Quote

java.lang.NullPointerException: Cannot invoke "net.minecraft.client.Minecraft.isDemo()" because "this.minecraft" is null
    at net.minecraft.client.gui.screens.TitleScreen.render(TitleScreen.java:366) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraftforge.client.ForgeHooksClient.drawScreenInternal(ForgeHooksClient.java:385) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2375%2381!/:?] {re:classloading}
    at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:378) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2375%2381!/:?] {re:classloading}
    at net.minecraft.client.renderer.GameRenderer.render(GameRenderer.java:900) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:1070) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.doLoadLevel(Minecraft.java:2012) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.loadLevel(Minecraft.java:1913) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.gui.screens.worldselection.WorldSelectionList$WorldListEntry.loadWorld(WorldSelectionList.java:473) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.gui.screens.worldselection.WorldSelectionList$WorldListEntry.joinWorld(WorldSelectionList.java:330) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.gui.screens.worldselection.WorldSelectionList$WorldListEntry.mouseClicked(WorldSelectionList.java:257) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.gui.components.AbstractSelectionList.mouseClicked(AbstractSelectionList.java:323) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.gui.components.events.ContainerEventHandler.mouseClicked(ContainerEventHandler.java:31) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.MouseHandler.lambda$onPress$0(MouseHandler.java:93) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.gui.screens.Screen.wrapScreenError(Screen.java:528) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.MouseHandler.onPress(MouseHandler.java:90) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.MouseHandler.lambda$setup$4(MouseHandler.java:195) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.util.thread.BlockableEventLoop.execute(BlockableEventLoop.java:90) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.client.MouseHandler.lambda$setup$5(MouseHandler.java:194) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:runtimedistcleaner:A}
    at org.lwjgl.glfw.GLFWMouseButtonCallbackI.callback(GLFWMouseButtonCallbackI.java:36) ~[lwjgl-glfw-3.2.2.jar%2354!/:build 10] {}
    at org.lwjgl.system.JNI.invokeV(Native Method) ~[lwjgl-3.2.2.jar%2360!/:build 10] {}
    at org.lwjgl.glfw.GLFW.glfwPollEvents(GLFW.java:3101) ~[lwjgl-glfw-3.2.2.jar%2354!/:build 10] {}
    at com.mojang.blaze3d.systems.RenderSystem.flipFrame(RenderSystem.java:168) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:runtimedistcleaner:A}
    at com.mojang.blaze3d.platform.Window.updateDisplay(Window.java:337) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:1092) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.run(Minecraft.java:668) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.main.Main.main(Main.java:205) ~[forge-1.18.2-40.1.0_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2376!/:?] {re:classloading,pl:runtimedistcleaner:A}
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}
    at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}
    at net.minecraftforge.fml.loading.targets.ForgeClientUserdevLaunchHandler.lambda$launchService$0(ForgeClientUserdevLaunchHandler.java:24) ~[fmlloader-1.18.2-40.1.0.jar%230!/:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-9.1.3.jar%2310!/:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-9.1.3.jar%2310!/:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-9.1.3.jar%2310!/:?] {}
    at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-9.1.3.jar%2310!/:?] {}
    at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-9.1.3.jar%2310!/:?] {}
    at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-9.1.3.jar%2310!/:?] {}
    at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-9.1.3.jar%2310!/:?] {}
    at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149) [bootstraplauncher-1.0.0.jar:?] {}

 

 

My Event Class:

@Mod.EventBusSubscriber(modid = EdomRpMod.MOD_ID)
public class ModEvents {
    @SubscribeEvent
    public static void onServerStarting(ServerStartingEvent event){
        Minecraft.getInstance().setScreen(new TitleScreen());
    }
}

 

EDIT: Add error stack trace

 

Does anyone know how to switch screens between the main menu and other screens (no ingame overlay)?

Edited by J3ramy
Link to comment
Share on other sites

I am programming a mod which checks if the player is whitelisted via database query. And in the ServerStartingEvent I want to check if the connection can be established  - if not, then switch back to the title screen

 

EDIT: I found the ClientPlayerNetworkEvent.LoggedInEvent which is client only. There, I can also disconnect the player from the server immediately via ClientPlayerNetworkEvent.LoggedInEvent#getConnection()#disconnect(Component)

Edited by J3ramy
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.



×
×
  • Create New...

Important Information

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