Jump to content

[1.12.2] Packet Crashes Client on Server [SOLVED]


HalestormXV

Recommended Posts

So a simple question. I followed this tutorial by McJty which utilizes the SimpleNetwork message setup. He uses MovingObjectPosition which I know has been changed to RayTraceResult so I made that change. But when I am on a server and press the Key Bind the client crashes with this: https://pastebin.com/Aje5pDik

 

It's crashing at line 38 of this class: https://pastebin.com/4x3hKbMd

 

Now I know from some past network usage on older versions, that usually Minecraft.getMinecraft() may not be the best thing to use since if I recall getMinecraft() is a bad function to call on a server (perhaps I am wrong). I am only guessing that it has to do with that because it works fine on SinglePlayer only. It only blows up like that if you do it while logged into a server. Insights? Correction that needs to be applied? Perhaps the tutorial was made for a different version of Forge and something else was changed that I was unaware of?

 

If you happen to need the PacketHandler itself, it is really small so I just pasted it.

 

public class PacketHandler
{
    private static int packetId = 0;

    public static SimpleNetworkWrapper INSTANCE = null;

    public PacketHandler() {
    }

    public static int nextID() {
        return packetId++;
    }

    public static void registerMessages(String channelName)
    {
        INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(channelName);
        registerMessages();
    }

    public static void registerMessages() {
        // Register messages which are sent from the client to the server here:
        INSTANCE.registerMessage(PacketSendKey.Handler.class, PacketSendKey.class, nextID(), Side.SERVER);
    }
}
Edited by HalestormXV
Link to comment
Share on other sites

That tutorial isn't really doing things quite right here.

 

Have two seperate constructors for your packet like so:

 

public PacketSendKey() {}

public PacketSendKey(BlockPos blockPos)
{
	this.blockPos = blockPos;
}

 

Then when you go to send this packet, get the mousever position from the client and pass it to the packet constructor yourself.

 

You can't reference client-sided code in the packet constructor as the packet also needs to be constructed on the server (so it can be passed to your packet handler).

  • Like 1
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.