2018-04-25 12:59:18 +02:00
|
|
|
package com.minelittlepony.model.components;
|
|
|
|
|
2016-05-04 03:23:57 +02:00
|
|
|
import net.minecraft.util.math.MathHelper;
|
2015-12-14 09:29:10 +01:00
|
|
|
|
2018-04-25 12:59:18 +02:00
|
|
|
import static com.minelittlepony.model.PonyModelConstants.*;
|
|
|
|
|
2018-04-25 16:40:47 +02:00
|
|
|
import com.minelittlepony.model.AbstractPonyModel;
|
2018-05-11 13:52:42 +02:00
|
|
|
import com.minelittlepony.model.capabilities.IModelPart;
|
2018-04-28 18:13:35 +02:00
|
|
|
import com.minelittlepony.model.capabilities.IModelPegasus;
|
2018-04-25 16:40:47 +02:00
|
|
|
|
2018-05-11 13:52:42 +02:00
|
|
|
public class PegasusWings implements IModelPart {
|
2016-11-25 05:40:19 +01:00
|
|
|
|
2018-04-28 18:13:35 +02:00
|
|
|
private final IModelPegasus pegasus;
|
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
|
|
|
|
2018-04-28 18:13:35 +02:00
|
|
|
public <T extends AbstractPonyModel & IModelPegasus> PegasusWings(T model, float yOffset, float stretch) {
|
|
|
|
pegasus = model;
|
2018-04-27 13:49:33 +02:00
|
|
|
|
2018-04-28 18:13:35 +02:00
|
|
|
leftWing = new ModelWing(model, false, 4f, yOffset, stretch, 32);
|
|
|
|
rightWing = new ModelWing(model, true, -6f, yOffset, stretch, 16);
|
2015-12-14 09:29:10 +01:00
|
|
|
}
|
2018-04-24 17:12:23 +02:00
|
|
|
|
2018-05-11 13:52:42 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void init(float yOffset, float stretch) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setRotationAndAngles(boolean rainboom, float move, float swing, float bodySwing, float ticks) {
|
2018-04-27 13:49:33 +02:00
|
|
|
float flap = 0;
|
2018-04-28 18:13:35 +02:00
|
|
|
float progress = pegasus.getSwingAmount();
|
2018-04-27 13:49:33 +02:00
|
|
|
|
2018-04-28 18:13:35 +02:00
|
|
|
if (progress > 0) {
|
|
|
|
flap = MathHelper.sin(MathHelper.sqrt(progress) * PI * 2);
|
2018-04-26 17:20:02 +02:00
|
|
|
} else {
|
2018-04-27 13:49:33 +02:00
|
|
|
float pi = PI * (float) Math.pow(swing, 16);
|
|
|
|
|
|
|
|
float mve = move * 0.6662f; // magic number ahoy
|
|
|
|
float srt = swing / 4;
|
|
|
|
|
|
|
|
flap = MathHelper.cos(mve + pi) * srt;
|
2018-04-26 17:20:02 +02:00
|
|
|
}
|
2018-04-27 13:49:33 +02:00
|
|
|
|
|
|
|
leftWing.rotateWalking(flap);
|
|
|
|
rightWing.rotateWalking(-flap);
|
|
|
|
|
2018-04-28 18:13:35 +02:00
|
|
|
if (pegasus.wingsAreOpen()) {
|
2018-04-26 17:20:02 +02:00
|
|
|
float flapAngle = getWingRotationFactor(ticks);
|
|
|
|
leftWing.rotateFlying(flapAngle);
|
|
|
|
rightWing.rotateFlying(-flapAngle);
|
2015-12-14 09:29:10 +01:00
|
|
|
}
|
2018-04-27 13:49:33 +02:00
|
|
|
|
2018-04-26 17:20:02 +02:00
|
|
|
}
|
2018-04-27 13:49:33 +02:00
|
|
|
|
2018-04-26 17:20:02 +02:00
|
|
|
public float getWingRotationFactor(float ticks) {
|
2018-06-03 22:23:32 +02:00
|
|
|
if (pegasus.isSwimming()) {
|
|
|
|
return (MathHelper.sin(ticks * 0.136f) / 2) + ROTATE_270;
|
|
|
|
}
|
2018-04-28 18:13:35 +02:00
|
|
|
if (pegasus.isFlying()) {
|
2018-06-03 22:23:32 +02:00
|
|
|
return MathHelper.sin(ticks * 0.536f) + ROTATE_270 + 0.4f;
|
2018-04-26 17:20:02 +02:00
|
|
|
}
|
|
|
|
return LEFT_WING_ROTATE_ANGLE_Z_SNEAK;
|
|
|
|
}
|
2018-04-27 13:49:33 +02:00
|
|
|
|
2018-05-11 13:52:42 +02:00
|
|
|
@Override
|
2018-04-28 18:13:35 +02:00
|
|
|
public void render(float scale) {
|
|
|
|
boolean standing = pegasus.wingsAreOpen();
|
2018-04-26 17:20:02 +02:00
|
|
|
leftWing.render(standing, scale);
|
|
|
|
rightWing.render(standing, scale);
|
2015-12-14 09:29:10 +01:00
|
|
|
}
|
|
|
|
}
|