Separate wing angle and whether a model is horizontal into separate model attributes

This commit is contained in:
Sollace 2021-03-01 00:16:39 +02:00
parent 120965fb8b
commit c7ea57c2b6
6 changed files with 36 additions and 21 deletions

View file

@ -13,7 +13,7 @@ org.gradle.daemon=false
displayname=Mine Little Pony displayname=Mine Little Pony
authors=Verdana, Rene_Z, Mumfrey, Killjoy1221, Sollace authors=Verdana, Rene_Z, Mumfrey, Killjoy1221, Sollace
description=Mine Little Pony turns players and mobs into ponies. Press F9 ingame to access settings. description=Mine Little Pony turns players and mobs into ponies. Press F9 ingame to access settings.
version=4.2.1 version=4.2.2
release=SNAPSHOT release=SNAPSHOT
# Dependencies # Dependencies

View file

@ -68,7 +68,7 @@ public abstract class AbstractPonyModel<T extends LivingEntity> extends ClientPo
*/ */
@Override @Override
public void setAngles(T entity, float move, float swing, float ticks, float headYaw, float headPitch) { public void setAngles(T entity, float move, float swing, float ticks, float headYaw, float headPitch) {
attributes.checkRainboom(entity, swing, canFly()); attributes.checkRainboom(entity, swing, canFly(), ticks);
PonyModelPrepareCallback.EVENT.invoker().onPonyModelPrepared(entity, this, EquineRenderManager.Mode.OTHER); PonyModelPrepareCallback.EVENT.invoker().onPonyModelPrepared(entity, this, EquineRenderManager.Mode.OTHER);
super.setAngles(entity, move, swing, ticks, headYaw, headPitch); super.setAngles(entity, move, swing, ticks, headYaw, headPitch);

View file

@ -114,15 +114,15 @@ public class EquineRenderManager<T extends LivingEntity, M extends EntityModel<T
} }
if (entity.isAlive() && entity.isSleeping()) { if (entity.isAlive() && entity.isSleeping()) {
return PonyPosture.DEFAULT; return PonyPosture.STANDING;
} }
if (getModel().getAttributes().isSwimming) { if (getModel().getAttributes().isHorizontal) {
return PonyPosture.SWIMMING; return PonyPosture.SWIMMING;
} }
if (getModel().getAttributes().isGoingFast) { if (getModel().getAttributes().isGoingFast) {
return PonyPosture.FLIGHT; return PonyPosture.FLYING;
} }
return PonyPosture.FALLING; return PonyPosture.FALLING;

View file

