RenderHuman.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package me.km.entities;
  2. import net.minecraft.client.Minecraft;
  3. import net.minecraft.client.model.ModelBiped;
  4. import net.minecraft.client.model.ModelPlayer;
  5. import net.minecraft.client.renderer.GlStateManager;
  6. import net.minecraft.client.renderer.entity.RenderLivingBase;
  7. import net.minecraft.client.renderer.entity.layers.LayerArrow;
  8. import net.minecraft.client.renderer.entity.layers.LayerBipedArmor;
  9. import net.minecraft.client.renderer.entity.layers.LayerCustomHead;
  10. import net.minecraft.client.renderer.entity.layers.LayerElytra;
  11. import net.minecraft.client.renderer.entity.layers.LayerHeldItem;
  12. import net.minecraft.item.EnumAction;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.util.EnumHandSide;
  15. import net.minecraft.util.ResourceLocation;
  16. import net.minecraftforge.fml.relauncher.Side;
  17. import net.minecraftforge.fml.relauncher.SideOnly;
  18. @SideOnly(Side.CLIENT)
  19. public class RenderHuman extends RenderLivingBase<EntityHuman>
  20. {
  21. /** this field is used to indicate the 3-pixel wide arms */
  22. private final ModelHuman steve;
  23. private final ModelHuman alex;
  24. public RenderHuman()
  25. {
  26. super(Minecraft.getMinecraft().getRenderManager(), new ModelHuman(0, false), 0.5f);
  27. this.addLayer(new LayerBipedArmor(this));
  28. this.addLayer(new LayerHeldItem(this));
  29. this.addLayer(new LayerArrow(this));
  30. this.addLayer(new LayerCustomHead(this.getMainModel().bipedHead));
  31. this.addLayer(new LayerElytra(this));
  32. this.steve = this.getMainModel();
  33. this.alex = new ModelHuman(0, true);
  34. }
  35. @Override
  36. public final ModelHuman getMainModel()
  37. {
  38. return (ModelHuman) super.getMainModel();
  39. }
  40. @Override
  41. public void doRender(EntityHuman h, double x, double y, double z, float entityYaw, float partialTicks)
  42. {
  43. double d0 = y;
  44. if (h.isSneaking())
  45. {
  46. d0 = y - 0.125D;
  47. }
  48. this.setModelVisibilities(h);
  49. GlStateManager.enableBlendProfile(GlStateManager.Profile.PLAYER_SKIN);
  50. if(h.isSlim())
  51. {
  52. this.mainModel = alex;
  53. super.doRender(h, x, d0, z, entityYaw, partialTicks);
  54. this.mainModel = steve;
  55. }
  56. else
  57. {
  58. super.doRender(h, x, d0, z, entityYaw, partialTicks);
  59. }
  60. GlStateManager.disableBlendProfile(GlStateManager.Profile.PLAYER_SKIN);
  61. }
  62. private void setModelVisibilities(EntityHuman h)
  63. {
  64. ModelPlayer modelplayer = this.getMainModel();
  65. modelplayer.setVisible(true);
  66. modelplayer.bipedHeadwear.showModel = true;
  67. modelplayer.bipedBodyWear.showModel = true;
  68. modelplayer.bipedLeftLegwear.showModel = true;
  69. modelplayer.bipedRightLegwear.showModel = true;
  70. modelplayer.bipedLeftArmwear.showModel = true;
  71. modelplayer.bipedRightArmwear.showModel = true;
  72. modelplayer.isSneak = false;
  73. ModelBiped.ArmPose modelbiped$armpose = ModelBiped.ArmPose.EMPTY;
  74. ModelBiped.ArmPose modelbiped$armpose1 = ModelBiped.ArmPose.EMPTY;
  75. ItemStack mainHand = h.getHeldItemMainhand();
  76. if (!mainHand.isEmpty())
  77. {
  78. modelbiped$armpose = ModelBiped.ArmPose.ITEM;
  79. if (h.getItemInUseCount() > 0)
  80. {
  81. EnumAction enumaction = mainHand.getItemUseAction();
  82. if (enumaction == EnumAction.BLOCK)
  83. {
  84. modelbiped$armpose = ModelBiped.ArmPose.BLOCK;
  85. }
  86. else if (enumaction == EnumAction.BOW)
  87. {
  88. modelbiped$armpose = ModelBiped.ArmPose.BOW_AND_ARROW;
  89. }
  90. }
  91. }
  92. ItemStack offHand = h.getHeldItemMainhand();
  93. if (!offHand.isEmpty())
  94. {
  95. modelbiped$armpose1 = ModelBiped.ArmPose.ITEM;
  96. if (h.getItemInUseCount() > 0)
  97. {
  98. EnumAction enumaction1 = offHand.getItemUseAction();
  99. if (enumaction1 == EnumAction.BLOCK)
  100. {
  101. modelbiped$armpose1 = ModelBiped.ArmPose.BLOCK;
  102. }
  103. // FORGE: fix MC-88356 allow offhand to use bow and arrow animation
  104. else if (enumaction1 == EnumAction.BOW)
  105. {
  106. modelbiped$armpose1 = ModelBiped.ArmPose.BOW_AND_ARROW;
  107. }
  108. }
  109. }
  110. if (h.getPrimaryHand() == EnumHandSide.RIGHT)
  111. {
  112. modelplayer.rightArmPose = modelbiped$armpose;
  113. modelplayer.leftArmPose = modelbiped$armpose1;
  114. }
  115. else
  116. {
  117. modelplayer.rightArmPose = modelbiped$armpose1;
  118. modelplayer.leftArmPose = modelbiped$armpose;
  119. }
  120. }
  121. @Override
  122. public ResourceLocation getEntityTexture(EntityHuman h)
  123. {
  124. return h.getTexture();
  125. }
  126. @Override
  127. public void transformHeldFull3DItemLayer()
  128. {
  129. GlStateManager.translate(0.0F, 0.1875F, 0.0F);
  130. }
  131. @Override
  132. protected void preRenderCallback(EntityHuman entitylivingbaseIn, float partialTickTime)
  133. {
  134. GlStateManager.scale(0.9375F, 0.9375F, 0.9375F);
  135. }
  136. }