Crashing when trying to call functions in MCP

Viewed 170

I am trying to create a client using ModCoderPack for 1.8.8 but when I try to call any function that isnt in the same class such as mc.displayGuiScreen, the game crashes. I have code that waits for keypresses

public void onKeyPressed(GameSettings gs) {
        if(gs.jbClientToggleMenu.isKeyDown()) {
            this.mc.displayGuiScreen(new ModManager());
    }
}

That function is called in Minecraft.java

else
{
    jbclient.onKeyPressed(this.gameSettings); // <-=

    if (k == 1)
    {
        this.displayInGameMenu();
    }

Here is the entire code for the Client class

Code:

public class Client {
    private final Minecraft mc = Minecraft.getMinecraft();
    private GameSettings gameSettings = new GameSettings();
    public static String clientName = "jbClient";
    public static String clientVersion = "0.01";

    public static final ModManager modManager = new ModManager();

    public static final Logger logger = LogManager.getLogger();

        public void onKeyPressed(GameSettings gs) {
            if(gs.jbClientToggleMenu.isKeyDown()) {
                this.mc.displayGuiScreen(new ModManager());
            }
        }
}

Crash log

---- Minecraft Crash Report ----
// Hi. I'm Minecraft, and I'm a crashaholic.

Time: 6/18/20 5:53 PM
Description: Unexpected error

java.lang.NullPointerException: Unexpected error
    at jordanbaron.jbclient.Client.onKeyPressed(Client.java:23)
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:1950)
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1123)
    at net.minecraft.client.Minecraft.run(Minecraft.java:429)
    at net.minecraft.client.main.Main.main(Main.java:113)
    at Start.main(Start.java:11)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
    at jordanbaron.jbclient.Client.onKeyPressed(Client.java:23)

