Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Prevent client event being sent to Server?
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
Timeraa

Prevent client event being sent to Server?

By Timeraa, July 22, 2018 in Modder Support

  • Start new topic

Recommended Posts

Timeraa    0

Timeraa

Timeraa    0

  • Tree Puncher
  • Timeraa
  • Members
  • 0
  • 12 posts
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    2

Discult

Discult    2

  • Creeper Killer
  • Discult
  • Members
  • 2
  • 105 posts
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

Timeraa

Timeraa    0

  • Tree Puncher
  • Timeraa
  • Members
  • 0
  • 12 posts
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

Timeraa

Timeraa    0

  • Tree Puncher
  • Timeraa
  • Members
  • 0
  • 12 posts
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    741

Animefan8888

Animefan8888    741

  • Reality Controller
  • Animefan8888
  • Forge Modder
  • 741
  • 6157 posts
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.


VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Share this post


Link to post
Share on other sites

Timeraa    0

Timeraa

Timeraa    0

  • Tree Puncher
  • Timeraa
  • Members
  • 0
  • 12 posts
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    741

Animefan8888

Animefan8888    741

  • Reality Controller
  • Animefan8888
  • Forge Modder
  • 741
  • 6157 posts
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)

 


VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Share this post


Link to post
Share on other sites

Timeraa    0

Timeraa

Timeraa    0

  • Tree Puncher
  • Timeraa
  • Members
  • 0
  • 12 posts
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    741

Animefan8888

Animefan8888    741

  • Reality Controller
  • Animefan8888
  • Forge Modder
  • 741
  • 6157 posts
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.


VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Share this post


Link to post
Share on other sites

Timeraa    0

Timeraa

Timeraa    0

  • Tree Puncher
  • Timeraa
  • Members
  • 0
  • 12 posts
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    593

jabelar

jabelar    593

  • Reality Controller
  • jabelar
  • Members
  • 593
  • 3266 posts
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.


Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Share this post


Link to post
Share on other sites

Timeraa    0

Timeraa

Timeraa    0

  • Tree Puncher
  • Timeraa
  • Members
  • 0
  • 12 posts
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    593

jabelar

jabelar    593

  • Reality Controller
  • jabelar
  • Members
  • 593
  • 3266 posts
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.


Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Share this post


Link to post
Share on other sites

Timeraa    0

Timeraa

Timeraa    0

  • Tree Puncher
  • Timeraa
  • Members
  • 0
  • 12 posts
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

m00nl1ght

m00nl1ght    2

  • Tree Puncher
  • m00nl1ght
  • Members
  • 2
  • 22 posts
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    118

Matryoshika

Matryoshika    118

  • Dragon Slayer
  • Matryoshika
  • Forge Modder
  • 118
  • 523 posts
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

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Share this post


Link to post
Share on other sites

diesieben07    7587

diesieben07

diesieben07    7587

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7587
  • 54935 posts
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

simondoestuff    0

simondoestuff

simondoestuff    0

  • Tree Puncher
  • simondoestuff
  • Members
  • 0
  • 1 post
Posted April 5, 2020

It is possible to replace the playercontroller with one of your own that occasionally returns immediately.

Share this post


Link to post
Share on other sites

diesieben07    7587

diesieben07

diesieben07    7587

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7587
  • 54935 posts
Posted April 6, 2020

Ancient thread. Locked.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Linky132
      [SOLVED] [1.16.5 ] Dust Block Texture Glitch

      By Linky132 · Posted just now

      I figured it out. I had the render type set to translucent, when what it should have been on was cutout. Thanks for the help.
    • Klarks
      [1.16.4] How i can open a container by clicking on my mob

      By Klarks · Posted 25 minutes ago

      So what needs to be implemented? My Entity?  
    • Linky132
      (1.16.2) Making a new capability (3)

      By Linky132 · Posted 56 minutes ago

      I could be wrong, but I think you might need to add this code in the constructor: FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); And you may need to change the setup method to non-static.
    • Linky132
      [SOLVED] [1.16.5 ] Dust Block Texture Glitch

      By Linky132 · Posted 1 hour ago

      Also, the texture doesn't glitch when the dust is in a straight line, or when it's in its dot form (not the '+' shape).
    • Linky132
      [SOLVED] [1.16.5 ] Dust Block Texture Glitch

      By Linky132 · Posted 1 hour ago

      Unfortunately, that didn't work, it still glitches. Any other ideas?
  • Topics

    • Linky132
      4
      [SOLVED] [1.16.5 ] Dust Block Texture Glitch

      By Linky132
      Started 17 hours ago

    • Klarks
      12
      [1.16.4] How i can open a container by clicking on my mob

      By Klarks
      Started 17 hours ago

    • e2rifia
      13
      (1.16.2) Making a new capability (3)

      By e2rifia
      Started 6 hours ago

    • Somonestolemyusername
      18
      [1.15.2] How Would I make a custom bow?

      By Somonestolemyusername
      Started Tuesday at 09:30 PM

    • Edrax
      0
      Creating custom atlas?

      By Edrax
      Started 1 hour ago

  • Who's Online (See full list)

    • st4s1k
    • Klarks
    • Linky132
    • Talp1
    • Thorius
    • ptki ptki Ptki pt
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Prevent client event being sent to Server?
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community