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?
The update for 1.13 is being worked on - please be patient. (Updated 02/19/19)
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 1
Timeraa

Prevent client event being sent to Server?

Started by Timeraa, July 22, 2018

17 posts in this topic

Timeraa    0

Timeraa

Timeraa    0

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

Discult

Discult    1

  • Stone Miner
  • Discult
  • Members
  • 1
  • 97 posts
  • 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

Timeraa

Timeraa    0

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

Timeraa

Timeraa    0

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

Animefan8888

Animefan8888    491

  • Reality Controller
  • Animefan8888
  • Forge Modder
  • 491
  • 4324 posts
  • 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

Timeraa

Timeraa    0

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

Animefan8888

Animefan8888    491

  • Reality Controller
  • Animefan8888
  • Forge Modder
  • 491
  • 4324 posts
  • 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

Timeraa

Timeraa    0

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

Animefan8888

Animefan8888    491

  • Reality Controller
  • Animefan8888
  • Forge Modder
  • 491
  • 4324 posts
  • 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

Timeraa

Timeraa    0

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

jabelar

jabelar    585

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

Timeraa

Timeraa    0

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

jabelar

jabelar    585

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

Timeraa

Timeraa    0

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

m00nl1ght

m00nl1ght    2

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

Matryoshika

Matryoshika    115

  • Dragon Slayer
  • Matryoshika
  • Forge Modder
  • 115
  • 509 posts
  • 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

diesieben07

diesieben07    6116

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6116
  • 40281 posts
  • 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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 1
Go To Topic Listing Modder Support

  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Marc10601
      Forge Keeps Crashing on loggin in (client side)

      By Marc10601 · Posted 19 minutes ago

      yes, they are currently up to date
    • drakola42
      1.13 Dropper won't drop items

      By drakola42 · Posted 35 minutes ago

      Do you just install optifine on forge? If you do that you can just press on the .jar file and install it.  
    • diesieben07
      RegistryEvent for IRecipe in 1.13.2

      By diesieben07 · Posted 39 minutes ago

      No mod needed to change recipes: https://minecraft.gamepedia.com/Data_pack
    • cente
      Fresh install, Missing library: libraries/net/minecraft/server/1.13.2/server-1.13.2-data.jar

      By cente · Posted 40 minutes ago

      Well yeah, just trying to gauge whether it's a bug I should wait to get fixed or whether I'm just derping around.
    • youngbaguette
      1.13 Dropper won't drop items

      By youngbaguette · Posted 40 minutes ago

      Hey so I'm running the latest version of Forge (25.0.49) and it seems to prevent droppers from dropping items. The items can be transferred into other containers, but not actually dropped as an item. I tested this out first in vanilla where it (obviously) worked, then with a clean install of Forge with no mods where it wouldn't drop, all on the same world. Can someone else confirm this to make sure I'm not just going crazy?
  • Topics

    • Marc10601
      6
      Forge Keeps Crashing on loggin in (client side)

      By Marc10601
      Started 3 hours ago

    • youngbaguette
      1
      1.13 Dropper won't drop items

      By youngbaguette
      Started 40 minutes ago

    • MrMarnic
      4
      RegistryEvent for IRecipe in 1.13.2

      By MrMarnic
      Started Yesterday at 10:28 PM

    • cente
      11
      Fresh install, Missing library: libraries/net/minecraft/server/1.13.2/server-1.13.2-data.jar

      By cente
      Started 4 hours ago

    • drakola42
      0
      Not enough items (1.12.2)

      By drakola42
      Started 40 minutes ago

  • Who's Online (See full list)

    • BloomCake
    • sunsigne
    • Hedaox
    • Roiniti
    • Awakened Redstone
    • desht
    • peanut07
    • mrburgerUS
    • drakola42
    • diesieben07
    • Kzitold
    • Sarffe
    • Marc10601
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Prevent client event being sent to Server?
  • Theme
  • Contact Us

Copyright © 2017 ForgeDevelopment LLC Powered by Invision Community