    001package net.minecraft.client.settings;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import java.util.ArrayList;
    006import java.util.Iterator;
    007import java.util.List;
    008import net.minecraft.util.IntHashMap;
    009
    010@SideOnly(Side.CLIENT)
    011public class KeyBinding
    012{
    013    public static List keybindArray = new ArrayList();
    014    public static IntHashMap hash = new IntHashMap();
    015    public String keyDescription;
    016    public int keyCode;
    017
    018    /** because _303 wanted me to call it that(Caironater) */
    019    public boolean pressed;
    020    public int pressTime = 0;
    021
    022    public static void onTick(int par0)
    023    {
    024        KeyBinding keybinding = (KeyBinding)hash.lookup(par0);
    025
    026        if (keybinding != null)
    027        {
    028            ++keybinding.pressTime;
    029        }
    030    }
    031
    032    public static void setKeyBindState(int par0, boolean par1)
    033    {
    034        KeyBinding keybinding = (KeyBinding)hash.lookup(par0);
    035
    036        if (keybinding != null)
    037        {
    038            keybinding.pressed = par1;
    039        }
    040    }
    041
    042    public static void unPressAllKeys()
    043    {
    044        Iterator iterator = keybindArray.iterator();
    045
    046        while (iterator.hasNext())
    047        {
    048            KeyBinding keybinding = (KeyBinding)iterator.next();
    049            keybinding.unpressKey();
    050        }
    051    }
    052
    053    public static void resetKeyBindingArrayAndHash()
    054    {
    055        hash.clearMap();
    056        Iterator iterator = keybindArray.iterator();
    057
    058        while (iterator.hasNext())
    059        {
    060            KeyBinding keybinding = (KeyBinding)iterator.next();
    061            hash.addKey(keybinding.keyCode, keybinding);
    062        }
    063    }
    064
    065    public KeyBinding(String par1Str, int par2)
    066    {
    067        this.keyDescription = par1Str;
    068        this.keyCode = par2;
    069        keybindArray.add(this);
    070        hash.addKey(par2, this);
    071    }
    072
    073    public boolean isPressed()
    074    {
    075        if (this.pressTime == 0)
    076        {
    077            return false;
    078        }
    079        else
    080        {
    081            --this.pressTime;
    082            return true;
    083        }
    084    }
    085
    086    private void unpressKey()
    087    {
    088        this.pressTime = 0;
    089        this.pressed = false;
    090    }
    091}