From 5fb54aa2fdbd94b05c0064101fc8c006ad7422ed Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 7 Feb 2024 10:56:13 +0000 Subject: [PATCH] Fixed changeling wing animations and posing --- .../client/minelittlepony/BodyPartGear.java | 32 +++++--- .../minelittlepony/UnicopiaPonyData.java | 75 +++++++++++++++++++ 2 files changed, 98 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/client/minelittlepony/UnicopiaPonyData.java diff --git a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/BodyPartGear.java b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/BodyPartGear.java index 3ec5d015..76f267f5 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/BodyPartGear.java +++ b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/BodyPartGear.java @@ -6,6 +6,7 @@ import java.util.function.Predicate; import com.minelittlepony.api.model.*; import com.minelittlepony.api.model.gear.IGear; +import com.minelittlepony.api.pony.IPonyData; import com.minelittlepony.client.model.ClientPonyModel; import com.minelittlepony.client.model.ModelType; import com.minelittlepony.client.model.PlayerModelKey; @@ -16,7 +17,7 @@ import com.minelittlepony.client.model.part.UnicornHorn; import com.minelittlepony.mson.api.MsonModel; import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.FlightType; -import com.minelittlepony.unicopia.Race; + import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.entity.AmuletSelectors; @@ -27,6 +28,8 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.util.Identifier; +import com.minelittlepony.api.pony.meta.Race; + class BodyPartGear & MsonModel & IModel> implements IGear { private static final Predicate MINE_LP_HAS_NO_WINGS = e -> !MineLPDelegate.getInstance().getRace(e).canFly(); @@ -41,14 +44,14 @@ class BodyPartGear & MsonModel & IModel> public static final Predicate BAT_WINGS_PREDICATE = MINE_LP_HAS_NO_WINGS.and(AmuletSelectors.PEGASUS_AMULET.negate()).and(EquinePredicates.PLAYER_BAT); public static final Identifier BAT_WINGS = Unicopia.id("textures/models/wings/bat_pony.png"); - public static final Predicate UNICORN_HORN_PREDICATE = MINE_LP_HAS_NO_HORN.and(AmuletSelectors.ALICORN_AMULET.or(EquinePredicates.raceMatches(Race::canCast))); + public static final Predicate UNICORN_HORN_PREDICATE = MINE_LP_HAS_NO_HORN.and(AmuletSelectors.ALICORN_AMULET.or(EquinePredicates.raceMatches(com.minelittlepony.unicopia.Race::canCast))); public static final Identifier UNICORN_HORN = Unicopia.id("textures/models/horn/unicorn.png"); public static final Predicate PEGA_WINGS_PREDICATE = MINE_LP_HAS_NO_WINGS.and(AmuletSelectors.PEGASUS_AMULET.or(EquinePredicates.raceMatches(race -> race.flightType() == FlightType.AVIAN))); public static final Identifier PEGASUS_WINGS = Unicopia.id("textures/models/wings/pegasus_pony.png"); public static BodyPartGear pegasusWings() { - return new BodyPartGear<>(BodyPart.BODY, ModelType.PEGASUS, PEGA_WINGS_PREDICATE, WingsGearModel::new, WingsGearModel::getWings, e -> { + return new BodyPartGear<>(Race.PEGASUS, BodyPart.BODY, ModelType.PEGASUS, PEGA_WINGS_PREDICATE, WingsGearModel::new, WingsGearModel::getWings, e -> { if (AmuletSelectors.PEGASUS_AMULET.test((LivingEntity)e)) { return e.getWorld().getDimension().ultrawarm() ? ICARUS_WINGS_CORRUPTED : ICARUS_WINGS; } @@ -57,15 +60,15 @@ class BodyPartGear & MsonModel & IModel> } public static BodyPartGear batWings() { - return new BodyPartGear<>(BodyPart.BODY, ModelType.BAT_PONY, BAT_WINGS_PREDICATE, WingsGearModel::new, IPegasus::getWings, e -> BAT_WINGS); + return new BodyPartGear<>(Race.BATPONY, BodyPart.BODY, ModelType.BAT_PONY, BAT_WINGS_PREDICATE, WingsGearModel::new, IPegasus::getWings, e -> BAT_WINGS); } public static BodyPartGear bugWings() { - return new BodyPartGear<>(BodyPart.BODY, ModelType.CHANGELING, BUG_WINGS_PREDICATE, BugWingsGearModel::new, IPegasus::getWings, e -> BUG_WINGS); + return new BodyPartGear<>(Race.CHANGELING, BodyPart.BODY, ModelType.CHANGELING, BUG_WINGS_PREDICATE, BugWingsGearModel::new, IPegasus::getWings, e -> BUG_WINGS); } public static BodyPartGear unicornHorn() { - return new BodyPartGear<>(BodyPart.HEAD, ModelType.UNICORN, UNICORN_HORN_PREDICATE, HornGearModel::new, HornGearModel::getHorn, e -> UNICORN_HORN); + return new BodyPartGear<>(Race.UNICORN, BodyPart.HEAD, ModelType.UNICORN, UNICORN_HORN_PREDICATE, HornGearModel::new, HornGearModel::getHorn, e -> UNICORN_HORN); } private final M model; @@ -73,14 +76,17 @@ class BodyPartGear & MsonModel & IModel> private final IPart part; private final Function textureSupplier; private final BodyPart gearLocation; + private final UnicopiaPonyData ponyData; public BodyPartGear( + Race race, BodyPart gearLocation, PlayerModelKey modelKey, Predicate renderTargetPredicate, MsonModel.Factory modelFactory, Function partExtractor, Function textureSupplier) { + this.ponyData = new UnicopiaPonyData(race); this.gearLocation = gearLocation; this.model = modelKey.steveKey().createModel(modelFactory); this.part = partExtractor.apply(this.model); @@ -107,9 +113,17 @@ class BodyPartGear & MsonModel & IModel> @SuppressWarnings({ "unchecked", "rawtypes" }) @Override - public void pose(IModel model, Entity entity, boolean rainboom, UUID interpolatorId, float move, float swing, float bodySwing, float ticks) { - ((ClientPonyModel)model).copyAttributes(this.model); - part.setPartAngles(this.model.getAttributes(), move, swing, bodySwing, ticks); + public void pose(IModel model, Entity entity, boolean rainboom, UUID interpolatorId, float move, float swing, float bodySwing, float tickDelta) { + final IPonyData data = this.model.getAttributes().metadata; + try { + ponyData.original = data; + ((ClientPonyModel)model).copyAttributes(this.model); + this.model.getAttributes().metadata = ponyData; + this.model.animateModel((LivingEntity)entity, move, swing, tickDelta); + this.model.setAngles((LivingEntity)entity, move, swing, entity.age + tickDelta, 0, 0); + } finally { + this.model.getAttributes().metadata = data; + } } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/UnicopiaPonyData.java b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/UnicopiaPonyData.java new file mode 100644 index 00000000..063d46b5 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/UnicopiaPonyData.java @@ -0,0 +1,75 @@ +package com.minelittlepony.unicopia.client.minelittlepony; + +import java.util.Map; +import java.util.UUID; + +import com.minelittlepony.api.pony.IPonyData; +import com.minelittlepony.api.pony.TriggerPixelType; +import com.minelittlepony.api.pony.meta.Gender; +import com.minelittlepony.api.pony.meta.Race; +import com.minelittlepony.api.pony.meta.Size; +import com.minelittlepony.api.pony.meta.TailLength; +import com.minelittlepony.api.pony.meta.TailShape; +import com.minelittlepony.api.pony.meta.Wearable; +import com.minelittlepony.common.util.animation.Interpolator; + +public class UnicopiaPonyData implements IPonyData { + + Race race; + IPonyData original; + + public UnicopiaPonyData(Race race) { + this.race = race; + } + + @Override + public Race getRace() { + return race; + } + + @Override + public TailLength getTailLength() { + return original.getTailLength(); + } + + @Override + public TailShape getTailShape() { + return original.getTailShape(); + } + + @Override + public Gender getGender() { + return original.getGender(); + } + + @Override + public Size getSize() { + return original.getSize(); + } + + @Override + public int getGlowColor() { + return original.getGlowColor(); + } + + @Override + public Wearable[] getGear() { + return original.getGear(); + } + + @Override + public boolean isWearing(Wearable wearable) { + return original.isWearing(wearable); + } + + @Override + public Interpolator getInterpolator(UUID interpolatorId) { + return original.getInterpolator(interpolatorId); + } + + @Override + public Map> getTriggerPixels() { + return original.getTriggerPixels(); + } + +}