Jump to content

[SOLVED] Current Item Change & Chat Send Event


Zelnehlun

Recommended Posts

Hello,

 

I have two questions regarding switching the current item in hand and being notified when the player sends a chat message to the server (presses enter in chat).

 

Q1: Is there a way to disable changing the current item in hand with the num keys?

The code is in the Minecraft class or more specifically in the tick loop there is a for which seems to iterate 0 to 9 and checks if the corresponding key is pressed.

Without editing the base class I would like to disable this behavior (switching by scrolling the mouse wheel should still be possible)

 

Q2: Is there a ChatSendEvent?

I would like to retrieve the message a player is about to send to the server.

This is because I need to declare a client-side-only command, the server should not know about this command.

(If this is not possible, no problem the first question is more important ;))

 

 

Thank you for reading =)

Link to comment
Share on other sites

Hi

 

I think it might be rather difficult to be honest.  I don't know of a way to intercept the call to Keyboard.getKeyDown to stop 0..8 from changing theplayer.inventory.currentItem.  You might be able to put some code into

FMLCommonHandler.instance().onPostClientTick();

to check whether the currentItem has changed, and somehow figure out whether 0..8 caused it, and if so undo it.  I doubt this would be robust unfortunately.

 

There seem to be more opportunities to intercept a chat message to the server, in each case it would mean extending one of the base classes and replacing references to it in the code; for example

class MyEntityClientPlayerMP extends EntityClientPlayerMP {

@override 
    public void sendChatMessage(String par1Str)
    {
        if (par1Str == "mycommand") {
            // do my command here
        } else {
          this.sendQueue.addToSendQueue(new Packet3Chat(par1Str));
        }
    }
}

and somewhere in your code you would need to set

Minecraft.getMinecraft().thePlayer = new MyEntityClientPlayerMP(Minecraft.getMinecraft().thePlayer);

 

where you write the copy constructor to copy the EntityClientPlayerMP into your MyEntityClientPlayerMP.

 

Disclaimer: it looks like this should work but I've never tried it.

 

-TGG

Link to comment
Share on other sites

@TheGreyGhost

 

Works like a charm actually.

I listen for the tick start event and put the current item into a variable, in the tick end event I check if the current item has changed.

If it changed lookup keys from 1 to 9 and reset it to the state before the tick if one of the keys is down.

Of course, sometimes (very rare) it misses a key event and changes the item but that is not too bad.

Thank you for your help!

 

 

Updating Forge to be able to use the ClientCommandHandler, I will edit this post with the source code if someone looks into this thread ;)

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



×
×
  • Create New...

Important Information

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