Jump to content

[Solved] [1.8.9] Scrollwheel as input


Tschipp

Recommended Posts

I'm trying to get the scrollwheel as input for my item, but what I currently have doesn't seem to work. I'm new to events so please tell me if I'm doing something completely wrong. This is the function that I have in my Item class:

@SubscribeEvent
      public void scroll(MouseEvent event) {
     
            event.setCanceled(true);
      }

Link to comment
Share on other sites

1. Did you register event?

2. I don't think MouseEvent is cancelable (read docs).

3. MouseEvent (like any other input events) are client-sided. First of all they shouldn't be placed in common classes like Item. Second - you will need packets to do anything there (send packet to server from client when you want to do stuff).

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

To register call MinecraftForge.EVENT_BUS.register(...);

Doesn't matter right now, but it doesn't say it is or is not(at least for me).

Make a new Class to put it in.

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

Alright, I got the event sorta working. But how do I get the player from the event? And is this the correct way to make it client-side only?(probably not) I register the event in my main Classes Pre-Init. Is that the way to do it?

This is my event class:

public class MouseScroll {
     
      @SideOnly(Side.CLIENT)
      @SubscribeEvent
      public void scroll(MouseEvent event)
      {
     
            if(event.dwheel > 0)
            {
                             
            }
            else if(event.dwheel < 0)
            {
                 
            }
      }

}

Link to comment
Share on other sites

You should register it in init. What you need to do is use packets to send the data to the server.

If you don't know how to use packets here is a link. http://jabelarminecraft.blogspot.com/p/minecraft-forge.html

The data should contain something like a boolean or a byte with either 0 or 1 to determine > or <

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

You actually need to get the players UUID so Minecraft holds a client side player variable inside itself.

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

Yes I have. This is where I send the packet:

public class MouseScroll {

      @SideOnly(Side.CLIENT)
      @SubscribeEvent
      public void scroll(MouseEvent event)
      {
           



                  if(event.dwheel > 0)
                  {
                        CreativePlus.network.sendToServer(new NoisePacket(1));
                        System.out.println("Packet 1 Sent");
                  }
                  else if(event.dwheel < 0)
                  {
                       
                        CreativePlus.network.sendToServer(new NoisePacket(2));
                        System.out.println("Packet 2 Sent");

                  }

           
      }

}

 

This is the Packet:

public class NoisePacket implements IMessage{
     
      private int upOrDown;
     
      public NoisePacket() {
           
      }
     
      public NoisePacket(int i) {
            this.upOrDown = i;
      }

      @Override
      public void fromBytes(ByteBuf buf) {
            upOrDown = ByteBufUtils.readVarInt(buf, 4);
      }

      @Override
      public void toBytes(ByteBuf buf) {
            ByteBufUtils.writeVarInt(buf, upOrDown, 4);
      }

}

 

This is the Packet Handler:

public class NoisePacketHandler implements IMessageHandler<NoisePacket, IMessage> {


      @Override
      public IMessage onMessage(NoisePacket message, MessageContext ctx) {
            IThreadListener mainThread = Minecraft.getMinecraft();

            mainThread.addScheduledTask(new Runnable(){

                  @Override
                  public void run() {
                        EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;

                        System.out.println("Packet Revieved");
                        if(player.getItemInUse().getItem() == CustomItems.noiseFill && player.isSneaking()) {



                              ItemStack stack = player.getItemInUse();

                              NBTTagCompound subTag = stack.getTagCompound();

                              subTag.setDouble("percentage", subTag.getDouble("percentage") + 0.1);

                              stack.setTagCompound(subTag);
                        }

                  }

            });

            return null;
      }



}

 

I have registred the Packet on the client Side.

How do I use the Packet Handler to change some nbt on the players currently held itemStack?

Link to comment
Share on other sites

Don't use EntityPlayerSP for this if you are editing NBT or any data it must be handled by the server, which means use EntityPlayerMP and you can't use Minecraft...thePlayer. You should use...

