Tiny drive-by cleanup of action pack's onUpdate

This commit is contained in:
altrisi committed 2023-04-02 21:54:44 +02:00
1 parent 73260a220c
commit 5fcfc7aa8d
1 file changed
+5 -4
@@ -213,19 +213,20 @@ public class EntityPlayerActionPack
public void onUpdate() public void onUpdate()
{ {
Map<ActionType, Boolean> actionAttempts = new HashMap<>(); Map<ActionType, Boolean> actionAttempts = new HashMap<>();
actions.entrySet().removeIf((e) -> e.getValue().done); actions.values().removeIf(e -> e.done);
for (Map.Entry<ActionType, Action> e : actions.entrySet()) for (Map.Entry<ActionType, Action> e : actions.entrySet())
{ {
ActionType type = e.getKey();
Action action = e.getValue(); Action action = e.getValue();
// skipping attack if use was successful // skipping attack if use was successful
if (!(actionAttempts.getOrDefault(ActionType.USE, false) && e.getKey() == ActionType.ATTACK)) if (!(actionAttempts.getOrDefault(ActionType.USE, false) && type == ActionType.ATTACK))
{ {
Boolean actionStatus = action.tick(this, e.getKey()); Boolean actionStatus = action.tick(this, e.getKey());
if (actionStatus != null) if (actionStatus != null)
actionAttempts.put(e.getKey(), actionStatus); actionAttempts.put(type, actionStatus);
} }
// optionally retrying use after successful attack and unsuccessful use // optionally retrying use after successful attack and unsuccessful use
if ( e.getKey() == ActionType.ATTACK if (type == ActionType.ATTACK
&& actionAttempts.getOrDefault(ActionType.ATTACK, false) && actionAttempts.getOrDefault(ActionType.ATTACK, false)
&& !actionAttempts.getOrDefault(ActionType.USE, true) ) && !actionAttempts.getOrDefault(ActionType.USE, true) )
{ {