getOrDefault instead of custom hashmap
This commit is contained in:
		| @@ -1,6 +1,5 @@ | ||||
| package baritone.bot; | ||||
|  | ||||
| import baritone.bot.utils.DefaultHashMap; | ||||
| import baritone.bot.utils.Helper; | ||||
| import net.minecraft.client.settings.KeyBinding; | ||||
| import org.lwjgl.input.Keyboard; | ||||
| @@ -23,12 +22,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 DefaultHashMap<>(false); | ||||
|     private final Map<KeyBinding, Boolean> inputForceStateMap = new HashMap<>(); | ||||
|  | ||||
|     /** | ||||
|      * Maps keycodes to whether or not we are forcing their state down. | ||||
|      */ | ||||
|     private final Map<Integer, Boolean> keyCodeForceStateMap = new DefaultHashMap<>(false); | ||||
|     private final Map<Integer, Boolean> keyCodeForceStateMap = new HashMap<>(); | ||||
|  | ||||
|     /** | ||||
|      * Returns whether or not we are forcing down the specified {@link KeyBinding}. | ||||
| @@ -37,7 +36,7 @@ public final class InputOverrideHandler implements Helper { | ||||
|      * @return Whether or not it is being forced down | ||||
|      */ | ||||
|     public final boolean isInputForcedDown(KeyBinding key) { | ||||
|         return inputForceStateMap.get(key); | ||||
|         return inputForceStateMap.getOrDefault(key, false); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -56,7 +55,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.get(keyCode); | ||||
|         return Keyboard.isKeyDown(keyCode) || keyCodeForceStateMap.getOrDefault(keyCode, false); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -6,6 +6,10 @@ import java.util.Collection; | ||||
| import java.util.List; | ||||
|  | ||||
| public interface IPath { | ||||
|     /** | ||||
|      * | ||||
|      */ | ||||
|     List<BlockPos> movements(); | ||||
|  | ||||
|     /** | ||||
|      * All positions along the way. | ||||
|   | ||||
| @@ -1,17 +1,17 @@ | ||||
| package baritone.bot.pathing.action; | ||||
|  | ||||
| import baritone.bot.InputOverrideHandler.Input; | ||||
| import baritone.bot.utils.DefaultHashMap; | ||||
| import net.minecraft.util.Tuple; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
|  | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
|  | ||||
| public class ActionState { | ||||
|  | ||||
|     protected ActionStatus status; | ||||
|     public ActionGoal goal; | ||||
|     protected final Map<Input, Boolean> inputState = new DefaultHashMap<>(false); | ||||
|     protected final Map<Input, Boolean> inputState = new HashMap<>(); | ||||
|  | ||||
|     public ActionState setStatus(ActionStatus status) { | ||||
|         this.status = status; | ||||
| @@ -53,10 +53,14 @@ public class ActionState { | ||||
|     } | ||||
|  | ||||
|     public ActionState setInput(Input input, boolean forced) { | ||||
|         this.inputState.put(input, forced); | ||||
|         inputState.put(input, forced); | ||||
|         return this; | ||||
|     } | ||||
|  | ||||
|     public boolean getInput(Input input) { | ||||
|         return inputState.getOrDefault(input, false); | ||||
|     } | ||||
|  | ||||
|     public enum ActionStatus { | ||||
|         WAITING, RUNNING, SUCCESS, UNREACHABLE, FAILED; | ||||
|     } | ||||
|   | ||||
| @@ -1,17 +0,0 @@ | ||||
| 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; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user