-- Affected level --
Details:
    Level name: MpServer
    All players: 1 total; [EntityPlayerSP['Player824'/288, l='MpServer', x=87.13, y=81.00, z=-381.85]]
    Chunk stats: MultiplayerChunkCache: 583, 583
    Level seed: 0
    Level generator: ID 00 - default, ver 1. Features enabled: false
    Level generator options: 
    Level spawn location: -52.00,64.00,132.00 - World: (-52,64,132), Chunk: (at 12,4,4 in -4,8; contains blocks -64,0,128 to -49,255,143), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)
    Level time: 5569 game time, 5569 day time
    Level dimension: 0
    Level storage version: 0x00000 - Unknown?
    Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
    Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
    Forced entities: 84 total; [EntityCreeper['Creeper'/4096, l='MpServer', x=163.50, y=18.00, z=-365.50], EntityCreeper['Creeper'/4097, l='MpServer', x=159.50, y=18.00, z=-362.50], EntitySkeleton['Skeleton'/4099, l='MpServer', x=166.19, y=18.00, z=-366.66], EntitySkeleton['Skeleton'/2820, l='MpServer', x=156.50, y=27.00, z=-360.50], EntityBat['Bat'/3889, l='MpServer', x=99.47, y=12.53, z=-440.25], EntityZombie['Zombie'/4659, l='MpServer', x=35.50, y=55.00, z=-427.50], EntityBat['Bat'/2612, l='MpServer', x=51.44, y=49.59, z=-424.41], EntityZombie['Zombie'/4660, l='MpServer', x=34.50, y=55.00, z=-428.50], EntityRabbit['Rabbit'/826, l='MpServer', x=141.50, y=71.00, z=-426.50], EntityRabbit['Rabbit'/827, l='MpServer', x=138.34, y=72.00, z=-427.66], EntityRabbit['Rabbit'/828, l='MpServer', x=136.34, y=72.00, z=-427.66], EntityZombie['Zombie'/3139, l='MpServer', x=154.50, y=20.00, z=-324.50], EntityZombie['Zombie'/3140, l='MpServer', x=154.50, y=20.00, z=-325.50], EntityZombie['Zombie'/3141, l='MpServer', x=150.50, y=20.00, z=-322.50], EntityZombie['Zombie'/3142, l='MpServer', x=156.44, y=20.00, z=-324.06], EntityZombie['Zombie'/2376, l='MpServer', x=128.47, y=37.00, z=-366.81], EntityCreeper['Creeper'/2377, l='MpServer', x=129.06, y=38.00, z=-367.66], EntitySkeleton['Skeleton'/4426, l='MpServer', x=149.53, y=12.00, z=-461.66], EntitySpider['Spider'/2891, l='MpServer', x=160.69, y=40.09, z=-417.31], EntitySquid['Squid'/2898, l='MpServer', x=97.00, y=61.41, z=-403.77], EntitySquid['Squid'/2900, l='MpServer', x=100.53, y=58.30, z=-399.57], EntitySquid['Squid'/2901, l='MpServer', x=101.89, y=60.17, z=-386.47], EntitySquid['Squid'/2902, l='MpServer', x=102.47, y=57.00, z=-391.50], EntityBat['Bat'/4955, l='MpServer', x=153.43, y=17.07, z=-438.28], EntityCreeper['Creeper'/3932, l='MpServer', x=147.56, y=26.00, z=-459.94], EntityCreeper['Creeper'/3938, l='MpServer', x=97.50, y=18.00, z=-354.50], EntityCreeper['Creeper'/2147, l='MpServer', x=49.50, y=51.00, z=-342.50], EntitySkeleton['Skeleton'/3939, l='MpServer', x=95.50, y=18.00, z=-355.50], EntitySkeleton['Skeleton'/4966, l='MpServer', x=159.50, y=18.00, z=-363.50], EntitySkeleton['Skeleton'/4967, l='MpServer', x=157.50, y=18.00, z=-364.50], EntityBat['Bat'/3433, l='MpServer', x=147.27, y=11.30, z=-340.73], EntityBat['Bat'/3434, l='MpServer', x=144.89, y=12.05, z=-343.34], EntityPlayerSP['Player824'/288, l='MpServer', x=87.13, y=81.00, z=-381.85], EntityZombie['Zombie'/4208, l='MpServer', x=34.50, y=40.00, z=-334.50], EntityZombie['Zombie'/2673, l='MpServer', x=50.50, y=34.00, z=-424.50], EntitySkeleton['Skeleton'/3953, l='MpServer', x=21.94, y=25.00, z=-306.06], EntityWitch['Witch'/3186, l='MpServer', x=56.50, y=44.00, z=-421.50], EntitySpider['Spider'/3954, l='MpServer', x=19.91, y=25.00, z=-308.09], EntitySpider['Spider'/2674, l='MpServer', x=13.50, y=11.00, z=-376.50], EntityCreeper['Creeper'/3187, l='MpServer', x=47.50, y=44.00, z=-421.50], EntityZombie['Zombie'/2936, l='MpServer', x=112.50, y=17.00, z=-352.50], EntityZombie['Zombie'/2937, l='MpServer', x=113.81, y=16.00, z=-351.25], EntityZombie['Zombie'/3196, l='MpServer', x=33.50, y=35.00, z=-428.50], EntityItem['item.item.seeds'/386, l='MpServer', x=43.13, y=63.00, z=-357.88], EntityRabbit['Rabbit'/387, l='MpServer', x=34.50, y=68.00, z=-334.50], EntityRabbit['Rabbit'/388, l='MpServer', x=32.13, y=66.00, z=-330.88], EntityRabbit['Rabbit'/389, l='MpServer', x=32.75, y=66.00, z=-330.25], EntityCow['Cow'/1929, l='MpServer', x=111.50, y=65.00, z=-448.50], EntityCow['Cow'/1930, l='MpServer', x=113.50, y=66.00, z=-449.50], EntityCow['Cow'/1931, l='MpServer', x=115.50, y=66.00, z=-450.50], EntityCow['Cow'/1932, l='MpServer', x=115.50, y=66.00, z=-446.50], EntityChicken['Chicken'/1933, l='MpServer', x=100.47, y=64.00, z=-452.53], EntityChicken['Chicken'/1934, l='MpServer', x=104.50, y=65.00, z=-442.50], EntityChicken['Chicken'/1935, l='MpServer', x=108.50, y=65.00, z=-449.50], EntityChicken['Chicken'/1936, l='MpServer', x=109.50, y=65.00, z=-449.50], EntityCow['Cow'/406, l='MpServer', x=49.13, y=86.00, z=-402.06], EntityCow['Cow'/407, l='MpServer', x=43.88, y=83.00, z=-397.59], EntityCow['Cow'/408, l='MpServer', x=44.50, y=83.00, z=-394.50], EntityCow['Cow'/409, l='MpServer', x=44.50, y=88.00, z=-392.50], EntityZombie['Zombie'/3737, l='MpServer', x=91.28, y=11.06, z=-455.56], EntityBat['Bat'/5793, l='MpServer', x=66.75, y=35.10, z=-397.75], EntityCreeper['Creeper'/3509, l='MpServer', x=39.50, y=82.00, z=-373.50], EntityItem['item.item.seeds'/5064, l='MpServer', x=65.28, y=64.00, z=-362.81], EntitySquid['Squid'/5070, l='MpServer', x=39.81, y=60.75, z=-353.53], EntitySquid['Squid'/5071, l='MpServer', x=46.47, y=60.19, z=-347.03], EntityCreeper['Creeper'/3024, l='MpServer', x=153.50, y=24.00, z=-375.50], EntitySquid['Squid'/5072, l='MpServer', x=36.47, y=61.00, z=-350.34], EntityCreeper['Creeper'/3025, l='MpServer', x=156.50, y=24.00, z=-377.50], EntityEnderman['Enderman'/3795, l='MpServer', x=41.50, y=55.00, z=-432.50], EntityZombie['Zombie'/4315, l='MpServer', x=142.50, y=13.00, z=-443.50], EntitySkeleton['Skeleton'/3550, l='MpServer', x=91.50, y=23.00, z=-455.50], EntitySkeleton['Skeleton'/3552, l='MpServer', x=78.50, y=23.00, z=-458.16], EntitySkeleton['Skeleton'/3297, l='MpServer', x=28.16, y=25.00, z=-309.75], EntityZombie['Zombie'/744, l='MpServer', x=70.50, y=34.00, z=-312.50], EntitySkeleton['Skeleton'/745, l='MpServer', x=67.50, y=34.00, z=-316.50], EntityZombie['Zombie'/746, l='MpServer', x=70.50, y=34.00, z=-309.50], EntityBat['Bat'/3821, l='MpServer', x=162.75, y=15.66, z=-452.50], EntityRabbit['Rabbit'/494, l='MpServer', x=105.50, y=63.00, z=-398.50], EntitySkeleton['Skeleton'/2287, l='MpServer', x=109.50, y=18.00, z=-351.50], EntityRabbit['Rabbit'/495, l='MpServer', x=103.94, y=64.00, z=-401.88], EntityRabbit['Rabbit'/496, l='MpServer', x=109.53, y=66.00, z=-399.81], EntityRabbit['Rabbit'/2037, l='MpServer', x=109.78, y=65.00, z=-457.59], EntityCreeper['Creeper'/3574, l='MpServer', x=89.50, y=17.00, z=-459.50], EntityCreeper['Creeper'/3582, l='MpServer', x=48.50, y=55.00, z=-427.50]]
    Retry entities: 0 total; []
    Server brand: vanilla
    Server type: Integrated singleplayer server
