| 1 | package net.minecraft.entity;
|
| 2 |
|
| 3 | import net.minecraft.util.MathHelper;
|
| 4 |
|
| 5 | public class EntityBodyHelper
|
| 6 | {
|
| 7 | /** Instance of EntityLiving. */
|
| 8 | private EntityLivingBase theLiving;
|
| 9 |
|
| 10 | /**
|
| 11 | * Used to progressively ajust the rotation of the body to the rotation of the head
|
| 12 | */
|
| 13 | private int rotationTickCounter;
|
| 14 | private float prevRenderYawHead;
|
| 15 |
|
| 16 | public EntityBodyHelper(EntityLivingBase p_i1611_1_)
|
| 17 | {
|
| 18 | this.theLiving = p_i1611_1_;
|
| 19 | }
|
| 20 |
|
| 21 | /**
|
| 22 | * Update the Head and Body rendenring angles
|
| 23 | */
|
| 24 | public void updateRenderAngles()
|
| 25 | {
|
| 26 | double d0 = this.theLiving.posX - this.theLiving.prevPosX;
|
| 27 | double d1 = this.theLiving.posZ - this.theLiving.prevPosZ;
|
| 28 |
|
| 29 | if (d0 * d0 + d1 * d1 > 2.500000277905201E-7D)
|
| 30 | {
|
| 31 | this.theLiving.renderYawOffset = this.theLiving.rotationYaw;
|
| 32 | this.theLiving.rotationYawHead = this.computeAngleWithBound(this.theLiving.renderYawOffset, this.theLiving.rotationYawHead, 75.0F);
|
| 33 | this.prevRenderYawHead = this.theLiving.rotationYawHead;
|
| 34 | this.rotationTickCounter = 0;
|
| 35 | }
|
| 36 | else
|
| 37 | {
|
| 38 | float f = 75.0F;
|
| 39 |
|
| 40 | if (Math.abs(this.theLiving.rotationYawHead - this.prevRenderYawHead) > 15.0F)
|
| 41 | {
|
| 42 | this.rotationTickCounter = 0;
|
| 43 | this.prevRenderYawHead = this.theLiving.rotationYawHead;
|
| 44 | }
|
| 45 | else
|
| 46 | {
|
| 47 | ++this.rotationTickCounter;
|
| 48 | int i = 10;
|
| 49 |
|
| 50 | if (this.rotationTickCounter > 10)
|
| 51 | {
|
| 52 | f = Math.max(1.0F - (float)(this.rotationTickCounter - 10) / 10.0F, 0.0F) * 75.0F;
|
| 53 | }
|
| 54 | }
|
| 55 |
|
| 56 | this.theLiving.renderYawOffset = this.computeAngleWithBound(this.theLiving.rotationYawHead, this.theLiving.renderYawOffset, f);
|
| 57 | }
|
| 58 | }
|
| 59 |
|
| 60 | /**
|
| 61 | * Return the new angle2 such that the difference between angle1 and angle2 is lower than angleMax. Args : angle1,
|
| 62 | * angle2, angleMax
|
| 63 | */
|
| 64 | private float computeAngleWithBound(float p_75665_1_, float p_75665_2_, float p_75665_3_)
|
| 65 | {
|
| 66 | float f = MathHelper.wrapAngleTo180_float(p_75665_1_ - p_75665_2_);
|
| 67 |
|
| 68 | if (f < -p_75665_3_)
|
| 69 | {
|
| 70 | f = -p_75665_3_;
|
| 71 | }
|
| 72 |
|
| 73 | if (f >= p_75665_3_)
|
| 74 | {
|
| 75 | f = p_75665_3_;
|
| 76 | }
|
| 77 |
|
| 78 | return p_75665_1_ - f;
|
| 79 | }
|
| 80 | }
|
| 81 |
|