Added a wing spreading animation

This commit is contained in:
Sollace 2022-01-05 18:54:54 +02:00
parent 188c3a5523
commit ea38a6f1ff
4 changed files with 41 additions and 10 deletions

View file

@ -6,7 +6,9 @@ import com.minelittlepony.api.model.fabric.PonyModelPrepareCallback;
import com.minelittlepony.api.model.gear.IGear;
import com.minelittlepony.unicopia.Owned;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation;
import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.AnimationUtil;
import net.fabricmc.api.ClientModInitializer;
import net.minecraft.entity.Entity;
@ -39,6 +41,11 @@ public class Main implements ClientModInitializer {
model.getAttributes().isHorizontal = true;
}
model.getAttributes().isGoingFast |= pony.getMotion().isRainbooming();
if (pony.getAnimation() == Animation.SPREAD_WINGS) {
model.getAttributes().wingAngle = -AnimationUtil.seeSitSaw(pony.getAnimationProgress(1), 1.5F) * (float)Math.PI / 1.2F;
model.getAttributes().isFlying = true;
}
}
} catch (Throwable t) {
Unicopia.LOGGER.error("Exception occured in MineLP hook:onPonyModelPrepared", t);

View file

@ -5,6 +5,7 @@ import java.util.Optional;
import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.client.minelittlepony.MineLPConnector;
import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.AnimationUtil;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.entity.model.BipedEntityModel;
@ -73,7 +74,7 @@ public class PlayerPoser {
}
case WAVE_ONE:
case WAVE_TWO: {
progress = seesaw(progress);
progress = AnimationUtil.seesaw(progress);
if (animation == Animation.WAVE_TWO && isPony) {
rearUp(matrices, model, progress);
@ -124,7 +125,7 @@ public class PlayerPoser {
break;
}
case STOMP: {
progress = seesaw(progress);
progress = AnimationUtil.seesaw(progress);
if (!isPony) {
if (player.getMainArm() == Arm.LEFT) {
@ -145,10 +146,10 @@ public class PlayerPoser {
break;
}
progress = seesaw(progress) * MathHelper.sin(player.age / 4F);
progress = AnimationUtil.seesaw(progress) * MathHelper.sin(player.age) / 7F;
model.getHead().getChild("mare").pivotY += progress;
model.getHead().getChild("stallion").pivotY += progress;
model.getHead().getChild("mare").pivotY = progress;
model.getHead().getChild("stallion").pivotY = progress;
break;
}
default:
@ -169,10 +170,6 @@ public class PlayerPoser {
model.leftLeg.yaw = roll / 7F;
}
static float seesaw(float progress) {
return Math.max(0, MathHelper.cos((progress - 0.5F) * (float)Math.PI));
}
public enum Animation {
NONE(0),
WOLOLO(USounds.ENTITY_PLAYER_WOLOLO, 40),
@ -182,7 +179,8 @@ public class PlayerPoser {
WAVE_TWO(USounds.ENTITY_PLAYER_WHISTLE, 20),
KICK(USounds.ENTITY_PLAYER_KICK, 5),
STOMP(5),
WIGGLE_NOSE(6);
WIGGLE_NOSE(6),
SPREAD_WINGS(6);
private final int duration;
private final Optional<SoundEvent> sound;

View file

@ -7,6 +7,7 @@ import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.ability.magic.SpellPredicate;
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.advancement.UCriteria;
import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation;
import com.minelittlepony.unicopia.entity.Creature;
import com.minelittlepony.unicopia.entity.EntityPhysics;
import com.minelittlepony.unicopia.entity.Jumper;
@ -18,6 +19,7 @@ import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
import com.minelittlepony.unicopia.projectile.ProjectileUtil;
import com.minelittlepony.unicopia.util.NbtSerialisable;
import com.minelittlepony.unicopia.util.Tickable;
import com.minelittlepony.unicopia.util.AnimationUtil;
import com.minelittlepony.unicopia.util.MutableVector;
import net.minecraft.block.Block;
@ -99,6 +101,11 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
@Override
public float getWingAngle() {
if (pony.getAnimation() == Animation.SPREAD_WINGS) {
return AnimationUtil.seeSitSaw(pony.getAnimationProgress(1), 1.5F);
}
float spreadAmount = -0.5F;
if (isFlying()) {

View file

@ -0,0 +1,19 @@
package com.minelittlepony.unicopia.util;
import net.minecraft.util.math.MathHelper;
public interface AnimationUtil {
/**
* Converts a smooth 0-1 transition to a smooth 0-1-0 transition
*/
static float seesaw(float progress) {
return Math.max(0, MathHelper.cos((progress - 0.5F) * (float)Math.PI));
}
/**
* Converts a smooth 0-1 transition to a stretched 0-1-1-1-1-0 transition
*/
static float seeSitSaw(float progress, float clipRatio) {
return Math.min(1, seesaw(progress) * clipRatio);
}
}