grossik

Untitled

Aug 14th, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. package com.example.examplemod;
  2.  
  3. import net.minecraft.client.model.IMultipassModel;
  4. import net.minecraft.client.model.ModelBase;
  5. import net.minecraft.client.renderer.GlStateManager;
  6. import net.minecraft.client.renderer.entity.Render;
  7. import net.minecraft.client.renderer.entity.RenderManager;
  8. import net.minecraft.util.ResourceLocation;
  9. import net.minecraft.util.math.MathHelper;
  10. import net.minecraftforge.fml.relauncher.Side;
  11. import net.minecraftforge.fml.relauncher.SideOnly;
  12.  
  13. @SideOnly(Side.CLIENT)
  14. public class RenderVehicle extends Render<EntityVehicle>
  15. {
  16. private static final ResourceLocation[] BOAT_TEXTURES = new ResourceLocation[] {new ResourceLocation("textures/entity/boat/boat_oak.png"), new ResourceLocation("textures/entity/boat/boat_spruce.png"), new ResourceLocation("textures/entity/boat/boat_birch.png"), new ResourceLocation("textures/entity/boat/boat_jungle.png"), new ResourceLocation("textures/entity/boat/boat_acacia.png"), new ResourceLocation("textures/entity/boat/boat_darkoak.png")};
  17. /** instance of ModelBoat for rendering */
  18. protected ModelBase modelBoat = new ModelVehicle();
  19.  
  20. public RenderVehicle(RenderManager renderManagerIn)
  21. {
  22. super(renderManagerIn);
  23. this.shadowSize = 0.5F;
  24. }
  25.  
  26. /**
  27. * Renders the desired {@code T} type Entity.
  28. */
  29. public void doRender(EntityVehicle entity, double x, double y, double z, float entityYaw, float partialTicks)
  30. {
  31. GlStateManager.pushMatrix();
  32. this.setupTranslation(x, y, z);
  33. this.setupRotation(entity, entityYaw, partialTicks);
  34. this.bindEntityTexture(entity);
  35.  
  36. if (this.renderOutlines)
  37. {
  38. GlStateManager.enableColorMaterial();
  39. GlStateManager.enableOutlineMode(this.getTeamColor(entity));
  40. }
  41.  
  42. this.modelBoat.render(entity, partialTicks, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
  43.  
  44. if (this.renderOutlines)
  45. {
  46. GlStateManager.disableOutlineMode();
  47. GlStateManager.disableColorMaterial();
  48. }
  49.  
  50. GlStateManager.popMatrix();
  51. super.doRender(entity, x, y, z, entityYaw, partialTicks);
  52. }
  53.  
  54. public void setupRotation(EntityVehicle p_188311_1_, float p_188311_2_, float p_188311_3_)
  55. {
  56. GlStateManager.rotate(180.0F - p_188311_2_, 0.0F, 1.0F, 0.0F);
  57. float f = (float)p_188311_1_.getTimeSinceHit() - p_188311_3_;
  58. float f1 = p_188311_1_.getDamageTaken() - p_188311_3_;
  59.  
  60. if (f1 < 0.0F)
  61. {
  62. f1 = 0.0F;
  63. }
  64.  
  65. if (f > 0.0F)
  66. {
  67. GlStateManager.rotate(MathHelper.sin(f) * f * f1 / 10.0F * (float)p_188311_1_.getForwardDirection(), 1.0F, 0.0F, 0.0F);
  68. }
  69.  
  70. GlStateManager.scale(-1.0F, -1.0F, 1.0F);
  71. }
  72.  
  73. public void setupTranslation(double p_188309_1_, double p_188309_3_, double p_188309_5_)
  74. {
  75. GlStateManager.translate((float)p_188309_1_, (float)p_188309_3_ + 0.375F, (float)p_188309_5_);
  76. }
  77.  
  78. /**
  79. * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
  80. */
  81. protected ResourceLocation getEntityTexture(EntityVehicle entity)
  82. {
  83. return BOAT_TEXTURES[entity.getBoatType().ordinal()];
  84. }
  85.  
  86. public boolean isMultipass()
  87. {
  88. return true;
  89. }
  90.  
  91. public void renderMultipass(EntityVehicle p_188300_1_, double p_188300_2_, double p_188300_4_, double p_188300_6_, float p_188300_8_, float p_188300_9_)
  92. {
  93. GlStateManager.pushMatrix();
  94. this.setupTranslation(p_188300_2_, p_188300_4_, p_188300_6_);
  95. this.setupRotation(p_188300_1_, p_188300_8_, p_188300_9_);
  96. this.bindEntityTexture(p_188300_1_);
  97. ((IMultipassModel)this.modelBoat).renderMultipass(p_188300_1_, p_188300_9_, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
  98. GlStateManager.popMatrix();
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment