MineLittlePony/src/main/java/com/minelittlepony/model/components/PegasusWings.java

76 lines
2.4 KiB
Java
Raw Normal View History

package com.minelittlepony.model.components;
import net.minecraft.client.model.ModelBase;
import net.minecraft.entity.Entity;
2016-05-04 03:23:57 +02:00
import net.minecraft.util.math.MathHelper;
import static com.minelittlepony.model.PonyModelConstants.*;
import com.minelittlepony.model.AbstractPonyModel;
public class PegasusWings extends ModelBase {
2016-04-09 08:24:15 +02:00
private final AbstractPonyModel pony;
2018-04-24 17:12:23 +02:00
2018-04-26 23:53:03 +02:00
public final ModelWing leftWing;
public final ModelWing rightWing;
2018-04-24 17:12:23 +02:00
public PegasusWings(AbstractPonyModel pony, float yOffset, float stretch) {
this.pony = pony;
2018-04-24 16:46:53 +02:00
leftWing = new ModelWing(pony, false, 4f, yOffset, stretch, 32);
rightWing = new ModelWing(pony, true, -6f, yOffset, stretch, 16);
}
2018-04-24 17:12:23 +02:00
@Override
2018-04-24 16:46:53 +02:00
public void setRotationAngles(float limbSwing, float limbSwingAmount, float ticks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) {
if (!isVisible()) return;
2018-04-24 16:46:53 +02:00
float swing = 0;
2018-04-24 16:46:53 +02:00
if (pony.swingProgress > 0) {
swing = MathHelper.sin(MathHelper.sqrt(pony.swingProgress) * PI * 2);
} else {
float pi = PI * (float) Math.pow(limbSwingAmount, 16);
2018-04-26 23:53:03 +02:00
float mve = limbSwing * 0.6662f; // magic number ahoy
float srt = limbSwingAmount / 4;
2018-04-24 16:46:53 +02:00
swing = MathHelper.cos(mve + pi) * srt;
}
leftWing.rotateWalking(swing);
rightWing.rotateWalking(-swing);
if (isExtended()) {
float flapAngle = getWingRotationFactor(ticks);
leftWing.rotateFlying(flapAngle);
rightWing.rotateFlying(-flapAngle);
}
2018-04-24 16:46:53 +02:00
}
public float getWingRotationFactor(float ticks) {
if (pony.isFlying) {
2018-04-26 23:53:03 +02:00
return (MathHelper.sin(ticks * 0.536f) * 1) + ROTATE_270 + 0.4f;
}
return LEFT_WING_ROTATE_ANGLE_Z_SNEAK;
}
public boolean isVisible() {
return pony.metadata.getRace().hasWings();
}
public boolean isExtended() {
return pony.isFlying || pony.isSneak;
}
2018-04-24 17:12:23 +02:00
@Override
public void render(Entity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
if (!isVisible()) return;
boolean standing = isExtended();
leftWing.render(standing, scale);
rightWing.render(standing, scale);
}
}