Package vazkii.botania.client.render.entity

Source Code of vazkii.botania.client.render.entity.RenderPixie

/**
* This class was created by <Adubbz>. 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 @ [? (GMT)]
*/
package vazkii.botania.client.render.entity;

import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.ARBShaderObjects;
import org.lwjgl.opengl.GL11;

import vazkii.botania.api.internal.ShaderCallback;
import vazkii.botania.client.core.helper.ShaderHelper;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.client.model.ModelPixie;
import vazkii.botania.common.entity.EntityPixie;

public class RenderPixie extends RenderLiving {

  ShaderCallback callback = new ShaderCallback() {

    @Override
    public void call(int shader) {
      // Frag Uniforms
      int disfigurationUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "disfiguration");
      ARBShaderObjects.glUniform1fARB(disfigurationUniform, 0.025F);

      // Vert Uniforms
      int grainIntensityUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "grainIntensity");
      ARBShaderObjects.glUniform1fARB(grainIntensityUniform, 0.05F);
    }
  };

  public RenderPixie() {
    super(new ModelPixie(), 0.25F);
    setRenderPassModel(new ModelPixie());
    shadowSize = 0.0F;
  }

  @Override
  protected ResourceLocation getEntityTexture(Entity entity) {
    return new ResourceLocation(LibResources.MODEL_PIXIE);
  }

  @Override
  public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9) {
    EntityPixie pixie = (EntityPixie) par1Entity;

    if(pixie.getType() == 1)
      ShaderHelper.useShader(ShaderHelper.doppleganger, callback);
    super.doRender(par1Entity, par2, par4, par6, par8, par9);
    if(pixie.getType() == 1)
      ShaderHelper.releaseShader();
  }

  protected int setPixieBrightness(EntityPixie par1EntityPixie, int par2, float par3) {
    if (par2 != 0)
      return -1;
    else {
      bindTexture(getEntityTexture(par1EntityPixie));
      float f1 = 1.0F;
      GL11.glEnable(GL11.GL_BLEND);
      GL11.glDisable(GL11.GL_ALPHA_TEST);
      GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);

      if (par1EntityPixie.isInvisible())
        GL11.glDepthMask(false);
      else
        GL11.glDepthMask(true);

      char c0 = 61680;
      int j = c0 % 65536;
      int k = c0 / 65536;
      OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, j / 1.0F, k / 1.0F);
      GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
      GL11.glColor4f(1.0F, 1.0F, 1.0F, f1);
      return 1;
    }
  }

  @Override
  protected int shouldRenderPass(EntityLivingBase par1EntityLivingBase, int par2, float par3) {
    return setPixieBrightness((EntityPixie)par1EntityLivingBase, par2, par3);
  }
}
TOP

Related Classes of vazkii.botania.client.render.entity.RenderPixie

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.