package wtf.opal.utility.player;

import java.util.List;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import wtf.opal.client.Constants;

@Environment(EnvType.CLIENT)
public final class PlayerUtility {
   public static final List<KeyBinding> MOVEMENT_KEYS = List.of(
      Constants.mc.options.forwardKey, Constants.mc.options.backKey, Constants.mc.options.leftKey, Constants.mc.options.rightKey, Constants.mc.options.jumpKey
   );

   private PlayerUtility() {
   }

   public static boolean isKeyPressed(int keyCode) {
      return InputUtil.isKeyPressed(Constants.mc.getWindow().getHandle(), keyCode);
   }

   public static boolean isKeyPressed(KeyBinding keyBinding) {
      return isKeyPressed(keyBinding.getDefaultKey().getCode());
   }

   public static void updateMovementKeyStates() {
      MOVEMENT_KEYS.forEach(k -> KeyBinding.setKeyPressed(k.getDefaultKey(), isKeyPressed(k)));
   }

   public static void unpressMovementKeyStates() {
      MOVEMENT_KEYS.forEach(k -> KeyBinding.setKeyPressed(k.getDefaultKey(), false));
   }
}
