Package com.flansmod.client.model

Source Code of com.flansmod.client.model.RenderVehicle

package com.flansmod.client.model;

import org.lwjgl.opengl.GL11;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.IItemRenderer.ItemRenderType;
import net.minecraftforge.client.IItemRenderer.ItemRendererHelper;

import com.flansmod.client.FlansModResourceHandler;
import com.flansmod.common.FlansMod;
import com.flansmod.common.driveables.DriveablePart;
import com.flansmod.common.driveables.DriveablePosition;
import com.flansmod.common.driveables.EntityVehicle;
import com.flansmod.common.driveables.EnumDriveablePart;
import com.flansmod.common.driveables.ItemPlane;
import com.flansmod.common.driveables.ItemVehicle;
import com.flansmod.common.driveables.PlaneType;
import com.flansmod.common.driveables.VehicleType;

public class RenderVehicle extends Render implements IItemRenderer
{
    public RenderVehicle()
    {
        shadowSize = 0.5F;
    }

    public void render(EntityVehicle vehicle, double d, double d1, double d2, float f, float f1)
    {
      bindEntityTexture(vehicle);
      VehicleType type = vehicle.getVehicleType();
        GL11.glPushMatrix();
        {
          GL11.glTranslatef((float)d, (float)d1, (float)d2);
          float dYaw = (vehicle.axes.getYaw() - vehicle.prevRotationYaw);
          for(; dYaw > 180F; dYaw -= 360F) {}
          for(; dYaw <= -180F; dYaw += 360F) {}
          float dPitch = (vehicle.axes.getPitch() - vehicle.prevRotationPitch);
          for(; dPitch > 180F; dPitch -= 360F) {}
          for(; dPitch <= -180F; dPitch += 360F) {}
          float dRoll = (vehicle.axes.getRoll() - vehicle.prevRotationRoll);
          for(; dRoll > 180F; dRoll -= 360F) {}
          for(; dRoll <= -180F; dRoll += 360F) {}
          GL11.glRotatef(180F - vehicle.prevRotationYaw - dYaw * f1, 0.0F, 1.0F, 0.0F);
          GL11.glRotatef(vehicle.prevRotationPitch + dPitch * f1, 0.0F, 0.0F, 1.0F);
      GL11.glRotatef(vehicle.prevRotationRoll + dRoll * f1, 1.0F, 0.0F, 0.0F);
      GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F);
 
      float modelScale = type.modelScale;
      GL11.glPushMatrix();
      {
        GL11.glScalef(modelScale, modelScale, modelScale);
            ModelVehicle modVehicle = (ModelVehicle)type.model;
        if(modVehicle != null)
          modVehicle.render(vehicle, f1);
       
        GL11.glPushMatrix();
        if(type.turretOrigin != null && vehicle.isPartIntact(EnumDriveablePart.turret) && vehicle.seats != null && vehicle.seats[0] != null)
        {
          dYaw = (vehicle.seats[0].looking.getYaw() - vehicle.seats[0].prevLooking.getYaw());
              for(; dYaw > 180F; dYaw -= 360F) {}
              for(; dYaw <= -180F; dYaw += 360F) {}
            float yaw = vehicle.seats[0].prevLooking.getYaw() + dYaw * f1;
           
            GL11.glTranslatef(type.turretOrigin.x, type.turretOrigin.y, type.turretOrigin.z);
          GL11.glRotatef(-yaw, 0.0F, 1.0F, 0.0F);
          GL11.glTranslatef(-type.turretOrigin.x, -type.turretOrigin.y, -type.turretOrigin.z);
         
          if(modVehicle != null)
            modVehicle.renderTurret(0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F, vehicle, f1);
         
          if(FlansMod.DEBUG)
          {         
              GL11.glTranslatef(type.turretOrigin.x, type.turretOrigin.y, type.turretOrigin.z);
            GL11.glRotatef(-vehicle.seats[0].looking.getPitch(), 0.0F, 0.0F, 1.0F);
            GL11.glTranslatef(-type.turretOrigin.x, -type.turretOrigin.y, -type.turretOrigin.z);
           
            //Render shoot points
            GL11.glColor4f(0F, 0F, 1F, 0.3F);
            for(DriveablePosition point : type.shootPointsPrimary)     
              if(point.part == EnumDriveablePart.turret)
                renderAABB(AxisAlignedBB.getBoundingBox(point.position.x - 0.25F, point.position.y - 0.25F, point.position.z - 0.25F, point.position.x + 0.25F, point.position.y + 0.25F, point.position.z + 0.25F));
           
            GL11.glColor4f(0F, 1F, 0F, 0.3F);
            for(DriveablePosition point : type.shootPointsSecondary
              if(point.part == EnumDriveablePart.turret)
                renderAABB(AxisAlignedBB.getBoundingBox(point.position.x - 0.25F, point.position.y - 0.25F, point.position.z - 0.25F, point.position.x + 0.25F, point.position.y + 0.25F, point.position.z + 0.25F));
          }
        }
        GL11.glPopMatrix();
      }
      GL11.glPopMatrix();
     
      if(FlansMod.DEBUG)
      {
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glColor4f(1F, 0F, 0F, 0.3F);
        GL11.glScalef(1F, 1F, 1F);
        for(DriveablePart part : vehicle.getDriveableData().parts.values())
        {
          if(part.box == null)
            continue;
         
          renderAABB(AxisAlignedBB.getBoundingBox(part.box.x, part.box.y, part.box.z, (part.box.x + part.box.w), (part.box.y + part.box.h), (part.box.z + part.box.d)));
        }
        //GL11.glColor4f(0F, 1F, 0F, 0.3F);
        //if(type.barrelPosition != null)
        //  renderAABB(AxisAlignedBB.getBoundingBox(type.barrelPosition.x - 0.25F, type.barrelPosition.y - 0.25F, type.barrelPosition.z - 0.25F, type.barrelPosition.x + 0.25F, type.barrelPosition.y + 0.25F, type.barrelPosition.z + 0.25F));
       
        //Render shoot points
        GL11.glColor4f(0F, 0F, 1F, 0.3F);
        for(DriveablePosition point : type.shootPointsPrimary)     
          if(point.part != EnumDriveablePart.turret)
            renderAABB(AxisAlignedBB.getBoundingBox(point.position.x - 0.25F, point.position.y - 0.25F, point.position.z - 0.25F, point.position.x + 0.25F, point.position.y + 0.25F, point.position.z + 0.25F));
       
        GL11.glColor4f(0F, 1F, 0F, 0.3F);
        for(DriveablePosition point : type.shootPointsSecondary
          if(point.part != EnumDriveablePart.turret)
            renderAABB(AxisAlignedBB.getBoundingBox(point.position.x - 0.25F, point.position.y - 0.25F, point.position.z - 0.25F, point.position.x + 0.25F, point.position.y + 0.25F, point.position.z + 0.25F));

       
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glColor4f(1F, 1F, 1F, 1F);
      }
        }
        GL11.glPopMatrix();
    }

    @Override
  public void doRender(Entity entity, double d, double d1, double d2, float f, float f1)
    {
        render((EntityVehicle)entity, d, d1, d2, f, f1);
    }
   
  @Override
  protected ResourceLocation getEntityTexture(Entity entity)
  {
    return FlansModResourceHandler.getTexture(((EntityVehicle)entity).getVehicleType());
  }
 
  @Override
  public boolean handleRenderType(ItemStack item, ItemRenderType type)
  {
    switch(type)
    {
    case EQUIPPED : case EQUIPPED_FIRST_PERSON : case ENTITY : return Minecraft.getMinecraft().gameSettings.fancyGraphics && item != null && item.getItem() instanceof ItemVehicle && ((ItemVehicle)item.getItem()).type.model != null;
    default : break;
    }
    return false;
  }

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

  @Override
  public void renderItem(ItemRenderType type, ItemStack item, Object... data)
  {
    GL11.glPushMatrix();
    if(item != null && item.getItem() instanceof ItemVehicle)
    {
      VehicleType vehicleType = ((ItemVehicle)item.getItem()).type;
      if(vehicleType.model != null)
      {
        float scale = 0.5F;
        switch(type)
        {
        case ENTITY:
        {
          scale = 1.5F;
          GL11.glRotatef(((EntityItem)data[1]).ticksExisted, 0F, 1F, 0F);
          break;
        }
        case EQUIPPED:
        {
          GL11.glRotatef(15F, 0F, 0F, 1F);
          GL11.glRotatef(15F, 1F, 0F, 0F);
          GL11.glRotatef(270F, 0F, 1F, 0F);
          GL11.glTranslatef(0F, 0.15F, -0.4F);
          scale = 1F;
          break;
        }
        case EQUIPPED_FIRST_PERSON:
        {
          GL11.glRotatef(25F, 0F, 0F, 1F);
          GL11.glRotatef(-5F, 0F, 1F, 0F);
          GL11.glTranslatef(0.15F, 0.45F, -0.6F);
          break;
        }
        default : break;
        }
       
        GL11.glScalef(scale / vehicleType.cameraDistance, scale / vehicleType.cameraDistance, scale / vehicleType.cameraDistance);
        Minecraft.getMinecraft().renderEngine.bindTexture(FlansModResourceHandler.getTexture(vehicleType));
        ModelDriveable model = vehicleType.model;
        model.render(vehicleType);
      }
    }
    GL11.glPopMatrix();
  }
}
TOP

Related Classes of com.flansmod.client.model.RenderVehicle

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.