Posted December 31, 20186 yr I need to execute some code when the player switches his armor. But the LivingEquipmentChangeEvent is only server side and i need to do my stuff client side. So is there a way to run my stuff client side when the LivingEquipmentChangeEvent is fired?
December 31, 20186 yr Author I tried sending a packet and it is recieved on the client. public class MessageHandlerBD implements IMessageHandler<MessageBD, IMessage> { @Override public IMessage onMessage(MessageBD messageBD, MessageContext ctx) { System.out.println("PACKET"); return null; } } But instead of just writing PACKET in the client log, I want to do something with my Capability on the client side. But when i try it the game always is crashing @Override public IMessage onMessage(MessageBD messageBD, MessageContext ctx) { ctx.getServerHandler().player.getCapability(DiveSpeedProvider.DIVESPEED, null).updateDiveSpeed(ctx.getServerHandler().player); return null; }
December 31, 20186 yr Author I also thought that the getServerHandler isn't working on client side. But how can I access the Player object on the client side?
December 31, 20186 yr Author 14 minutes ago, diesieben07 said: The client player is always Minecraft#player. Ok. I feel like that was pretty obvious. Thanks for the help. 15 minutes ago, diesieben07 said: Note that you will need to encapsulate this access to client-only classes through @SidedProxy. But I don't know what you mean with that.
December 31, 20186 yr Author Ok, I now registered the Packet in my ClientProxy public class ClientProxy implements CommonProxy { @Override public void init() { BetterDiving.INSTANCE.registerMessage(MessageHandlerBD.class, MessageBD.class, 0, Side.CLIENT); } } But once i switch armor on a server nothing happens and on the server i get this message: Undefined discriminator for message type MessageBD in channel better_diving
December 31, 20186 yr Author Now I created a MessageHandlerBDDummy class and I'm calling this in my ServerProxy BetterDiving.INSTANCE.registerMessage(MessageHandlerBDDummy.class, MessageBD.class, 0, Side.SERVER); The MessageHandlyerBDDummy class isn't doing something when receiving a packet. And everything seems to work know. Thank you for the help. If there is a better way of solving my issue you can say it.
January 1, 20196 yr 20 hours ago, Meldexun said: CommonProxy A common proxy doesn’t make sense, proxies are for separating side specific code i.e. code that will crash when executed on the wrong side. A proxy by definition cannot be common. Common code goes anywhere except for in a proxy About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
January 1, 20196 yr Author 1 hour ago, diesieben07 said: The packet must be registered on both sides, no reason to do that through your proxy. Only the packet action must be encapsulated. Ok. That makes sense. I will try to do that. 13 minutes ago, Cadiboo said: A common proxy doesn’t make sense, proxies are for separating side specific code i.e. code that will crash when executed on the wrong side. A proxy by definition cannot be common. Common code goes anywhere except for in a proxy It's just the name of the interface. I have just followed a tutorial for modding beginning and there it was named common proxy. I'm not doing something in this interface.
January 1, 20196 yr 3 minutes ago, Meldexun said: It's just the name of the interface. I have just followed a tutorial for modding beginning and there it was named common proxy. I'm not doing something in this interface. Great! IProxy is the conventional name for it though About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
January 1, 20196 yr Author 1 hour ago, diesieben07 said: The packet must be registered on both sides, no reason to do that through your proxy. Only the packet action must be encapsulated. I now check in my MessageHandler if the message is recieved client side and it seems to work. @Override public IMessage onMessage(MessageCapabilitySync messageCapabilitySync, MessageContext ctx) { if (ctx.side.isClient()) { //do some stuff } return null; } I tried that before but then it was crashing all the time. Thats why I used the proxy to register my message. 17 minutes ago, Cadiboo said: Great! IProxy is the conventional name for it though I also noticed that most people name it IProxy. Maybe I will change it too.
January 1, 20196 yr Author 8 minutes ago, diesieben07 said: The condition is pointless, you know which side you sent the packet do. The "do some stuff" part must be in your client proxy though, like I initially mentioned. So I just create a method in my Client proxy which is than called by the MessageHandler. @Override public IMessage onMessage(MessageCapabilitySync messageCapabilitySync, MessageContext ctx) { ClientProxy.message1(messageCapabilitySync, ctx); return null; }
January 1, 20196 yr Directly calling something on ClientProxy defeats its purpose IIRC, You need to call the method from your proxy instance About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
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.