@ -8,9 +8,9 @@ import com.minelittlepony.model.IModel;
public interface PonyPosture<T extends LivingEntity> { public interface PonyPosture<T extends LivingEntity> {
PonyPosture<LivingEntity> DEFAULT = new PostureStanding();; PonyPosture<LivingEntity> STANDING = new PostureStanding();;
PonyPosture<LivingEntity> ELYTRA = new PostureElytra(); PonyPosture<LivingEntity> ELYTRA = new PostureElytra();
PonyPosture<PlayerEntity> FLIGHT = new PostureFlight(); PonyPosture<PlayerEntity> FLYING = new PostureFlight();
PonyPosture<PlayerEntity> SWIMMING = new PostureSwimming(); PonyPosture<PlayerEntity> SWIMMING = new PostureSwimming();
PonyPosture<LivingEntity> FALLING = new PostureFalling(); PonyPosture<LivingEntity> FALLING = new PostureFalling();

View file

@ -1,10 +1,5 @@
package com.minelittlepony.model; package com.minelittlepony.model;
import net.minecraft.util.math.MathHelper;
import static com.minelittlepony.model.PonyModelConstants.ROTATE_270;
import static com.minelittlepony.model.PonyModelConstants.WING_ROT_Z_SNEAK;
public interface IPegasus extends IModel { public interface IPegasus extends IModel {
/** /**
@ -25,13 +20,7 @@ public interface IPegasus extends IModel {
* @param ticks Partial render ticks * @param ticks Partial render ticks
*/ */
default float getWingRotationFactor(float ticks) { default float getWingRotationFactor(float ticks) {
if (getAttributes().isSwimming) { return getAttributes().wingAngle;
return (MathHelper.sin(ticks * 0.136f) / 2) + ROTATE_270;
}
if (isFlying()) {
return MathHelper.sin(ticks * 0.536f) + ROTATE_270 + 0.4f;
}
return WING_ROT_Z_SNEAK;
} }
} }

View file

@ -8,10 +8,14 @@ import com.minelittlepony.util.MathUtil;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Arm; import net.minecraft.util.Arm;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import java.util.UUID; import java.util.UUID;
import static com.minelittlepony.model.PonyModelConstants.ROTATE_270;
import static com.minelittlepony.model.PonyModelConstants.WING_ROT_Z_SNEAK;
public class ModelAttributes<T extends LivingEntity> { public class ModelAttributes<T extends LivingEntity> {
/** /**
@ -27,6 +31,10 @@ public class ModelAttributes<T extends LivingEntity> {
* from regular flying in that there are actual "wings" involved. * from regular flying in that there are actual "wings" involved.
*/ */
public boolean isGliding; public boolean isGliding;
/**
* True if the model is rotated 90degs (players)
*/
public boolean isHorizontal;
/** /**
* True if the model is swimming under water. * True if the model is swimming under water.
*/ */
@ -79,10 +87,15 @@ public class ModelAttributes<T extends LivingEntity> {
*/ */
public float visualHeight = 2F; public float visualHeight = 2F;
/**
* The angle used to animate wing flaps whilst flying/swimming.
*/
public float wingAngle;
/** /**
* Checks flying and speed conditions and sets rainboom to true if we're a species with wings and is going faaast. * Checks flying and speed conditions and sets rainboom to true if we're a species with wings and is going faaast.
*/ */
public void checkRainboom(T entity, float swing, boolean hasWings) { public void checkRainboom(T entity, float swing, boolean hasWings, float ticks) {
Vec3d motion = entity.getVelocity(); Vec3d motion = entity.getVelocity();
double zMotion = Math.sqrt(motion.x * motion.x + motion.z * motion.z); double zMotion = Math.sqrt(motion.x * motion.x + motion.z * motion.z);
@ -90,6 +103,18 @@ public class ModelAttributes<T extends LivingEntity> {
isGoingFast &= zMotion > 0.4F; isGoingFast &= zMotion > 0.4F;
motionLerp = MathUtil.clampLimit(zMotion * 30, 1); motionLerp = MathUtil.clampLimit(zMotion * 30, 1);
wingAngle = calcWingRotationFactor(ticks);
}
private float calcWingRotationFactor(float ticks) {
if (isSwimming) {
return (MathHelper.sin(ticks * 0.136f) / 2) + ROTATE_270;
}
if (isFlying) {
return MathHelper.sin(ticks * 0.536f) + ROTATE_270 + 0.4f;
}
return WING_ROT_Z_SNEAK;
} }
public void updateLivingState(T entity, IPony pony, EquineRenderManager.Mode mode) { public void updateLivingState(T entity, IPony pony, EquineRenderManager.Mode mode) {
@ -99,7 +124,8 @@ public class ModelAttributes<T extends LivingEntity> {
isFlying = mode == Mode.THIRD_PERSON && pony.isFlying(entity); isFlying = mode == Mode.THIRD_PERSON && pony.isFlying(entity);
isGliding = entity.isFallFlying(); isGliding = entity.isFallFlying();
isSwimming = mode == Mode.THIRD_PERSON && pony.isSwimming(entity); isSwimming = mode == Mode.THIRD_PERSON && pony.isSwimming(entity);
isSwimmingRotated = mode == Mode.THIRD_PERSON && isSwimming && (entity instanceof PlayerEntity || entity instanceof IRotatedSwimmer); isSwimmingRotated = isSwimming && (entity instanceof PlayerEntity || entity instanceof IRotatedSwimmer);
isHorizontal = isSwimming;
isRidingInteractive = pony.isRidingInteractive(entity); isRidingInteractive = pony.isRidingInteractive(entity);
interpolatorId = entity.getUuid(); interpolatorId = entity.getUuid();
isLeftHanded = entity.getMainArm() == Arm.LEFT; isLeftHanded = entity.getMainArm() == Arm.LEFT;