GregTechCEu Modern

GregTechCEu Modern

6M Downloads

Crash on Client Tick - GTNetwork.sendToServer() causes NPE before connection established

KowaretaTerra opened this issue · 0 comments

commented

Checked for existing issues

  • I have checked for existing issues, and have found none.

Tested latest version

  • I have checked that this occurs on the latest version.

GregTech CEu Version

7.1.4

Minecraft Version

1.20.1 Forge

Recipe Viewer Installed

JEI

Environment

Multiplayer - Dedicated Server

Cross-Mod Interaction

Yes

Other Installed Mods

TerraFirmaGreg - Modern

Expected Behavior

Connection to the server and packets being sent after connection is established.

Actual Behavior

The game crashes on client tick due to GTNetwork.sendToServer() being called when the Minecraft client hasn't fully initialized (likely before the ClientPacketListener is ready).

This causes a NullPointerException in:

GTNetwork.sendToServer()

The crash seems to originate from SyncedKeyMapping.onClientTick() — likely triggered either:

Just before or during server connection

Or right after disconnecting

Or during some automatic key-binding / client event logic

The Crash log:

java.lang.NullPointerException: Cannot invoke "net.minecraft.client.multiplayer.ClientPacketListener.m_104910_()"
because the return value of "net.minecraft.client.Minecraft.m_91403_()" is null

at net.minecraftforge.network.simple.SimpleChannel.sendToServer(SimpleChannel.java:87)
at com.gregtechceu.gtceu.common.network.GTNetwork.sendToServer(GTNetwork.java:37)
at com.gregtechceu.gtceu.utils.input.SyncedKeyMapping.onClientTick(SyncedKeyMapping.java:228)

Steps to Reproduce

  1. Join modded server with GTCEu installed

  2. Let the client load in (or press a GTCEu keybind early)

  3. Crash happens consistently depending on timing

Additional Information

Suggested Fix

Add a null check for Minecraft.getInstance().getConnection() before sending packets from the client:

if (Minecraft.getInstance().getConnection() != null) {
// send packet
}