Example #1
0
  public boolean checkPlayerCollision(Vector3f location) {
    int[] chunk =
        new int[] {
          ((int) (-location.x / WorldChunk.SIZE)),
          ((int) (-location.y / WorldChunk.SIZE)),
          ((int) (-location.z / WorldChunk.SIZE))
        };

    // System.out.println(chunk[0] + " " + chunk[1] + " " + chunk[2]);

    Voxel[] player = new Voxel[1];

    for (int i = 0; i < 1; i++) {
      player[i] = new Voxel(i, i, i);
      player[i].setActualPosition(-location.x, -location.y, -location.z);
    }

    WorldChunk foundChunk = null;
    for (WorldChunk c : chunks) {
      if (Arrays.equals(c.coordinates, chunk)) {
        foundChunk = c;
        break;
      }
    }

    if (foundChunk == null) {
      System.out.println("Oops");
      return false;
    }

    for (Voxel voxel : foundChunk.terrian) {
      if (voxel.shouldRender) {
        for (Voxel p : player) {
          if (voxel.hasCollidedWith(p)) {
            System.out.println("Hit");
            return true;
          }
        }
      }
    }

    return false;
  }