Clean up elytra code

This commit is contained in:
Sollace 2018-04-27 09:46:44 +02:00
parent 36ee3966d7
commit 17624c484a

View file

@ -1,6 +1,5 @@
package com.minelittlepony.model.components; package com.minelittlepony.model.components;
import com.minelittlepony.model.PonyModelConstants;
import com.minelittlepony.render.PonyRenderer; import com.minelittlepony.render.PonyRenderer;
import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.entity.AbstractClientPlayer;
@ -10,6 +9,11 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import static com.minelittlepony.model.PonyModelConstants.*;
/**
* Modified from ModelElytra.
*/
public class PonyElytra extends ModelBase { public class PonyElytra extends ModelBase {
private PonyRenderer rightWing = new PonyRenderer(this, 22, 0); private PonyRenderer rightWing = new PonyRenderer(this, 22, 0);
private PonyRenderer leftWing = new PonyRenderer(this, 22, 0); private PonyRenderer leftWing = new PonyRenderer(this, 22, 0);
@ -28,55 +32,56 @@ public class PonyElytra extends ModelBase {
} }
@Override @Override
public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) { public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entity) {
super.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scaleFactor, entityIn); super.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scaleFactor, entity);
final float PI = (float) Math.PI; float rotateX = PI / 2;
float rotateX = PI / 2F; float rotateY = PI / 8;
float rotateY = PI / 8F;
float rotateZ = PI / 12; float rotateZ = PI / 12;
float rpY = PonyModelConstants.BODY_RP_Y_NOTSNEAK; float rpY = BODY_RP_Y_NOTSNEAK;
if (entityIn instanceof EntityLivingBase && ((EntityLivingBase) entityIn).isElytraFlying()) { if (entity instanceof EntityLivingBase && ((EntityLivingBase) entity).isElytraFlying()) {
float f4 = 1; float velY = 1;
if (entityIn.motionY < 0) { if (entity.motionY < 0) {
Vec3d vec3d = (new Vec3d(entityIn.motionX, entityIn.motionY, entityIn.motionZ)).normalize(); Vec3d motion = (new Vec3d(entity.motionX, entity.motionY, entity.motionZ)).normalize();
f4 = 1 - (float) Math.pow(-vec3d.y, 1.5); velY = 1 - (float) Math.pow(-motion.y, 1.5);
} }
rotateX = f4 * PI * (2 / 3F) + (1 - f4) * rotateX; rotateX = velY * PI * (2 / 3F) + (1 - velY) * rotateX;
rotateY = f4 * ((float) Math.PI / 2F) + (1 - f4) * rotateY; rotateY = velY * (PI / 2) + (1 - velY) * rotateY;
} else if (entityIn.isSneaking()) { } else if (entity.isSneaking()) {
rotateX = ((float) Math.PI * 1.175F); rotateX = PI * 1.175F;
rotateY = PI / 2; rotateY = PI / 2;
rpY = PonyModelConstants.BODY_RP_Y_SNEAK; rotateZ = PI / 4;
rotateZ = PI / 4F; rpY = BODY_RP_Y_SNEAK;
} }
this.leftWing.rotationPointX = 5; leftWing.rotationPointX = 5;
this.leftWing.rotationPointY = rpY; leftWing.rotationPointY = rpY;
if (entityIn instanceof AbstractClientPlayer) { if (entity instanceof AbstractClientPlayer) {
AbstractClientPlayer abstractclientplayer = (AbstractClientPlayer) entityIn; AbstractClientPlayer player = (AbstractClientPlayer) entity;
abstractclientplayer.rotateElytraX = (float) (abstractclientplayer.rotateElytraX + (rotateX - abstractclientplayer.rotateElytraX) * 0.1D);
abstractclientplayer.rotateElytraY = (float) (abstractclientplayer.rotateElytraY + (rotateY - abstractclientplayer.rotateElytraY) * 0.1D); player.rotateElytraX += (rotateX - player.rotateElytraX) / 10;
abstractclientplayer.rotateElytraZ = (float) (abstractclientplayer.rotateElytraZ + (rotateZ - abstractclientplayer.rotateElytraZ) * 0.1D); player.rotateElytraY += (rotateY - player.rotateElytraY) / 10;
this.leftWing.rotateAngleX = abstractclientplayer.rotateElytraX; player.rotateElytraZ += (rotateZ - player.rotateElytraZ) / 10;
this.leftWing.rotateAngleY = abstractclientplayer.rotateElytraY;
this.leftWing.rotateAngleZ = abstractclientplayer.rotateElytraZ; leftWing.rotateAngleX = player.rotateElytraX;
leftWing.rotateAngleY = player.rotateElytraY;
leftWing.rotateAngleZ = player.rotateElytraZ;
} else { } else {
this.leftWing.rotateAngleX = rotateX; leftWing.rotateAngleX = rotateX;
this.leftWing.rotateAngleZ = rotateZ; leftWing.rotateAngleZ = rotateZ;
this.leftWing.rotateAngleY = rotateY; leftWing.rotateAngleY = rotateY;
} }
this.rightWing.rotationPointX = -this.leftWing.rotationPointX; rightWing.rotationPointX = -leftWing.rotationPointX;
this.rightWing.rotateAngleY = -this.leftWing.rotateAngleY; rightWing.rotationPointY = leftWing.rotationPointY;
this.rightWing.rotationPointY = this.leftWing.rotationPointY; rightWing.rotateAngleX = leftWing.rotateAngleX;
this.rightWing.rotateAngleX = this.leftWing.rotateAngleX; rightWing.rotateAngleY = -leftWing.rotateAngleY;
this.rightWing.rotateAngleZ = -this.leftWing.rotateAngleZ; rightWing.rotateAngleZ = -leftWing.rotateAngleZ;
} }
} }