<commit_before>package crazypants.enderio.item.darksteel;

import java.awt.Color;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.IItemRenderer;

import org.lwjgl.opengl.GL11;

import cofh.api.energy.IEnergyContainerItem;
import crazypants.render.ColorUtil;
import crazypants.render.RenderUtil;
import crazypants.vecmath.Vector4f;

public class PoweredItemRenderer implements IItemRenderer {

  private RenderItem ri = new RenderItem();

  @Override
  public boolean handleRenderType(ItemStack item, ItemRenderType type) {
    return type == ItemRenderType.INVENTORY;
  }

  @Override
  public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
    return false;
  }

  @Override
  public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
    if(data != null && data.length > 0) {
      renderToInventory(item, (RenderBlocks) data[0]);
    }
  }

  public void renderToInventory(ItemStack item, RenderBlocks renderBlocks) {

    Minecraft mc = Minecraft.getMinecraft();
    ri.renderItemIntoGUI(mc.fontRenderer, mc.getTextureManager(), item, 0, 0, true);
    GL11.glDisable(GL11.GL_LIGHTING);

    if(isJustCrafted(item)) {
      return;
    }
    
    boolean hasEnergyUpgrade = EnergyUpgrade.loadFromItem(item) != null;
    int y = hasEnergyUpgrade ? 12 : 13;
    int bgH = hasEnergyUpgrade ? 4 : 2;
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    RenderUtil.renderQuad2D(2, y, 0, 13, bgH, ColorUtil.getRGB(Color.black));

    double maxDam = item.getMaxDamage();
    double dispDamage = item.getItemDamageForDisplay();
    y = hasEnergyUpgrade ? 14 : 13;
    renderBar(y, maxDam, dispDamage, Color.green, Color.red);

    if(hasEnergyUpgrade) {
      IEnergyContainerItem armor = (IEnergyContainerItem) item.getItem();
      maxDam = armor.getMaxEnergyStored(item);
      dispDamage = armor.getEnergyStored(item);
      y = 12;
      Color color = new Color(0x2D, 0xCE, 0xFA); // electric blue
      renderBar2(y, maxDam, maxDam - dispDamage, color, color);
    }

    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    GL11.glEnable(GL11.GL_LIGHTING);
  }

  private boolean isJustCrafted(ItemStack item) {
    return EnergyUpgrade.loadFromItem(item) == null && item.getItemDamageForDisplay() == 0;
  }

  private void renderBar2(int y, double maxDam, double dispDamage, Color full, Color empty) {
    double ratio = dispDamage / maxDam;
    Vector4f fg = ColorUtil.toFloat(full);
    Vector4f ec = ColorUtil.toFloat(empty);
    fg.interpolate(ec, (float) ratio);
    int barLength = (int) Math.round(12.0 * (1 - ratio));    
    RenderUtil.renderQuad2D(2, y, 0, barLength, 1, fg);<commit_msg>Add dark blue bg bar to charge bar<commit_after>package crazypants.enderio.item.darksteel;

import java.awt.Color;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.IItemRenderer;

import org.lwjgl.opengl.GL11;

import cofh.api.energy.IEnergyContainerItem;
import crazypants.render.ColorUtil;
import crazypants.render.RenderUtil;
import crazypants.vecmath.Vector4f;

public class PoweredItemRenderer implements IItemRenderer {

  private RenderItem ri = new RenderItem();

  @Override
  public boolean handleRenderType(ItemStack item, ItemRenderType type) {
    return type == ItemRenderType.INVENTORY;
  }

  @Override
  public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
    return false;
  }

  @Override
  public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
    if(data != null && data.length > 0) {
      renderToInventory(item, (RenderBlocks) data[0]);
    }
  }

  public void renderToInventory(ItemStack item, RenderBlocks renderBlocks) {

    Minecraft mc = Minecraft.getMinecraft();
    ri.renderItemIntoGUI(mc.fontRenderer, mc.getTextureManager(), item, 0, 0, true);
    GL11.glDisable(GL11.GL_LIGHTING);

    if(isJustCrafted(item)) {
      return;
    }
    
    boolean hasEnergyUpgrade = EnergyUpgrade.loadFromItem(item) != null;
    int y = hasEnergyUpgrade ? 12 : 13;
    int bgH = hasEnergyUpgrade ? 4 : 2;
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    RenderUtil.renderQuad2D(2, y, 0, 13, bgH, ColorUtil.getRGB(Color.black));

    double maxDam = item.getMaxDamage();
    double dispDamage = item.getItemDamageForDisplay();
    y = hasEnergyUpgrade ? 14 : 13;
    renderBar(y, maxDam, dispDamage, Color.green, Color.red);

    if(hasEnergyUpgrade) {
      IEnergyContainerItem armor = (IEnergyContainerItem) item.getItem();
      maxDam = armor.getMaxEnergyStored(item);
      dispDamage = armor.getEnergyStored(item);
      y = 12;
      Color color = new Color(0x2D, 0xCE, 0xFA); // electric blue
      renderBar2(y, maxDam, maxDam - dispDamage, color, color);
    }

    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    GL11.glEnable(GL11.GL_LIGHTING);
  }

  private boolean isJustCrafted(ItemStack item) {
    return EnergyUpgrade.loadFromItem(item) == null && item.getItemDamageForDisplay() == 0;
  }

  private void renderBar2(int y, double maxDam, double dispDamage, Color full, Color empty) {
    double ratio = dispDamage / maxDam;
    Vector4f fg = ColorUtil.toFloat(full);
    Vector4f ec = ColorUtil.toFloat(empty);
    fg.interpolate(ec, (float) ratio);
    Vector4f bg = ColorUtil.toFloat(Color.black);
    bg.interpolate(fg, 0.15f);
    
    int barLength = (int) Math.round(12.0 * (1 - ratio));    
    
    RenderUtil.renderQuad2D(2, y, 0, 12, 1, bg);
    RenderUtil.renderQuad2D(2, y, 0, barLength, 1, fg);
{'fraction_non_alphanumeric': 0.11306143520908622, 'fraction_numerical': 0.026157287902254345, 'mean_word_length': 3.9888412017167383, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2894497', 'n_tokens_mistral': 2085, 'n_tokens_neox': 1986, 'n_words': 425}