Refactor PegasusWings

This commit is contained in:
Sollace 2018-04-24 16:46:53 +02:00
parent fbb40134e2
commit a99873f8e6
2 changed files with 120 additions and 156 deletions

View file

@ -0,0 +1,95 @@
package com.minelittlepony.model;
import net.minecraft.client.model.ModelRenderer;
// TODO: Combine each wing into one ModelRenderer with multiple boxes, not multiple ModelRenderers each with one box.
public class ModelWing implements PonyModelConstants {
public ModelRenderer[] folded = new ModelRenderer[3],
extended = new ModelRenderer[6];
public ModelWing(AbstractPonyModel pony, boolean mirror, float xOffset, float yOffset, float stretch, int texY) {
// TODO: Don't add the model to the pony if you're just going to remove it again.
for (int i = 0; i < folded.length; i++) {
folded[i] = new ModelRenderer(pony, 56, texY);
pony.boxList.remove(folded[i]);
}
for (int i = 0; i < extended.length; i++) {
extended[i] = new ModelRenderer(pony, 56, texY + 3);
pony.boxList.remove(extended[i]);
// this seems to hide the wings being a different size when folded
extended[i].mirror = mirror;
}
init(yOffset, xOffset, stretch);
addFeathers(mirror ? -1 : 1, yOffset, stretch);
}
private void addFeathers(float r, float y, float scale) {
addFeather(0, r, y, 6.0F, 0.0F, 8, scale + 0.1F);
addFeather(1, r, y, -1.2F, -0.2F, 8, scale + 0.2F);
addFeather(2, r, y, 1.8F, 1.3F, 8, scale - 0.1F);
addFeather(3, r, y, 5.0F, 2.0F, 8, scale);
addFeather(4, r, y, 0.0F, -0.2F, 6, scale + 0.3F);
addFeather(5, r, y, 0.0F, 0.2F, 3, scale + 0.19F);
}
private void addFeather(int i, float r, float Y, float y, float z, int h, float scale) {
extended[i].addBox(-0.5f, y, z, 1, h, 2, scale);
extended[i].setRotationPoint(r * LEFT_WING_EXT_RP_X, LEFT_WING_EXT_RP_Y + Y, LEFT_WING_EXT_RP_Z);
}
private void init(float x, float y, float scale) {
initFeather(folded[0], y, x, 2.0F, 6, scale);
initFeather(folded[1], y, x, 4.0F, 8, scale);
initFeather(folded[2], y, x, 6.0F, 6, scale);
}
private void initFeather(ModelRenderer wing, float y, float x, float z, int h, float scale) {
wing.addBox(x, 5f, z, 2, h, 2, scale);
wing.setRotationPoint(HEAD_RP_X, WING_FOLDED_RP_Y + y, WING_FOLDED_RP_Z);
wing.rotateAngleX = ROTATE_90;
}
public void updateModelRotation(float swing) {
for (ModelRenderer feather : folded) {
feather.rotateAngleY = swing * 0.2F;
}
}
public void rotate(float angle) {
for (ModelRenderer feather : folded) {
feather.rotateAngleX = angle;
}
// Special
extended[1].rotateAngleX -= 0.85F;
extended[2].rotateAngleX -= 0.75F;
extended[3].rotateAngleX -= 0.5F;
extended[5].rotateAngleX -= 0.85F;
}
private void renderWing(ModelRenderer[] wing, float scale) {
for (ModelRenderer feather : wing) {
feather.render(scale);
}
}
public void render(boolean standing, float scale) {
renderWing(standing ? folded : extended, scale);
}
public void rotateSneaked(float rotZ) {
for (ModelRenderer feather : extended) {
feather.rotateAngleX = EXT_WING_ROTATE_ANGLE_X;
feather.rotateAngleZ = rotZ;
}
}
public void rotateUnsneaked(float angle) {
for (ModelRenderer aLeftWingExt : extended) {
aLeftWingExt.rotateAngleX = EXT_WING_ROTATE_ANGLE_X;
aLeftWingExt.rotateAngleZ = -angle;
}
}
}

View file