Stacktrace:
    at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:390)
    at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2782)
    at net.minecraft.client.Minecraft.run(Minecraft.java:458)
    at net.minecraft.client.main.Main.main(Main.java:113)
    at Start.main(Start.java:11)

-- System Details --
Details:
    Minecraft Version: 1.8.9
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 1.8.0_251, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 837748936 bytes (798 MB) / 1532493824 bytes (1461 MB) up to 3806855168 bytes (3630 MB)
    JVM Flags: 0 total; 
    IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94
    Launched Version: mcp
    LWJGL: 2.9.4
    OpenGL: GeForce GTX 1660/PCIe/SSE2 GL version 4.6.0 NVIDIA 445.75, NVIDIA Corporation
    GL Caps: Using GL 1.3 multitexturing.
Using GL 1.3 texture combiners.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Shaders are available because OpenGL 2.1 is supported.
VBOs are available because OpenGL 1.5 is supported.

    Using VBOs: No
    Is Modded: Very likely; Jar signature invalidated
    Type: Client (map_client.txt)
    Resource Packs: 
    Current Language: English (US)
    Profiler Position: N/A (disabled)
    CPU: 4x Intel(R) Core(TM) i5-6400 CPU @ 2.70GHz

EDIT: It works when passing the Minecraft instance to the function

1 Answers

This is easy: You are facing a NullPointerException which means you are trying to use something that has no value assigned. I would guess that

this.gameSettings

either does not exist or has no value assigned yet, which means it is null. That is causing the NullPointerExcepting resulting in a crash. You probably need to write

this.gameSettings = gs;

or just use gs if possible. Both should work. Good luck :)

Related