Package vazkii.botania.client.render.item

Source Code of vazkii.botania.client.render.item.RenderTransparentItem

/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Aug 6, 2014, 10:04:57 PM (GMT)]
*/
package vazkii.botania.client.render.item;

import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraftforge.client.IItemRenderer;

import org.lwjgl.opengl.GL11;

public class RenderTransparentItem implements IItemRenderer {

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

  @Override
  public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
    return helper == ItemRendererHelper.ENTITY_ROTATION || helper == ItemRendererHelper.ENTITY_BOBBING;
  }

  @Override
  public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
    switch(type) {
    case ENTITY : {
      GL11.glPushMatrix();
      GL11.glTranslatef(-0.5F, 0F, 0F);
      if(item.isOnItemFrame())
        GL11.glTranslatef(0F, -0.3F, 0.01F);
      render(item);
      GL11.glPopMatrix();
      break;
    }
    case EQUIPPED : {
      render(item);
      break;
    }
    case EQUIPPED_FIRST_PERSON : {
      render(item);
      break;
    }
    default : break;
    }
  }

  public static void render(ItemStack item) {
    int dmg = item.getItemDamage();
    IIcon icon = item.getItem().getIconFromDamageForRenderPass(dmg, 0);
    float f = icon.getMinU();
    float f1 = icon.getMaxU();
    float f2 = icon.getMinV();
    float f3 = icon.getMaxV();
    float scale = 1F / 16F;

    GL11.glPushMatrix();
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4f(1F, 1F, 1F, 1F);
    ItemRenderer.renderItemIn2D(Tessellator.instance, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), scale);

    GL11.glDisable(GL11.GL_BLEND);
    GL11.glPopMatrix();

    GL11.glColor4f(1F, 1F, 1F, 1F);
  }


}
TOP

Related Classes of vazkii.botania.client.render.item.RenderTransparentItem

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.