From ea38a6f1ff2ce2ae67d4deea440c47e3429a45dc Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 5 Jan 2022 18:54:54 +0200 Subject: [PATCH] Added a wing spreading animation --- .../unicopia/client/minelittlepony/Main.java | 7 +++++++ .../unicopia/client/render/PlayerPoser.java | 18 ++++++++---------- .../unicopia/entity/player/PlayerPhysics.java | 7 +++++++ .../unicopia/util/AnimationUtil.java | 19 +++++++++++++++++++ 4 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/util/AnimationUtil.java diff --git a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/Main.java b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/Main.java index c3a6ce78..e90c7672 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/Main.java +++ b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/Main.java @@ -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); diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/PlayerPoser.java b/src/main/java/com/minelittlepony/unicopia/client/render/PlayerPoser.java index 2764482f..edab91b6 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/PlayerPoser.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/PlayerPoser.java @@ -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 sound; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java index 88c31cf8..67bb87c1 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java @@ -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 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()) { diff --git a/src/main/java/com/minelittlepony/unicopia/util/AnimationUtil.java b/src/main/java/com/minelittlepony/unicopia/util/AnimationUtil.java new file mode 100644 index 00000000..c5c3fcd3 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/util/AnimationUtil.java @@ -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); + } +}