Timeraa 0 Report post Posted July 22, 2018 Hey, i am creating a mod for a plugin server where you can select blocks with right click, but i only want to use the right click on the client side and don't want to send the right click to the server. How can i achieve this? Example: User clicks at block, mod opens a GUI. (Server does as well but should not) Share this post Link to post Share on other sites
Discult 1 Report post Posted July 22, 2018 are you specifying @SideOnly(Side.CLIENT) anywhere can you produce any src code to be reviewed. Share this post Link to post Share on other sites
Timeraa 0 Report post Posted July 22, 2018 @Mod.EventBusSubscriber public class SelectionEventHandler { @SubscribeEvent public void onRightClickBlock(PlayerInteractEvent.RightClickBlock event) {} } Basically this is the event. I removed the if statements in the event because i don't think they help you in any way because its basically just location checking etc. Share this post Link to post Share on other sites
Timeraa 0 Report post Posted July 22, 2018 I should probably mention that i am using Forge for 1.12.2 Share this post Link to post Share on other sites
Animefan8888 491 Report post Posted July 22, 2018 33 minutes ago, Timeraa said: Basically this is the event. I removed the if statements in the event because i don't think they help you in any way because its basically just location checking etc. event.getSide() == Side.CLIENT Though this is assuming that your method of opening a gui is client side only. Share this post Link to post Share on other sites
Timeraa 0 Report post Posted July 22, 2018 5 minutes ago, Animefan8888 said: event.getSide() == Side.CLIENT Though this is assuming that your method of opening a gui is client side only. Yes, but i want to prevent the server event like if i click the block the server plugin opens a gui but i want to prevent that event being sent to the server and just use the right click on the side end. Share this post Link to post Share on other sites
Animefan8888 491 Report post Posted July 22, 2018 8 minutes ago, Timeraa said: Yes, but i want to prevent the server event like if i click the block the server plugin opens a gui but i want to prevent that event being sent to the server and just use the right click on the side end. Have you tried setting the event to cancelled? event.setCanceled(true) Share this post Link to post Share on other sites
Timeraa 0 Report post Posted July 22, 2018 Just now, Animefan8888 said: Have you tried setting the event to cancelled? event.setCanceled(true) Yes i tried that but that does not prevent the event. (Maybe because i have multiple right click events in multiple packages?) Share this post Link to post Share on other sites
Animefan8888 491 Report post Posted July 22, 2018 Just now, Timeraa said: Yes i tried that but that does not prevent the event. (Maybe because i have multiple right click events in multiple packages?) No, unless your other right click events set cancelled to false. It seems that there is no way for this to happen with forge currently. Share this post Link to post Share on other sites
Timeraa 0 Report post Posted July 22, 2018 (edited) 2 minutes ago, Animefan8888 said: No, unless your other right click events set cancelled to false. It seems that there is no way for this to happen with forge currently. Hm thats unfortunate. Ill look through my packages to find out if i set it to false somewhere. Normally i develop plugins for Spigot but i needed a small change. Edited July 22, 2018 by Timeraa Share this post Link to post Share on other sites
jabelar 585 Report post Posted July 22, 2018 No, wait it should work. This is the way you should do it. In your proxy class create a method called something like showMyGui(). In the ClientProxy version of that method you would actually make the GUI. In the server version you would do nothing. In your event handler you just call that proxy method and it will behave differently on each side. Server would not put up a GUI. Share this post Link to post Share on other sites
Timeraa 0 Report post Posted July 22, 2018 3 minutes ago, jabelar said: No, wait it should work. This is the way you should do it. In your proxy class create a method called something like showMyGui(). In the ClientProxy version of that method you would actually make the GUI. In the server version you would do nothing. In your event handler you just call that proxy method and it will behave differently on each side. Server would not put up a GUI. ? But i want to completely prevent the client to sent the right click to the server. Share this post Link to post Share on other sites
jabelar 585 Report post Posted July 22, 2018 5 minutes ago, Timeraa said: ? But i want to completely prevent the client to sent the right click to the server. In the server version you would set cancelled. That should work. You mentioned handling the event in multiple places in your code? That is a bad idea because you don't know the order they will fire. Share this post Link to post Share on other sites
Timeraa 0 Report post Posted July 22, 2018 1 minute ago, jabelar said: In the server version you would set cancelled. That should work. You mentioned handling the event in multiple places in your code? That is a bad idea because you don't know the order they will fire. The server is a normal server running plugins, i don't want to handle those items on the server i want to simply cancel the event on the client side, you hold the item with the mod and the mod does not send the right click to the server if you right click, i already tried just using setCancelled(true) but that only stops the block placement but it still sends the right click to the server. Or is the problem because the other right click events that are used from other items make it so that setCancelled sets itself to false? Share this post Link to post Share on other sites
m00nl1ght 2 Report post Posted July 22, 2018 So, if I understand correctly, you are creating a client-side only mod? And when you right click a block something should happen on the client, but the server should not be notified of the right click? This is actually not that easy, because the client will always send the interaction package even if the event has been cancelled (in PlayerControllerMP#processRightClickBlock) : if (event.isCanceled()) { // Give the server a chance to fire event as well. That way server event is not dependant on client event. this.connection.sendPacket(new CPacketPlayerTryUseItemOnBlock(pos, direction, hand, f, f1, f2)); return event.getCancellationResult(); } Share this post Link to post Share on other sites
Matryoshika 115 Report post Posted July 22, 2018 (edited) All this dilly dallying for something simple. @EventBusSubscriber(value = Side.CLIENT) This will make sure that the event is only registered for the client Edited July 22, 2018 by Matryoshika Share this post Link to post Share on other sites
diesieben07 6116 Report post Posted July 22, 2018 (edited) 1 minute ago, Matryoshika said: All this dilly dallying for something simple. @EventBusSubscriber(value = Side.CLIENT) This will make sure that the event is fired only for clients. It will fire only on the physical client. It will fire for integrated servers as well. Treating integrated and dedicated servers differently is an antipattern. Moreover this does not solve the presented problem. Edited July 22, 2018 by diesieben07 Share this post Link to post Share on other sites