if (ctx.side == Side.SERVER)
		EntityPlayerMP player = ctx.getServerHandler().playerEntity;

or something similar.

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

Alright, the packet now gets recieved, but a nullPointerException is being thrown at the if(player.getItemInUse....)

public class NoisePacketHandler implements IMessageHandler<NoisePacket, IMessage> {


      @Override
      public IMessage onMessage(NoisePacket message, final MessageContext ctx) {
            IThreadListener mainThread = (WorldServer)ctx.getServerHandler().playerEntity.worldObj;

            mainThread.addScheduledTask(new Runnable(){
                  EntityPlayerMP player = ctx.getServerHandler().playerEntity;


                  @Override
                  public void run() {
                       
                       
                       
                        System.out.println("Packet Recieved");
                        if(player.getItemInUse().getItem() == CustomItems.noiseFill && player.isSneaking()) {



                              ItemStack stack = player.getItemInUse();

                              NBTTagCompound subTag = stack.getTagCompound();

                              subTag.setDouble("percentage", subTag.getDouble("percentage") + 0.1);

                              stack.setTagCompound(subTag);
                        } else {
                              return;
                        }

                  }

            });

            return null;
      }



}

Link to comment
Share on other sites

So I need to cancel the event, if the player is holding the Item and sneaking, but I don't know how to get the EntityPlayerMP object.

public class MouseScroll {

      @SideOnly(Side.CLIENT)
      @SubscribeEvent
      public void scroll(MouseEvent event)
      {
           

            EntityPlayerMP player = //what do I put here?

            System.out.println(player.getItemInUse());
            if(player.getItemInUse() != null) {
                  if(player.getItemInUse().getItem() == CustomItems.noiseFill && player.isSneaking()) {
                        if(event.dwheel > 0)
                        {
                              CreativePlus.network.sendToServer(new NoisePacket(1));
                              System.out.println("Packet 1 Sent");
                              event.setCanceled(true);
                        }
                        else if(event.dwheel < 0)
                        {

                              CreativePlus.network.sendToServer(new NoisePacket(2));
                              System.out.println("Packet 2 Sent");
                              event.setCanceled(true);

                        }

                  }

            }


      }

}

Link to comment
Share on other sites

I hope you mean is not sneaking or holding the item, but there since you are performing on the client again you should use EntityPlayerSP.

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

Umm no I want to cancel the event, so that the scrolling doesn't switch to another Item, and I only want to do that if the player is sneaking

 

EDIT: Nevermind me, I just noticed that getItemInUse is the wrong function to use

 

EDIT2: It all works!

Link to comment
Share on other sites

Umm no I want to cancel the event, so that the scrolling doesn't switch to another Item, and I only want to do that if the player is sneaking

 

EDIT: Nevermind me, I just noticed that getItemInUse is the wrong function to use

Then you may want to look at this in your message.

