diff --git a/src/api/java/com/minelittlepony/MineLittlePony.java b/src/api/java/com/minelittlepony/MineLittlePony.java new file mode 100644 index 00000000..25f05b3c --- /dev/null +++ b/src/api/java/com/minelittlepony/MineLittlePony.java @@ -0,0 +1,11 @@ +package com.minelittlepony; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class MineLittlePony { + public static Object getConfig() { + return null; + } +} diff --git a/src/api/java/com/minelittlepony/model/anim/BasicEasingInterpolator.java b/src/api/java/com/minelittlepony/model/anim/BasicEasingInterpolator.java new file mode 100644 index 00000000..9354e201 --- /dev/null +++ b/src/api/java/com/minelittlepony/model/anim/BasicEasingInterpolator.java @@ -0,0 +1,35 @@ +package com.minelittlepony.model.anim; + +import java.util.HashMap; +import java.util.Map; + +public class BasicEasingInterpolator implements IInterpolator { + + private final Map properties = new HashMap(); + + private float getLast(String key, float to) { + if (properties.containsKey(key)) { + return properties.get(key); + } + + return to; + } + + @Override + public float interpolate(String key, float to, float scalingFactor) { + float from = getLast(key, to); + + from += (to - from) / scalingFactor; + + if (Float.isNaN(from) || Float.isInfinite(from)) { + System.err.println("Error: Animation frame for " + key + " is NaN or Infinite."); + from = to; + } + + properties.put(key, from); + + return from; + + } + +} diff --git a/src/api/java/com/minelittlepony/model/anim/IInterpolator.java b/src/api/java/com/minelittlepony/model/anim/IInterpolator.java new file mode 100644 index 00000000..ad271b70 --- /dev/null +++ b/src/api/java/com/minelittlepony/model/anim/IInterpolator.java @@ -0,0 +1,16 @@ +package com.minelittlepony.model.anim; + +/** + * Interpolator function for handling transitions between animation states. + */ +@FunctionalInterface +public interface IInterpolator { + /** + * Interpolates a value between the requested final destination and what it was last. + * + * @param key Identifier to track previous values + * @param to The new values + * @param scalingFactor Scaling factor to control how quickly values change + */ + float interpolate(String key, float to, float scalingFactor); +} diff --git a/src/api/java/com/minelittlepony/pony/data/IPony.java b/src/api/java/com/minelittlepony/pony/data/IPony.java new file mode 100644 index 00000000..b1597170 --- /dev/null +++ b/src/api/java/com/minelittlepony/pony/data/IPony.java @@ -0,0 +1,17 @@ +package com.minelittlepony.pony.data; + +import net.minecraft.client.entity.AbstractClientPlayer; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +// Stub +@SideOnly(Side.CLIENT) +public interface IPony { + + static IPony forPlayer(AbstractClientPlayer player) { + return null; + } + + PonyRace getRace(boolean ignorePony); + +} diff --git a/src/api/java/com/minelittlepony/pony/data/PonyRace.java b/src/api/java/com/minelittlepony/pony/data/PonyRace.java new file mode 100644 index 00000000..a7ef4eca --- /dev/null +++ b/src/api/java/com/minelittlepony/pony/data/PonyRace.java @@ -0,0 +1,33 @@ +package com.minelittlepony.pony.data; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +// Stub +@SideOnly(Side.CLIENT) +public enum PonyRace { + HUMAN, + EARTH, + PEGASUS, + UNICORN, + ALICORN, + CHANGELING, + ZEBRA, + REFORMED_CHANGELING, + GRIFFIN, + HIPPOGRIFF, + BATPONY, + SEAPONY; + + public boolean hasHorn() { + return false; + } + + public boolean hasWings() { + return false; + } + + public boolean isHuman() { + return this == HUMAN; + } +} diff --git a/src/api/java/com/minelittlepony/transform/MotionCompositor.java b/src/api/java/com/minelittlepony/transform/MotionCompositor.java new file mode 100644 index 00000000..2a008197 --- /dev/null +++ b/src/api/java/com/minelittlepony/transform/MotionCompositor.java @@ -0,0 +1,47 @@ +package com.minelittlepony.transform; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.math.MathHelper; + +import com.minelittlepony.util.math.MathUtil; + +public abstract class MotionCompositor { + + protected double calculateRoll(EntityPlayer player, double motionX, double motionY, double motionZ) { + + // since model roll should probably be calculated from model rotation rather than entity rotation... + double roll = MathUtil.sensibleAngle(player.prevRenderYawOffset - player.renderYawOffset); + double horMotion = Math.sqrt(motionX * motionX + motionZ * motionZ); + float modelYaw = MathUtil.sensibleAngle(player.renderYawOffset); + + // detecting that we're flying backwards and roll must be inverted + if (Math.abs(MathUtil.sensibleAngle((float) Math.toDegrees(Math.atan2(motionX, motionZ)) + modelYaw)) > 90) { + roll *= -1; + } + + // ayyy magic numbers (after 5 - an approximation of nice looking coefficients calculated by hand) + + // roll might be zero, in which case Math.pow produces +Infinity. Anything x Infinity = NaN. + double pow = roll != 0 ? Math.pow(Math.abs(roll), -0.191) : 0; + + roll *= horMotion * 5 * (3.6884f * pow); + + assert !Float.isNaN((float)roll); + + return MathHelper.clamp(roll, -54, 54); + } + + protected double calculateIncline(EntityPlayer player, double motionX, double motionY, double motionZ) { + double dist = Math.sqrt(motionX * motionX + motionZ * motionZ); + double angle = Math.atan2(motionY, dist); + + if (!player.capabilities.isFlying) { + angle /= 2; + } + + angle = MathUtil.clampLimit(angle, Math.PI / 3); + + return Math.toDegrees(angle); + } + +} diff --git a/src/api/java/com/minelittlepony/util/math/MathUtil.java b/src/api/java/com/minelittlepony/util/math/MathUtil.java new file mode 100644 index 00000000..83824908 --- /dev/null +++ b/src/api/java/com/minelittlepony/util/math/MathUtil.java @@ -0,0 +1,32 @@ +package com.minelittlepony.util.math; + +import net.minecraft.util.math.MathHelper; + +public class MathUtil { + + public static double clampLimit(double num, double limit) { + return MathHelper.clamp(num, -limit, limit); + } + + public static float sensibleAngle(float angle) { + angle %= 360; + + if (angle > 180) angle -= 360; + if (angle < -180) angle += 360; + + return angle; + } + + public static float interpolateDegress(float prev, float current, float partialTicks) { + float difference = current - prev; + + while (difference < -180) difference += 360; + while (difference >= 180) difference -= 360; + + return prev + partialTicks * difference; + } + + public static float interpolateRadians(float prev, float current, float partialTicks) { + return (float)Math.toRadians(interpolateDegress(prev, current, partialTicks)); + } +} diff --git a/src/api/java/com/minelittlepony/util/render/ITextureSupplier.java b/src/api/java/com/minelittlepony/util/render/ITextureSupplier.java deleted file mode 100644 index ce4dc3f2..00000000 --- a/src/api/java/com/minelittlepony/util/render/ITextureSupplier.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.minelittlepony.util.render; - -import net.minecraft.util.ResourceLocation; - -/** - * A texture pool for generating multiple associated textures. - */ -@FunctionalInterface -public interface ITextureSupplier { - ResourceLocation supplyTexture(T key); -} diff --git a/src/api/java/com/minelittlepony/util/render/package-info.java b/src/api/java/com/minelittlepony/util/render/package-info.java deleted file mode 100644 index 4e9d3c08..00000000 --- a/src/api/java/com/minelittlepony/util/render/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -@MethodsReturnNonnullByDefault -@ParametersAreNonnullByDefault -package com.minelittlepony.util.render; - -import mcp.MethodsReturnNonnullByDefault; - -import javax.annotation.ParametersAreNonnullByDefault;