private FancyDial(TextureAtlasSprite icon, PropertiesFile properties) {
    this.icon = icon;
    this.properties = properties;
    name = IconAPI.getIconName(icon);
    x0 = IconAPI.getIconX0(icon);
    y0 = IconAPI.getIconY0(icon);
    width = IconAPI.getIconWidth(icon);
    height = IconAPI.getIconHeight(icon);
    scratchBuffer = ByteBuffer.allocateDirect(4 * width * height);

    int itemsTexture = TexturePackAPI.getTextureIfLoaded(TexturePackAPI.ITEMS_PNG);
    if (itemsTexture < 0) {
      logger.severe("could not get items texture");
      return;
    }
    itemsFBO = new FBO(itemsTexture, x0, y0, width, height);

    if (useScratchTexture) {
      logger.fine("rendering %s to %dx%d scratch texture", name, width, height);
      for (int i = 0; i < scratchFBO.length; i++) {
        scratchFBO[i] = new FBO(width, height);
      }
    } else {
      logger.fine("rendering %s directly to atlas", name);
    }

    boolean debug = false;
    for (int i = 0; ; i++) {
      Layer layer = newLayer(properties, "." + i);
      if (layer == null) {
        if (i > 0) {
          break;
        }
        continue;
      }
      layers.add(layer);
      debug |= layer.debug;
      logger.fine("  new %s", layer);
    }
    keyboard = new InputHandler(name, debug);
    if (layers.size() < 2) {
      logger.error("custom %s needs at least two layers defined", name);
      return;
    }

    outputFrames = properties.getInt("outputFrames", 0);

    int glError = GL11.glGetError();
    if (glError != 0) {
      logger.severe("%s during %s setup", GLU.gluErrorString(glError), name);
      return;
    }
    ok = true;
  }
 public static void setup(TextureAtlasSprite icon) {
   if (!fboSupported) {
     return;
   }
   String name = IconAPI.getIconName(icon).replaceFirst("^minecraft:items/", "");
   if (icon instanceof TextureClock && name.equals("compass")) { // 1.5 bug
     name = "clock";
   }
   if ("compass".equals(name)) {
     if (!enableCompass) {
       return;
     }
   } else if ("clock".equals(name)) {
     if (!enableClock) {
       return;
     }
   } else {
     logger.warning("ignoring custom animation for %s not compass or clock", name);
     return;
   }
   ResourceLocation resource =
       TexturePackAPI.newMCPatcherResourceLocation(
           "/misc/" + name + ".properties", "dial/" + name + ".properties");
   if (TexturePackAPI.hasResource(resource)) {
     logger.fine("found custom %s (%s)", name, resource);
     setupInfo.put(icon, resource);
     active = true;
   }
 }
 public static boolean update(TextureAtlasSprite icon, boolean itemFrameRenderer) {
   if (!initialized) {
     logger.finer("deferring %s update until initialization finishes", IconAPI.getIconName(icon));
     return false;
   }
   if (!active) {
     return false;
   }
   int oldFB = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
   if (oldFB != 0 && warnCount < 10) {
     logger.finer(
         "rendering %s while non-default framebuffer %d is active",
         IconAPI.getIconName(icon), oldFB);
     warnCount++;
   }
   int oldTexture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
   try {
     FancyDial instance = getInstance(icon);
     return instance != null && instance.render(itemFrameRenderer);
   } finally {
     EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, oldFB);
     GLAPI.glBindTexture(oldTexture);
   }
 }