@ -1,184 +1,53 @@
package com.minelittlepony.model; package com.minelittlepony.model;
import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
// TODO: Break this down into ModelWing (one for each side)
public class PegasusWings extends ModelBase implements PonyModelConstants { public class PegasusWings extends ModelBase implements PonyModelConstants {
private final AbstractPonyModel pony; private final AbstractPonyModel pony;
public ModelRenderer[] leftWing = new ModelRenderer[3], rightWing = new ModelRenderer[3], public final ModelWing leftWing, rightWing;
leftWingExt = new ModelRenderer[6], rightWingExt = new ModelRenderer[6];
public PegasusWings(AbstractPonyModel pony, float yOffset, float stretch) { public PegasusWings(AbstractPonyModel pony, float yOffset, float stretch) {
this.pony = pony; this.pony = pony;
// TODO: Don't add the model to the pony if you're just going to remove it again. leftWing = new ModelWing(pony, false, 4f, yOffset, stretch, 32);
for (int i = 0; i < leftWing.length; i++) { rightWing = new ModelWing(pony, true, -6f, yOffset, stretch, 16);
this.leftWing[i] = new ModelRenderer(pony, 56, 32);
this.pony.boxList.remove(this.leftWing[i]);
}
for (int i = 0; i < rightWing.length; i++) {
this.rightWing[i] = new ModelRenderer(pony, 56, 16);
this.pony.boxList.remove(this.rightWing[i]);
}
for (int i = 0; i < leftWingExt.length; i++) {
this.leftWingExt[i] = new ModelRenderer(pony, 56, 35);
this.pony.boxList.remove(this.leftWingExt[i]);
}
for (int i = 0; i < rightWingExt.length; i++) {
this.rightWingExt[i] = new ModelRenderer(pony, 56, 19);
// this seems to hide the wings being a different size when folded
this.rightWingExt[i].mirror = true;
this.pony.boxList.remove(this.rightWingExt[i]);
}
this.leftWing[0].addBox(4.0F, 5.0F, 2.0F, 2, 6, 2, stretch);
this.leftWing[0].setRotationPoint(HEAD_RP_X, WING_FOLDED_RP_Y + yOffset, WING_FOLDED_RP_Z);
this.leftWing[0].rotateAngleX = ROTATE_90;
this.leftWing[1].addBox(4.0F, 5.0F, 4.0F, 2, 8, 2, stretch);
this.leftWing[1].setRotationPoint(HEAD_RP_X, WING_FOLDED_RP_Y + yOffset, WING_FOLDED_RP_Z);
this.leftWing[1].rotateAngleX = ROTATE_90;
this.leftWing[2].addBox(4.0F, 5.0F, 6.0F, 2, 6, 2, stretch);
this.leftWing[2].setRotationPoint(HEAD_RP_X, WING_FOLDED_RP_Y + yOffset, WING_FOLDED_RP_Z);
this.leftWing[2].rotateAngleX = ROTATE_90;
this.rightWing[0].addBox(-6.0F, 5.0F, 2.0F, 2, 6, 2, stretch);
this.rightWing[0].setRotationPoint(HEAD_RP_X, WING_FOLDED_RP_Y + yOffset, WING_FOLDED_RP_Z);
this.rightWing[0].rotateAngleX = ROTATE_90;
this.rightWing[1].addBox(-6.0F, 5.0F, 4.0F, 2, 8, 2, stretch);
this.rightWing[1].setRotationPoint(HEAD_RP_X, WING_FOLDED_RP_Y + yOffset, WING_FOLDED_RP_Z);
this.rightWing[1].rotateAngleX = ROTATE_90;
this.rightWing[2].addBox(-6.0F, 5.0F, 6.0F, 2, 6, 2, stretch);
this.rightWing[2].setRotationPoint(HEAD_RP_X, WING_FOLDED_RP_Y + yOffset, WING_FOLDED_RP_Z);
this.rightWing[2].rotateAngleX = ROTATE_90;
this.leftWingExt[0].addBox(-0.5F, 6.0F, 0.0F, 1, 8, 2, stretch + 0.1F);
this.leftWingExt[0].setRotationPoint(LEFT_WING_EXT_RP_X, LEFT_WING_EXT_RP_Y + yOffset, LEFT_WING_EXT_RP_Z);
this.leftWingExt[1].addBox(-0.5F, -1.2F, -0.2F, 1, 8, 2, stretch - 0.2F);
this.leftWingExt[1].setRotationPoint(LEFT_WING_EXT_RP_X, LEFT_WING_EXT_RP_Y + yOffset, LEFT_WING_EXT_RP_Z);
this.leftWingExt[2].addBox(-0.5F, 1.8F, 1.3F, 1, 8, 2, stretch - 0.1F);
this.leftWingExt[2].setRotationPoint(LEFT_WING_EXT_RP_X, LEFT_WING_EXT_RP_Y + yOffset, LEFT_WING_EXT_RP_Z);
this.leftWingExt[3].addBox(-0.5F, 5.0F, 2.0F, 1, 8, 2, stretch);
this.leftWingExt[3].setRotationPoint(LEFT_WING_EXT_RP_X, LEFT_WING_EXT_RP_Y + yOffset, LEFT_WING_EXT_RP_Z);
this.leftWingExt[4].addBox(-0.5F, 0.0F, -0.2F, 1, 6, 2, stretch + 0.3F);
this.leftWingExt[4].setRotationPoint(LEFT_WING_EXT_RP_X, LEFT_WING_EXT_RP_Y + yOffset, LEFT_WING_EXT_RP_Z);
this.leftWingExt[5].addBox(-0.5F, 0.0F, 0.2F, 1, 3, 2, stretch + 0.19F);
this.leftWingExt[5].setRotationPoint(LEFT_WING_EXT_RP_X, LEFT_WING_EXT_RP_Y + yOffset, LEFT_WING_EXT_RP_Z);
this.rightWingExt[0].addBox(-0.5F, 6.0F, 0.0F, 1, 8, 2, stretch + 0.1F);
this.rightWingExt[0].setRotationPoint(RIGHT_WING_EXT_RP_X, RIGHT_WING_EXT_RP_Y + yOffset, RIGHT_WING_EXT_RP_Z);
this.rightWingExt[1].addBox(-0.5F, -1.2F, -0.2F, 1, 8, 2, stretch - 0.2F);
this.rightWingExt[1].setRotationPoint(RIGHT_WING_EXT_RP_X, RIGHT_WING_EXT_RP_Y + yOffset, RIGHT_WING_EXT_RP_Z);
this.rightWingExt[2].addBox(-0.5F, 1.8F, 1.3F, 1, 8, 2, stretch - 0.1F);
this.rightWingExt[2].setRotationPoint(RIGHT_WING_EXT_RP_X, RIGHT_WING_EXT_RP_Y + yOffset, RIGHT_WING_EXT_RP_Z);
this.rightWingExt[3].addBox(-0.5F, 5.0F, 2.0F, 1, 8, 2, stretch);
this.rightWingExt[3].setRotationPoint(RIGHT_WING_EXT_RP_X, RIGHT_WING_EXT_RP_Y + yOffset, RIGHT_WING_EXT_RP_Z);
this.rightWingExt[4].addBox(-0.5F, 0.0F, -0.2F, 1, 6, 2, stretch + 0.3F);
this.rightWingExt[4].setRotationPoint(RIGHT_WING_EXT_RP_X, RIGHT_WING_EXT_RP_Y + yOffset, RIGHT_WING_EXT_RP_Z);
this.rightWingExt[5].addBox(-0.5F, 0.0F, 0.2F, 1, 3, 2, stretch + 0.19F);
this.rightWingExt[5].setRotationPoint(RIGHT_WING_EXT_RP_X, RIGHT_WING_EXT_RP_Y + yOffset, RIGHT_WING_EXT_RP_Z);
} }
@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 ticks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) {
float bodySwingRotation = 0.0F; float bodySwingRotation = 0.0F;
if (pony.swingProgress > -9990.0F && !pony.metadata.hasMagic()) { if (pony.swingProgress > -9990.0F && !pony.metadata.hasMagic()) {
bodySwingRotation = MathHelper.sin(MathHelper.sqrt(pony.swingProgress) * 3.1415927F * 2.0F) * 0.2F; bodySwingRotation = MathHelper.sin(MathHelper.sqrt(pony.swingProgress) * 3.1415927F * 2.0F) * 0.2F;
} }
for (ModelRenderer aLeftWing : this.leftWing) {
aLeftWing.rotateAngleY = bodySwingRotation * 0.2F; leftWing.updateModelRotation(bodySwingRotation);
} rightWing.updateModelRotation(bodySwingRotation);
for (ModelRenderer aRightWing : this.rightWing) {
aRightWing.rotateAngleY = bodySwingRotation * 0.2F;
}
if (pony.isSneak && !pony.isFlying) { if (pony.isSneak && !pony.isFlying) {
this.sneak(); leftWing.rotateSneaked(LEFT_WING_ROTATE_ANGLE_Z_SNEAK);
} else { rightWing.rotateSneaked(RIGHT_WING_ROTATE_ANGLE_Z_SNEAK);
this.unsneak(ageInTicks); } else if (pony.isFlying) {
float WingRotateAngleZ = (MathHelper.sin(ticks * 0.536F) * 1.0F) + ROTATE_270 + 0.4F;
leftWing.rotateUnsneaked(-WingRotateAngleZ);
rightWing.rotateUnsneaked(WingRotateAngleZ);
} }
float angle = ROTATE_90; leftWing.rotate(ROTATE_90);
rightWing.rotate(ROTATE_90);
for (ModelRenderer aLeftWing : this.leftWing) {
aLeftWing.rotateAngleX = angle;
}
for (ModelRenderer aRightWing : this.rightWing) {
aRightWing.rotateAngleX = angle;
}
// Special
this.leftWingExt[1].rotateAngleX -= 0.85F;
this.leftWingExt[2].rotateAngleX -= 0.75F;
this.leftWingExt[3].rotateAngleX -= 0.5F;
this.leftWingExt[5].rotateAngleX -= 0.85F;
this.rightWingExt[1].rotateAngleX -= 0.85F;
this.rightWingExt[2].rotateAngleX -= 0.75F;
this.rightWingExt[3].rotateAngleX -= 0.5F;
this.rightWingExt[5].rotateAngleX -= 0.85F;
} }
@Override @Override
public void render(Entity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) { public void render(Entity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
if (pony.metadata.getRace().hasWings()) { if (pony.metadata.getRace().hasWings()) {
if (!pony.isFlying && !pony.isSneak) { boolean standing = !pony.isFlying && !pony.isSneak;
leftWing.render(standing, scale);
for (ModelRenderer aLeftWing : this.leftWing) { rightWing.render(standing, scale);
aLeftWing.render(scale);
}
for (ModelRenderer aRightWing : this.rightWing) {
aRightWing.render(scale);
}
} else {
for (ModelRenderer aLeftWingExt : this.leftWingExt) {
aLeftWingExt.render(scale);
}
for (ModelRenderer aRightWingExt : this.rightWingExt) {
aRightWingExt.render(scale);
}
}
} }
} }
private void sneak() {
for (ModelRenderer aLeftWingExt : this.leftWingExt) {
aLeftWingExt.rotateAngleX = EXT_WING_ROTATE_ANGLE_X;
aLeftWingExt.rotateAngleZ = LEFT_WING_ROTATE_ANGLE_Z_SNEAK;
}
for (int i = 0; i < this.leftWingExt.length; ++i) {
this.rightWingExt[i].rotateAngleX = EXT_WING_ROTATE_ANGLE_X;
this.rightWingExt[i].rotateAngleZ = RIGHT_WING_ROTATE_ANGLE_Z_SNEAK;
}
}
// TODO: Combine each wing into one ModelRenderer with multiple boxes, not multiple ModelRenderers each with one box.
private void unsneak(float tick) {
if (pony.isFlying) {
float WingRotateAngleZ = (MathHelper.sin(tick * 0.536F) * 1.0F) + ROTATE_270 + 0.4F;
for (ModelRenderer aLeftWingExt : this.leftWingExt) {
aLeftWingExt.rotateAngleX = EXT_WING_ROTATE_ANGLE_X;
aLeftWingExt.rotateAngleZ = -WingRotateAngleZ;
}
for (ModelRenderer aRightWingExt : this.rightWingExt) {
aRightWingExt.rotateAngleX = EXT_WING_ROTATE_ANGLE_X;
aRightWingExt.rotateAngleZ = WingRotateAngleZ;
}
}
}
} }