package net.vulkanmod.render.chunk.util;

import net.minecraft.class_2350;
import net.minecraft.class_2350.class_2351;

public class Util {
   public static final class_2350[] DIRECTIONS = class_2350.values();
   public static final class_2350[] XZ_DIRECTIONS = getXzDirections();

   public static byte getOppositeDirIdx(byte idx) {
      return (byte)((idx & 1) != 0 ? idx - 1 : idx + 1);
   }

   private static class_2350[] getXzDirections() {
      class_2350[] directions = new class_2350[4];
      int i = 0;

      for(class_2350 direction : class_2350.values()) {
         if (direction.method_10166() == class_2351.field_11048 || direction.method_10166() == class_2351.field_11051) {
            directions[i] = direction;
            ++i;
         }
      }

      return directions;
   }

   public static long posLongHash(int x, int y, int z) {
      return (long)x & 65535L | (long)z << 16 & 4294901760L | (long)y << 32 & 281470681743360L;
   }

   public static int flooredLog(int v) {
      assert v > 0;

      int log = 30;

      for(int t = 1073741824; (v & t) == 0; --log) {
         t >>= 1;
      }

      return log;
   }

   public static long align(long l, int alignment) {
      if (alignment == 0) {
         return l;
      } else {
         long r = l % (long)alignment;
         return r != 0L ? l + (long)alignment - r : l;
      }
   }
}
