Jump to content

[SOLVED] Trouble with KeyBindings


TheRedMezek

Recommended Posts

I'm making a new mod where my first step is to make a GUI come up when a player shift-right-clicks on an EntityTameable with an open hand. This is my first time delving into key bindings and GUIs. This code

 

@EventHandler
    public void init(FMLInitializationEvent event)
    {
        shift = new KeyBinding("key.shift", Keyboard.KEY_LSHIFT, "key.categories.pettransfer");
        ClientRegistry.registerKeyBinding(shift);
    }

 

@SubscribeEvent
    public void animalClicked(EntityInteractEvent event){
        if (event.entityPlayer.worldObj.isRemote) {
            if (!event.entityPlayer.isUsingItem()) {
                if (event.target instanceof EntityTameable) {
                    System.out.println("It works!!!!!!!!!!!");
                    event.entityPlayer.openGui(Base.instance, PetGUI.GUI_ID, event.entityPlayer.worldObj, (int)event.entityPlayer.posX, (int)event.entityPlayer.posY, (int)event.entityPlayer.posZ);
                }
            }
        }
    }

 

Made it so that the player could not crouch or move down while flying. I haven't a clue how to do this correctly. I was unable to find a decent tutorial on this and had to copy some of my code from another forum thread.

Link to comment
Share on other sites

I think a better way to do is, is by using no key registration at all. But check if the player is crouching when your EntityInteract event method is called. (event.entityPlayer.isCrouching(), ore something like that).

 

Unless of course you really want to bind a specific key!

Projects:

Discontinued:

- N2ConfigAPI

- Meachanical Crafting Table

 

Latest:

- CollectionUtils

 

Coöperations:

- InGameConfigManager

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.

×
×
  • Create New...

Important Information

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