@Override
  public IBlockState getExtendedState(IBlockState stateIn, IBlockAccess w, BlockPos pos) {
    if (stateIn.getBlock() == null || stateIn.getBlock().getMaterial() == Material.air) {
      return stateIn;
    }
    IExtendedBlockState state = (IExtendedBlockState) stateIn;
    Variation v =
        ((BlockCarvable) state.getBlock())
            .getType()
            .getVariants()[state.getBlock().getMetaFromState(state)];
    IBlockResources res = SubBlockUtil.getResources(state.getBlock(), v);
    if (res.getType() == IBlockResources.V4 || res.getType() == IBlockResources.V9) {
      int variationSize = BlockResources.getVariationWidth(res.getType());
      int xModulus = Math.abs(pos.getX() % variationSize);
      int zModulus = Math.abs(pos.getZ() % variationSize);
      int yModules = Math.abs(pos.getY() % variationSize);
      return state
          .withProperty(XMODULES, xModulus)
          .withProperty(YMODULES, yModules)
          .withProperty(ZMODULES, zModulus);
    } else if (res.getType() == IBlockResources.NORMAL
        || res.getType() == IBlockResources.R9
        || res.getType() == IBlockResources.R4
        || res.getType() == IBlockResources.R16) {
      return stateIn;
    }

    boolean up = false;
    boolean down = false;
    boolean north = false;
    boolean south = false;
    boolean east = false;
    boolean west = false;
    boolean north_east = false;
    boolean north_west = false;
    boolean north_up = false;
    boolean north_down = false;
    boolean south_east = false;
    boolean south_west = false;
    boolean south_up = false;
    boolean south_down = false;
    boolean east_up = false;
    boolean east_down = false;
    boolean west_up = false;
    boolean west_down = false;

    if (areBlocksEqual(state, w.getBlockState(pos.up()))) {
      up = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.down()))) {
      down = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.north()))) {
      north = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.south()))) {
      south = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.east()))) {
      east = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.west()))) {
      west = true;
    }

    if (areBlocksEqual(state, w.getBlockState(pos.north().east()))) {
      north_east = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.north().west()))) {
      north_west = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.north().up()))) {
      north_up = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.north().down()))) {
      north_down = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.south().east()))) {
      south_east = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.south().west()))) {
      south_west = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.south().up()))) {
      south_up = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.south().down()))) {
      south_down = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.east().up()))) {
      east_up = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.east().down()))) {
      east_down = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.west().up()))) {
      west_up = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.west().down()))) {
      west_down = true;
    }

    return state
        .withProperty(CONNECTED_UP, up)
        .withProperty(CONNECTED_DOWN, down)
        .withProperty(CONNECTED_NORTH, north)
        .withProperty(CONNECTED_SOUTH, south)
        .withProperty(CONNECTED_EAST, east)
        .withProperty(CONNECTED_WEST, west)
        .withProperty(CONNECTED_NORTH_EAST, north_east)
        .withProperty(CONNECTED_NORTH_WEST, north_west)
        .withProperty(CONNECTED_NORTH_UP, north_up)
        .withProperty(CONNECTED_NORTH_DOWN, north_down)
        .withProperty(CONNECTED_SOUTH_EAST, south_east)
        .withProperty(CONNECTED_SOUTH_WEST, south_west)
        .withProperty(CONNECTED_SOUTH_UP, south_up)
        .withProperty(CONNECTED_SOUTH_DOWN, south_down)
        .withProperty(CONNECTED_EAST_UP, east_up)
        .withProperty(CONNECTED_EAST_DOWN, east_down)
        .withProperty(CONNECTED_WEST_UP, west_up)
        .withProperty(CONNECTED_WEST_DOWN, west_down);
  }