Jump to content

Need Help with key input!


Recommended Posts

Hey, I've been doing many things in java and tried modding out. Ok so here it is, i'm trying some semi simple things. I want to add a simple jet pack to my mod, where when you press space bar you fly. I was trying to use simple Keyboard.isKeyPressed() which then i soon realized is that you cant use this on servers for some reason with packets. I do not have experience with packets if this is indeed the case. Nor do i know if this is whats needed. I looked in the crash report and it said something about keyboard not created so i used Keyboard.create() and then i keep getting more errors.


Now is there a simple way to do this or do i have to make packet handlers, etc. Now if someone could guide me in the right direction and if needed i will attach my code i'm using, just ask.


Thank you.

Link to comment
Share on other sites

Key inputs are client side only!

Try to use if(world.isRemote) above isKeyPressed().

This will ensure that code is only running client side.(It will not crash server side)

Then you have to send a packet to inform the server about you pressed the button and do other things you want.


For pakets i recommend you Diesieben tut. Its kinda easy!

You can find it in the Modder Support top page(Tutorials sticker).


Good luck!

Link to comment
Share on other sites

Ive had an error fixed using this. IT WORKS thank you soo much for pointing something obvious out to me. Ive been tryinng to mess with SideOnly because i knew it was a problem similar!


Now is this used with sounds server side not playing as well?


Link to comment
Share on other sites

If you want to play sounds only for you than client side is fine.

Just use world.playSound()

If you want to play the sound so everyone can hear it you need that packet handler.

Than just use world.playSoundAtEntity().


Glad i can help you!

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.

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.


  • Create New...

Important Information

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