Jump to content

Prevent client event being sent to Server?


Timeraa

Recommended Posts

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)

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by Timeraa
Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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();
}

 

Link to comment
Share on other sites

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 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.

Link to comment
Share on other sites

  • 1 year later...
  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Slot depo 5k merupakan situs slot depo 5k yang menyediakan slot minimal deposit 5rb atau 5k via dana yang super gacor, dimana para pemain hanya butuh modal depo sebesar 5k untuk bisa bermain di link slot gacor thailand terbaru tahun 2024 yang gampang menang ini.   DAFTAR & LOGIN AKUN PRO SLOT DEPO 5K ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit 3000 adalah situs slot deposit 3000 via dana yang super gacor dimana para pemain dijamin garansi wd hari ini juga hanya dengan modal receh berupa deposit sebesar 3000 baik via dana, ovo, gopay maupun linkaja untuk para pemain pengguna e-wallet di seluruh Indonesia.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT 3000 ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • OLXTOTO: Menikmati Sensasi Bermain Togel dan Slot dengan Aman dan Mengasyikkan Dunia perjudian daring terus berkembang dengan cepat, dan salah satu situs yang telah menonjol dalam pasar adalah OLXTOTO. Sebagai platform resmi untuk permainan togel dan slot, OLXTOTO telah memenangkan kepercayaan banyak pemain dengan menyediakan pengalaman bermain yang aman, adil, dan mengasyikkan. DAFTAR OLXTOTO DISINI <a href="https://imgbb.com/"><img src="https://i.ibb.co/GnjSVpx/daftar1-480x480.webp" alt="daftar1-480x480" border="0" /></a> Keamanan Sebagai Prioritas Utama Salah satu aspek utama yang membuat OLXTOTO begitu menonjol adalah komitmennya terhadap keamanan pemain. Dengan menggunakan teknologi enkripsi terkini, situs ini memastikan bahwa semua informasi pribadi dan keuangan para pemain tetap aman dan terlindungi dari akses yang tidak sah. Beragam Permainan yang Menarik Di OLXTOTO, pemain dapat menemukan beragam permainan yang menarik untuk dinikmati. Mulai dari permainan klasik seperti togel hingga slot modern dengan fitur-fitur inovatif, ada sesuatu untuk setiap selera dan preferensi. Grafik yang memukau dan efek suara yang mengagumkan menambah keseruan setiap putaran. Peluang Menang yang Tinggi Salah satu hal yang paling menarik bagi para pemain adalah peluang menang yang tinggi yang ditawarkan oleh OLXTOTO. Dengan pembayaran yang adil dan peluang yang setara bagi semua pemain, setiap taruhan memberikan kesempatan nyata untuk memenangkan hadiah besar. Layanan Pelanggan yang Responsif Tim layanan pelanggan OLXTOTO siap membantu para pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Dengan layanan yang ramah dan responsif, pemain dapat yakin bahwa mereka akan mendapatkan bantuan yang mereka butuhkan dengan cepat dan efisien. Kesimpulan OLXTOTO telah membuktikan dirinya sebagai salah satu situs terbaik untuk penggemar togel dan slot online. Dengan fokus pada keamanan, beragam permainan yang menarik, peluang menang yang tinggi, dan layanan pelanggan yang luar biasa, tidak mengherankan bahwa situs ini telah menjadi pilihan utama bagi banyak pemain. Jadi, jika Anda mencari pengalaman bermain yang aman, adil, dan mengasyikkan, jangan ragu untuk bergabung dengan OLXTOTO hari ini dan rasakan sensasi kemenangan!
    • Slot deposit dana adalah situs slot deposit dana yang juga menerima dari e-wallet lain seperti deposit via dana, ovo, gopay & linkaja terlengkap saat ini, sehingga para pemain yang tidak memiliki rekening bank lokal bisa tetap bermain slot dan terbantu dengan adanya fitur tersebut.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit dana adalah situs slot deposit dana minimal 5000 yang dijamin garansi super gacor dan gampang menang, dimana para pemain yang tidak memiliki rekening bank lokal tetap dalam bermain slot dengan melakukan deposit dana serta e-wallet lainnya seperti ovo, gopay maupun linkaja lengkap. Agar para pecinta slot di seluruh Indonesia tetap dapat menikmati permainan tanpa halangan apapun khususnya metode deposit, dimana ketersediaan cara deposit saat ini yang lebih beragam tentunya sangat membantu para pecinta slot.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.