Jump to content

Recommended Posts

Posted

Hi,

 

I currently have a GUI which opens when a key is pressed.

But the key binding also intercepts the key when the player write in the chat.

 

Which condition should i impose to check if the chat is used and avoid opening my GUI ?

 

thanks.

 

NB : current code is

package PLCmods.robotica.commands;

import java.util.EnumSet;

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.EntityPlayer;

import org.lwjgl.input.Keyboard;

import PLCmods.robotica.Robotica;
import PLCmods.trashbin.LoggerKeyTickHandler;
import cpw.mods.fml.client.registry.KeyBindingRegistry;
import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler;
import cpw.mods.fml.common.TickType;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;

public class LoggerKeys extends KeyHandler
{
    private EnumSet tickType = EnumSet.of(TickType.CLIENT);
    private boolean open;
    
    public static final KeyBinding[] key = {new KeyBinding("Logger GUI", Keyboard.KEY_L), new KeyBinding("Logger switch", Keyboard.KEY_O)};
    public static final boolean[] repeat = {false,false};

    public LoggerKeys()
    {
        super(key,repeat);
        KeyBindingRegistry.registerKeyBinding(this);
        open = false;
    }

    @Override
    public String getLabel()
    {
        return "Logger Key";
    }

    @Override
    public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat)
    {
        if(!tickEnd)
        {
            EntityClientPlayerMP e = Minecraft.getMinecraft().thePlayer;
            
            if(kb.keyCode == Keyboard.KEY_L)
            {
                if(open)
                    e.closeScreen();
                else
                    e.openGui(Robotica.modInstance, Robotica.GUI.LogControl, e.worldObj, 0, 0, 0);
                
                open = !open;
            }
            else if(kb.keyCode == Keyboard.KEY_O)
                e.sendChatMessage("/log switch");
        }
    }

    @Override
    public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd)
    {}

    @Override
    public EnumSet<TickType> ticks()
    {
        return tickType;
    }
}

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.