Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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).

  • Author

Fixed it, thanks. I thought something looked wrong with the tutorial since I have done similar things like this in the past and it just seemed off but I wasn't sure if something changed in 1.12.2 or something that I may have missed.

Edited by HalestormXV

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.