Advertisement
Guest User

RenderDog.java

a guest
Apr 3rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.18 KB | None | 0 0
  1. package com.copiousdogs.client.render.entity;
  2.  
  3. import net.minecraft.client.model.ModelBase;
  4. import net.minecraft.client.renderer.Tessellator;
  5. import net.minecraft.client.renderer.entity.RenderLiving;
  6. import net.minecraft.entity.Entity;
  7. import net.minecraft.entity.EntityLiving;
  8. import net.minecraft.entity.EntityLivingBase;
  9. import net.minecraft.entity.passive.EntitySheep;
  10. import net.minecraft.util.MathHelper;
  11. import net.minecraft.util.ResourceLocation;
  12. import net.minecraft.util.Vec3;
  13.  
  14. import org.lwjgl.opengl.GL11;
  15.  
  16. import com.copiousdogs.entity.EntityDog;
  17. import com.copiousdogs.entity.EntityPoodle;
  18. import com.copiousdogs.item.ItemDogCollar;
  19. import com.copiousdogs.lib.Reference;
  20.  
  21. public class RenderDog extends RenderLiving
  22. {
  23.  
  24.     public RenderDog(ModelBase model, ModelBase renderPass, float f)
  25.     {
  26.         super(model, f);
  27.         this.setRenderPassModel(renderPass);
  28.     }
  29.  
  30.     @Override
  31.     protected int inheritRenderPass(EntityLivingBase entity, int i0, float f0)
  32.     {
  33.         if (entity instanceof EntityDog)
  34.         {
  35.             EntityDog dog = (EntityDog) entity;
  36.            
  37.             float f1;
  38.             if (i0 == 1 && dog.isTamed() && dog.hasCollar())
  39.             {
  40.                 bindTexture(getDogCollarTexture(dog));
  41.                 f1 = 1.0f;
  42.                 int j = ItemDogCollar.getItemFromDye(dog.getCollarColor());
  43.                 float[] color = EntitySheep.fleeceColorTable[j];
  44.                 GL11.glColor3f(f1 * color[0], f1 * color[1], f1 * color[2]);
  45.                 return 1;
  46.             }
  47.             if (i0 == 0) {
  48.                
  49.                 if (dog instanceof EntityPoodle) {
  50.                    
  51.                     EntityPoodle poodle = (EntityPoodle) dog;
  52.                     bindTexture(poodle.getColorTexture());
  53.                     f1 = poodle.getColor() != 0 ? 0.9f:1f;
  54.                     float[] color = EntitySheep.fleeceColorTable[poodle.getColor()];
  55.                     GL11.glColor3f(f1 * color[0], f1 * color[1], f1 * color[2]);
  56.                     float scale = 1f;
  57.                     GL11.glScalef(scale, scale, scale);
  58.                     return 1;
  59.                 }
  60.             }
  61.         }
  62.         return -1;
  63.     }
  64.  
  65.     @Override
  66.     public void doRender(EntityLiving entity, double d0, double d1, double d2,
  67.             float f0, float f1)
  68.     {
  69.         super.doRender(entity, d0, d1, d2, f0, f1);
  70.  
  71.         EntityDog dog = (EntityDog) entity;
  72.        
  73.         if (dog.hasLeash() && dog.getOwner() != null)
  74.         {
  75.            
  76.             float f9 = ((EntityLivingBase) dog.getOwner()).getSwingProgress(f1);
  77.             float f10 = MathHelper.sin(MathHelper.sqrt_float(f9) * (float)Math.PI);
  78.  
  79.             Vec3 vec3 = Vec3.createVectorHelper(-.03D, 0D, -.03D);
  80.             vec3.rotateAroundX(-(dog.getOwner().prevRotationPitch + (dog.getOwner().rotationPitch - dog.getOwner().prevRotationPitch) * f1) * (float)Math.PI / 180.0F);
  81.             vec3.rotateAroundY(-(dog.getOwner().prevRotationYaw + (dog.getOwner().rotationYaw - dog.getOwner().prevRotationYaw) * f1) * (float)Math.PI / 180.0F);
  82.             vec3.rotateAroundY(f10 * 0.5F);
  83.             vec3.rotateAroundX(-f10 * 0.7F);
  84.            
  85.             double d3 = dog.getOwner().prevPosX + (dog.getOwner().posX - dog.getOwner().prevPosX) * (double)f1 + vec3.xCoord;
  86.             double d4 = dog.getOwner().prevPosY + (dog.getOwner().posY - dog.getOwner().prevPosY) * (double)f1 + vec3.yCoord;
  87.             double d5 = dog.getOwner().prevPosZ + (dog.getOwner().posZ - dog.getOwner().prevPosZ) * (double)f1 + vec3.zCoord;
  88.            
  89.             double d9 = entity.prevPosX + (entity.posX - entity.prevPosX) * (double)f1;
  90.             double d10 = entity.prevPosY + (entity.posY - entity.prevPosY) * (double)f1 + 0.5D;
  91.             double d11 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double)f1;
  92.             double d12 = (double)((float)(d3 - d9));
  93.             double d13 = (double)((float)(d4 - d10));
  94.             double d14 = (double)((float)(d5 - d11));
  95.             GL11.glDisable(GL11.GL_TEXTURE_2D);
  96.             GL11.glDisable(GL11.GL_LIGHTING);
  97.            
  98.             Tessellator tessellator = Tessellator.instance;
  99.      
  100.             tessellator.startDrawing(3);
  101.             tessellator.setColorOpaque_I(0);
  102.             byte b2 = 16;
  103.    
  104.             for (int i = 0; i <= b2; ++i)
  105.             {
  106.                 float f12 = (float)i / (float)b2;
  107.                 tessellator.addVertex(d0 + d12 * (double)f12, d1 + d13 * (double)(f12 * f12 + f12) * 0.5D + 0.25D, d2 + d14 * (double)f12);
  108.             }
  109.            
  110.             tessellator.draw();
  111.            
  112.             GL11.glEnable(GL11.GL_TEXTURE_2D);
  113.             GL11.glEnable(GL11.GL_LIGHTING);
  114.         }
  115.     }
  116.  
  117.     @Override
  118.     protected int shouldRenderPass(EntityLivingBase entity, int i0, float f0)
  119.     {
  120.         return this.inheritRenderPass((EntityDog) entity, i0, f0);
  121.     }
  122.  
  123.     @Override
  124.     protected ResourceLocation getEntityTexture(Entity entity)
  125.     {
  126.         if (entity instanceof EntityDog)
  127.         {
  128.        
  129.             if (((EntityDog) entity).getTextureName().contains("@")) //If name has number with one Digit like 1 then remove it -- only supports 0-9
  130.             {
  131.             return new ResourceLocation(Reference.MOD_ID.toLowerCase()
  132.                     + ":textures/entities/" + ((EntityDog) entity).getTextureName().substring(0, ((EntityDog) entity).getTextureName().length() - 2) + "/"
  133.                     + ((EntityDog) entity).getTextureName() + ".png");
  134.         }
  135.            
  136.             else if (((EntityDog) entity).getTextureName().contains("#")) //If name has number with two Digit like 10 then remove them -- only supports 10-99
  137.             {
  138.             return new ResourceLocation(Reference.MOD_ID.toLowerCase()
  139.                     + ":textures/entities/" + ((EntityDog) entity).getTextureName().substring(0, ((EntityDog) entity).getTextureName().length() - 3) + "/"
  140.                     + ((EntityDog) entity).getTextureName() + ".png");
  141.         }
  142.            
  143.             else if (((EntityDog) entity).getTextureName().contains("$")) //If name has number with three Digits like 100 then remove them -- only supports 100-999
  144.             {
  145.             return new ResourceLocation(Reference.MOD_ID.toLowerCase()
  146.                     + ":textures/entities/" + ((EntityDog) entity).getTextureName().substring(0, ((EntityDog) entity).getTextureName().length() - 4) + "/"
  147.                     + ((EntityDog) entity).getTextureName() + ".png");
  148.         }
  149.        
  150.         else {
  151.             return new ResourceLocation(Reference.MOD_ID.toLowerCase()
  152.                     + ":textures/entities/" + ((EntityDog) entity).getTextureName() + "/"
  153.                     + ((EntityDog) entity).getTextureName() + ".png");
  154.         }
  155.     }
  156.         return null;
  157.     }
  158.  
  159.     protected ResourceLocation getDogCollarTexture(EntityDog entity)
  160.     {
  161.         if (((EntityDog) entity).getTextureName().contains("@"))
  162.         {
  163.             return new ResourceLocation(Reference.MOD_ID.toLowerCase() + ":textures/entities/" + ((EntityDog) entity).getTextureName().substring(0, ((EntityDog) entity).getTextureName().length() - 2) + "/"
  164.                     + ((EntityDog) entity).getTextureName() + "_collar.png");
  165.         }
  166.        
  167.         else if (((EntityDog) entity).getTextureName().contains("#"))
  168.         {
  169.             return new ResourceLocation(Reference.MOD_ID.toLowerCase() + ":textures/entities/" + ((EntityDog) entity).getTextureName().substring(0, ((EntityDog) entity).getTextureName().length() - 3) + "/"
  170.                     + ((EntityDog) entity).getTextureName() + "_collar.png");
  171.         }
  172.        
  173.         else if (((EntityDog) entity).getTextureName().contains("$"))
  174.         {
  175.             return new ResourceLocation(Reference.MOD_ID.toLowerCase() + ":textures/entities/" + ((EntityDog) entity).getTextureName().substring(0, ((EntityDog) entity).getTextureName().length() - 4) + "/"
  176.                     + ((EntityDog) entity).getTextureName() + "_collar.png");
  177.         }
  178.        
  179.         else {
  180.             return new ResourceLocation(Reference.MOD_ID.toLowerCase() + ":textures/entities/" + ((EntityDog) entity).getTextureName() + "/"
  181.                     + ((EntityDog) entity).getTextureName() + "_collar.png");
  182.             }
  183.     }
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement