Package thaumic.tinkerer.client.render.item

Source Code of thaumic.tinkerer.client.render.item.RenderMobDisplay

package thaumic.tinkerer.client.render.item;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.IItemRenderer;
import org.lwjgl.opengl.GL11;
import thaumic.tinkerer.common.core.helper.EnumMobAspect;
import thaumic.tinkerer.common.item.ItemMobDisplay;

public class RenderMobDisplay implements IItemRenderer {

  @Override
  public boolean handleRenderType(ItemStack itemStack, ItemRenderType itemRenderType) {
    return true;
  }

  @Override
  public boolean shouldUseRenderHelper(ItemRenderType itemRenderType, ItemStack itemStack, ItemRendererHelper itemRendererHelper) {
    return true;
  }

  private static RenderItem renderItem = new RenderItem();

  @Override
  public void renderItem(ItemRenderType itemRenderType, ItemStack itemStack, Object... objects) {
    ItemMobDisplay item = (ItemMobDisplay) itemStack.getItem();
    EnumMobAspect aspect = item.getEntityType(itemStack);
    Entity entity = null;
    float f1 = 0.4f;
    float verticalOffset = 0.0f;
    if (aspect != null) {
      entity = EnumMobAspect.getEntityFromCache(aspect, null);
      f1 = aspect.getScale();
      verticalOffset = aspect.getVerticalOffset();
    }
    switch (itemRenderType) {

      case ENTITY:

        GL11.glPushMatrix();
        GL11.glTranslated(0.5, 0.2 + verticalOffset, 0.5);
        GL11.glRotatef(-30.0F, 1.0F, 0.0F, 0.0F);
        GL11.glTranslatef(0.0F, -0.4F, 0.0F);
        GL11.glScalef(f1, f1, f1);
        EntityItem eItem = (EntityItem) objects[1];
        if (entity != null) {
          entity.worldObj = (Minecraft.getMinecraft() != null) ? Minecraft.getMinecraft().theWorld : null;
          if (entity.worldObj != null) {
            Render renderer = RenderManager.instance.getEntityRenderObject(entity);
            entity.setWorld(eItem.worldObj);
            entity.copyLocationAndAnglesFrom(eItem);
            if (renderer != null && renderer.getFontRendererFromRenderManager() != null) {
              GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
              //if (renderWithLighting) RenderUtils.enableLightmap();
              renderer.doRender(entity, 0, 0, 0, 0, 0);
              GL11.glPopAttrib();
            }

          }
          entity.worldObj = null;
        }
        GL11.glPopMatrix();
      case EQUIPPED:
        break;
      case EQUIPPED_FIRST_PERSON:
        break;
      case INVENTORY:
        GL11.glPushMatrix();
        GL11.glTranslated(0.5, 0.2 + verticalOffset, 0.5);
        GL11.glRotatef(-30.0F, 1.0F, 0.0F, 0.0F);
        GL11.glTranslatef(0.0F, -0.4F, 0.0F);
        GL11.glScalef(f1, f1, f1);
        if (entity != null) {
          entity.worldObj = (Minecraft.getMinecraft() != null) ? Minecraft.getMinecraft().theWorld : null;
          if (entity.worldObj != null) {
            Render renderer = RenderManager.instance.getEntityRenderObject(entity);
            if (renderer != null && renderer.getFontRendererFromRenderManager() != null) {
              GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
              //if (renderWithLighting) RenderUtils.enableLightmap();
              renderer.doRender(entity, 0, 0, 0, 0, 0);
              GL11.glPopAttrib();
            }

          }
          entity.worldObj = null;
        }
        GL11.glPopMatrix();

      case FIRST_PERSON_MAP:
        break;
    }
  }
}
TOP

Related Classes of thaumic.tinkerer.client.render.item.RenderMobDisplay

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.