HalestormXV Posted February 10, 2018 Posted February 10, 2018 (edited) 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 February 10, 2018 by HalestormXV Quote
quadraxis Posted February 10, 2018 Posted February 10, 2018 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). 1 Quote
quadraxis Posted February 10, 2018 Posted February 10, 2018 Also read through the docs page if you haven't already. 1 Quote
HalestormXV Posted February 10, 2018 Author Posted February 10, 2018 (edited) 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 February 10, 2018 by HalestormXV Quote
Recommended Posts
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.