Jump to content

How to check if network is available - or better way to sync after death.


Recommended Posts

Posted

So my mod is not syncing the client side after respawn properly because the capabilities to receive the data have not been attached on the client yet. I get logs like this:

 

    [21Jan2023 15:18:13.229] [Server thread/INFO] [org.xire.joko.stats_and_skills.StatsNSkills/]: Cloned player stats.
    [21Jan2023 15:18:13.230] [Server thread/ERROR] [org.xire.joko.stats_and_skills.StatsNSkills/]: Reduced stats for player JontomXire because of death.
    [21Jan2023 15:18:13.244] [Render thread/ERROR] [org.xire.joko.stats_and_skills.StatsNSkills/]: Capabilities missing when syncing data for player JontomXire.
 

To try and solve this, I send a message to the server when handling AttachCapabilitiesEvent on the client. The problem is that when initially logging on, the network does not seem to be initialised. I get this error:

 

    [21Jan2023 15:25:19.507] [Render thread/ERROR] [net.minecraftforge.eventbus.EventBus/EVENTBUS]: Exception caught during firing event: Cannot invoke "net.minecraft.client.multiplayer.ClientPacketListener.m_6198_()" because the return value of "net.minecraft.client.Minecraft.m_91403_()" is null
        Index: 1
        Listeners:
            0: NORMAL
            1: ASM: class org.xire.joko.stats_and_skills.PlayerData onAttachCapability(Lnet/minecraftforge/event/AttachCapabilitiesEvent;)V
    java.lang.NullPointerException: Cannot invoke "net.minecraft.client.multiplayer.ClientPacketListener.m_6198_()" because the return value of "net.minecraft.client.Minecraft.m_91403_()" is null
    at TRANSFORMER/[email protected]/net.minecraftforge.network.simple.SimpleChannel.sendToServer(SimpleChannel.java:87)
 

So I either need a way to work out if this call will work or crash:

    INSTANCE.sendToServer(msg);

where INSTANCE is:

    private static final ResourceLocation RESOURCE = new ResourceLocation(StatsNSkills.MODID, "comms");
    private static final String           VERSION  = "1";
    private static final SimpleChannel    INSTANCE = NetworkRegistry.newSimpleChannel(RESOURCE,
                                                                                      () -> VERSION,
                                                                                      VERSION::equals,
                                                                                      VERSION::equals);

 

Or a better trigger to send the sync packet from the server side after respawn.


 

Posted

People that post snippets of incomplete code will usually just be ignored.

That is unless the error is trivially obvious from what you post.

You need to show all relevant code, preferably on github.

We don't play guessing games with you to try to figure out what the problem is.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted (edited)

https://gitlab.com/JontomXire/stats-and-skills

 

I actually did include all relevant bits of code, just not all the superfluous context.

 

I would imagine that a quick look, by someone that has access to the source code and knows how it is all laid out, at SimpleChannel.java:87 would be very illuminating. And that the error message, read by someone who understands that part of the Forge code, would allow them to immediately identify the problem and a solution.

Edited by Jontom Xire
Posted

The answer is to change the call to send to server to be like this:

 

        if (null != Minecraft.getInstance().getConnection()) {
            INSTANCE.sendToServer(msg);
        }

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.