if(player.getItemInUse().getItem() == CustomItems.noiseFill && player.isSneaking()) {

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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • LINK DAFTAR : KLIK DISINI LINK DAFTAR : KLIK DISINI   Slot SHOPEEPAY adalah situs slot deposit SHOPEEPAY Ribu paling gacor di indonesia pada tahun 2023. Situs slot SHOPEEPAY kini menyediakan layanan deposit pakai aplikasi shopee yang amat gacor sampai detik ini. MAXWINBET77 Situs slot SHOPEEPAY saat ini menggunakan layanan deposit dari e-wallet shopee adalah alat pembayaran dempet digital lewat SHOPEEPAY. Slot SHOPEEPAY saat ini menjadi situs slot ternama dengan banyak nya keunggulan di dalam situs slot SHOPEEPAY ini. Slot deposit SHOPEEPAY hadir untuk menyedia kan sarana deposit paling termurah di indonesia. Deposit slot SHOPEEPAY hanya dengan modal 5000 Ribu saja kamu sudah bisa mainkan semua jenis game yang ada di dalam situs slot SHOPEEPAY Ribu seperti gates of olympus, mahjong ways 2, Legacy of Kong Maxways dan Koi Gate yang saat ini banyak sekali di cari orang karna tingkatan kemenangan nya paling besar dan mudah jackpot. TRIK DAN TRIK BERMAIN PALING JITU / SLOT DEPOSIT SHOPEEPAY Pilih Game Slot Gacor Yang Sesuai Dengan Preferensi Dan Anggaran Anda Ada banyak tipe game slot gacor yang bisa Anda pilih, mulai dari yang bertema klasik, petualangan, mitologi, sampai film. Pilihlah game slot gacor yang menarik bagi anda dan cocok dengan volatilitas dan RTP yang anda inginkan. Volatilitas yakni tingkat risiko dan varians dalam permainan, sedangkan RTP yakni prosentase pengembalian kepada pemain. Pilihlah game slot gacor dengan volatilitas dan RTP yang pantas dengan anggaran dan tujuan anda. Manajemen Bankroll Yang Baik Bankroll ialah jumlah uang yang Anda siapkan untuk bermain slot gacor. Penting bagi anda untuk mengelola bankroll anda dengan bagus supaya tidak kehabisan uang atau terjebak dalam kecanduan judi. Tentukan jumlah maksimal yang mau anda pertaruhkan per sesi, per hari, atau per minggu, dan jangan melebihi batas tersebut. Juga, tentukan jumlah kemenangan yang mau anda capai atau jumlah kerugian yang bisa anda terima, dan stop bermain dikala mencapai salah satu dari keduanya. Manfaatkan Bonus Dan Promosi Situs slot gacor Neobank menawarkan bonus dan promosi menarik kepada para pemainnya, seperti bonus new member, bonus deposit, bonus cashback, bonus referral, bonus turnover, jackpot progresif, turnamen, freebet, dan lainnya. Manfaatkan bonus dan promosi ini untuk meningkatkan modal dan peluang kemenangan anda. Tetapi, pastikan juga untuk membaca syarat dan ketentuan yang berlaku agar tidak terjebak dalam prasyarat taruhan atau batasan penarikan yang tidak menguntungkan. Pelajari Paytable Dan Fitur Game Sebelum bermain slot gacor Neobank, pastikan Anda mempelajari paytable dan fitur game. Paytable yaitu tabel yang menonjolkan skor masing masing simbol dan kombinasi kemenangan dalam game. Fitur game yaitu fitur tambahan yang bisa meningkatkan kesempatan kemenangan Anda, seperti wild, scatter, cuma cuma spins, bonus games, multiplier, dsb. Dengan mempelajari paytable dan fitur game, Anda bisa mengenal simbol mana yang semestinya Anda targetkan ketika bermain.
    • Link Daftar : KLIK DISINI  Link Login : KLIK DISINI  Link RTP   : KLIK DISINI  Link Gacor Slot Dana   : KLIK DISINI slot deposit dana 5000 ribu via dana adalah permainan slot dana gacor dengan menyediakan slot server thailand deposit dana. dan slot deposit dana adalah slot terbesar di thailand. anda cukup daftar disini dan mainkan disini slot deposit 5000 ribu via dana sudah dipastikan dengan deposit dana akan membuat akun anda menjadi akun special. situs deposit dana adalah situs yang terpercaya dan terakurat. Slot dana merupakan situs slot deposit dana yang sangat trending dan sangat dikenal luas di masyarakat. dengan adanya MAXWINBET77 anda bisa mendapatkan keuntungan besar setiap hari tanpa adanya potongan  yang pastinya menguntungkan bagi anda. situs slot dana  maxwinbet77 adalah situs slot dana terbaik 2024 dan dijamin mudah maxwin. PERMAINAN YANG ADA DI SLOT DANA MAXWINBET77: - TOGEL 4D - SLOT ONLINE - LIVE CASINO - SPORTSBOOK - ARCADE TEMBAK IKAN - SABUNG AYAM Saat Ini Slot Dana Maxwinbet77 Menyediakan Bonus Berupa : - Bonus New Member - Bonus Deposit Harian - Bonus Cashback - Bonus 2D TERBALIK - Bonus Prize 2 & Prize 3 - Bonus Refferal DAFATR DISINI
    • LINK DAFTAR : KLIK DISINI LINK DAFTAR : KLIK DISINI   Slot seabank meruapakan salah satu situs slot paling gacor deposit seabank 100% mudah maxwin, hari ini situs slot seabank meghadirkan permainan slot dengan kemudahan bergabung hanya dengan menggunakan aplikasi Seabank langsung bisa join dengan bandar slot Seabank terbaik dan terpercaya no.1 di indonesia. Slot Seabank resmi di daftar situs slot deposit pakai Seabank 5000 Gampang Maxwin dimana aplikasi Seabank tersebut telah sanggat membantu para bosku untuk bermain slot online deposit via Seabank saat ini slot Seabank ini membantu dalam mempermudah transaksi disaat bosku ingin deposit melakukan pembayaran. kini orang orang ingin bermian judi online khusus nya games slot tidak perlu khawatir lagi apabila tidak memilikui saldo di ATM, sebab dengan adanya aplikasi Seabank sudah memberikan dampak signifikan buat perjudian di indonesia. Selain slot pakai Seabank, terdapat beberapa aplikasi e-wallet yang dapat di gunakan untuk bertansaksi antara lain, slot deposit 5000 Seabank, slot dana, slot ovo, slot pulsa tanpa potongan, dan slot shopeepay mudah menang bisa bosku pakai untuk setoran Seabank resmi terbaru. intinya slot online deposit Seabank memberikan jamianan kemudahan saat main games slot gacor uang asli terbaik di indonesia bos.
    • LINK DAFTAR : KLIK DISINI LINK DAFTAR : KLIK DISINI   Slot deposit bank bsi merupakan salah satu situs slot gacor deposit bank bsi 24 jam mudah maxwin tanpa batas. hari ini slot deposit bank bsi menawarkan bonus terbesar untuk player yang sudah bergabung di situs slot bank bsi ini, dengan ada nya slot bank bsi sanget mempermudah player untuk melakukan transaksi deposit dengan bank bsi. Sebagai Situs Slot Deposit Bank Bsi meyediakan banyak permainan seperti slot online, live casino, sabung ayam, tembak ikan, sportbook semua game tersebuat sangat aman dan terpercaya. Beramin slot bank bsi sangat mudah hanya dengan niminal deposit 5000 ribu saja anda sudah bisa bermain di semua game yang sudah di sediakan oleh situs slot bank bsi. Slot bank bsi adalah saranan untuk Pemain yang mencari pengalaman bermain slot gacor sekarang dapat menemukan metode pembayaran beragam di berbagai situs slot gacor yang tersebar luas di seluruh negeri. Munculnya situs Slot Bank BSI, kini para pemain dapat menikmati kemudahan dan kenyamanan dalam melakukan transaksi pembayaran. Bahkan memungkinkan pemain untuk fokus sepenuhnya pada permainan yang mereka nikmati sepanjang waktu. Ini adalah langkah penting dalam memperluas aksesibilitas judi slot online di Indonesia dan memberikan pengalaman bermain yang lebih baik kepada para pecinta slot gacor.    
    • Sometimes love could be the worst experience. you get to love and trust your partner only to feel regret over it. i have been married for 7 years now and i found some sudden change in my partner attitude, i tried talking about it but he complains i'm nagging a lot . i tried to ignore his attitude but it became unbearable so i was advised to hire a hacker to help me gain access to his phone so i had know if he is cheating or not so i was introduced to [ Remote spy hacker @ g m ail . c o m ] and this expert helped me gain access to his phone without his notice. i got to see his messages, photos, call recordings and many more . Now i can see his cheating and that's the reason for the attitude all along.
  • Topics

×
×
  • Create New...

Important Information

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