Add default-value HashMap
This commit is contained in:
parent
b6b67fdd71
commit
cb238ec130
@ -1,5 +1,6 @@
|
||||
package baritone.bot;
|
||||
|
||||
import baritone.bot.utils.DefaultHashMap;
|
||||
import baritone.bot.utils.Helper;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
@ -22,12 +23,12 @@ public final class InputOverrideHandler implements Helper {
|
||||
/**
|
||||
* Maps keybinds to whether or not we are forcing their state down.
|
||||
*/
|
||||
private final Map<KeyBinding, Boolean> inputForceStateMap = new HashMap<>();
|
||||
private final Map<KeyBinding, Boolean> inputForceStateMap = new DefaultHashMap<>(false);
|
||||
|
||||
/**
|
||||
* Maps keycodes to whether or not we are forcing their state down.
|
||||
*/
|
||||
private final Map<Integer, Boolean> keyCodeForceStateMap = new HashMap<>();
|
||||
private final Map<Integer, Boolean> keyCodeForceStateMap = new DefaultHashMap<>(false);
|
||||
|
||||
/**
|
||||
* Returns whether or not we are forcing down the specified {@link KeyBinding}.
|
||||
@ -36,7 +37,7 @@ public final class InputOverrideHandler implements Helper {
|
||||
* @return Whether or not it is being forced down
|
||||
*/
|
||||
public final boolean isInputForcedDown(KeyBinding key) {
|
||||
return inputForceStateMap.computeIfAbsent(key, k -> false);
|
||||
return inputForceStateMap.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,7 +56,7 @@ public final class InputOverrideHandler implements Helper {
|
||||
* @return Whether or not the specified key is down or overridden.
|
||||
*/
|
||||
public boolean isKeyDown(int keyCode) {
|
||||
return Keyboard.isKeyDown(keyCode) || keyCodeForceStateMap.computeIfAbsent(keyCode, k -> false);
|
||||
return Keyboard.isKeyDown(keyCode) || keyCodeForceStateMap.get(keyCode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,8 +0,0 @@
|
||||
package baritone.bot.pathing;
|
||||
|
||||
public class State {
|
||||
|
||||
public State() {
|
||||
|
||||
}
|
||||
}
|
14
src/main/java/baritone/bot/utils/DefaultHashMap.java
Normal file
14
src/main/java/baritone/bot/utils/DefaultHashMap.java
Normal file
@ -0,0 +1,14 @@
|
||||
package baritone.bot.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class DefaultHashMap<K,V> extends HashMap<K,V> {
|
||||
protected V defaultValue;
|
||||
public DefaultHashMap(V defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
@Override
|
||||
public V get(Object k) {
|
||||
return containsKey(k) ? super.get(k) : defaultValue;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user