mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 08:14:23 +01:00
Moved some utilities to Kirin
This commit is contained in:
parent
9f76e6c53a
commit
d3c6119c3c
15 changed files with 16 additions and 209 deletions
|
@ -5,7 +5,7 @@ import com.minelittlepony.api.pony.meta.Race;
|
||||||
import com.minelittlepony.api.pony.meta.Size;
|
import com.minelittlepony.api.pony.meta.Size;
|
||||||
import com.minelittlepony.api.pony.meta.TailLength;
|
import com.minelittlepony.api.pony.meta.TailLength;
|
||||||
import com.minelittlepony.api.pony.meta.Wearable;
|
import com.minelittlepony.api.pony.meta.Wearable;
|
||||||
import com.minelittlepony.util.IInterpolator;
|
import com.minelittlepony.common.util.animation.Interpolator;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -56,5 +56,5 @@ public interface IPonyData {
|
||||||
/**
|
/**
|
||||||
* Gets an interpolator for interpolating values.
|
* Gets an interpolator for interpolating values.
|
||||||
*/
|
*/
|
||||||
IInterpolator getInterpolator(UUID interpolatorId);
|
Interpolator getInterpolator(UUID interpolatorId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package com.minelittlepony.api.pony.meta;
|
||||||
import net.minecraft.client.texture.NativeImage;
|
import net.minecraft.client.texture.NativeImage;
|
||||||
|
|
||||||
import com.minelittlepony.api.pony.ITriggerPixelMapped;
|
import com.minelittlepony.api.pony.ITriggerPixelMapped;
|
||||||
import com.minelittlepony.util.Color;
|
import com.minelittlepony.common.util.Color;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Individual trigger pixels for a pony skin.
|
* Individual trigger pixels for a pony skin.
|
||||||
|
|
|
@ -8,10 +8,10 @@ import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
import com.minelittlepony.api.pony.meta.Wearable;
|
import com.minelittlepony.api.pony.meta.Wearable;
|
||||||
|
import com.minelittlepony.common.util.Color;
|
||||||
import com.minelittlepony.model.BodyPart;
|
import com.minelittlepony.model.BodyPart;
|
||||||
import com.minelittlepony.model.IModel;
|
import com.minelittlepony.model.IModel;
|
||||||
import com.minelittlepony.mson.api.ModelContext;
|
import com.minelittlepony.mson.api.ModelContext;
|
||||||
import com.minelittlepony.util.Color;
|
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
|
@ -8,10 +8,10 @@ import net.minecraft.client.render.VertexConsumerProvider.Immediate;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
|
||||||
import com.minelittlepony.client.render.MagicGlow;
|
import com.minelittlepony.client.render.MagicGlow;
|
||||||
|
import com.minelittlepony.common.util.Color;
|
||||||
import com.minelittlepony.model.IPart;
|
import com.minelittlepony.model.IPart;
|
||||||
import com.minelittlepony.mson.api.ModelContext;
|
import com.minelittlepony.mson.api.ModelContext;
|
||||||
import com.minelittlepony.mson.api.MsonModel;
|
import com.minelittlepony.mson.api.MsonModel;
|
||||||
import com.minelittlepony.util.Color;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,7 @@ import com.minelittlepony.api.pony.meta.TriggerPixels;
|
||||||
import com.minelittlepony.api.pony.meta.Wearable;
|
import com.minelittlepony.api.pony.meta.Wearable;
|
||||||
import com.minelittlepony.client.MineLittlePony;
|
import com.minelittlepony.client.MineLittlePony;
|
||||||
import com.minelittlepony.client.util.render.NativeUtil;
|
import com.minelittlepony.client.util.render.NativeUtil;
|
||||||
import com.minelittlepony.util.BasicEasingInterpolator;
|
import com.minelittlepony.common.util.animation.Interpolator;
|
||||||
import com.minelittlepony.util.IInterpolator;
|
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -145,8 +144,8 @@ public class PonyData implements IPonyData {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IInterpolator getInterpolator(UUID interpolatorId) {
|
public Interpolator getInterpolator(UUID interpolatorId) {
|
||||||
return BasicEasingInterpolator.getInstance(interpolatorId);
|
return Interpolator.linear(interpolatorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package com.minelittlepony.client.render;
|
package com.minelittlepony.client.render;
|
||||||
|
|
||||||
import net.minecraft.client.render.Frustum;
|
import net.minecraft.client.render.Frustum;
|
||||||
import net.minecraft.client.util.math.Matrix4f;
|
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.util.math.Box;
|
import net.minecraft.util.math.Box;
|
||||||
|
import net.minecraft.util.math.Matrix4f;
|
||||||
|
|
||||||
import com.minelittlepony.api.pony.IPony;
|
import com.minelittlepony.api.pony.IPony;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.minelittlepony.client.render;
|
||||||
|
|
||||||
import com.minelittlepony.api.pony.IPony;
|
import com.minelittlepony.api.pony.IPony;
|
||||||
import com.minelittlepony.client.MineLittlePony;
|
import com.minelittlepony.client.MineLittlePony;
|
||||||
import com.minelittlepony.util.Color;
|
import com.minelittlepony.common.util.Color;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,10 @@ import com.minelittlepony.client.model.IPonyModel;
|
||||||
import com.minelittlepony.client.model.ModelWrapper;
|
import com.minelittlepony.client.model.ModelWrapper;
|
||||||
import com.minelittlepony.client.model.armour.DefaultArmourTextureResolver;
|
import com.minelittlepony.client.model.armour.DefaultArmourTextureResolver;
|
||||||
import com.minelittlepony.client.render.IPonyRenderContext;
|
import com.minelittlepony.client.render.IPonyRenderContext;
|
||||||
|
import com.minelittlepony.common.util.Color;
|
||||||
import com.minelittlepony.model.armour.ArmourLayer;
|
import com.minelittlepony.model.armour.ArmourLayer;
|
||||||
import com.minelittlepony.model.armour.IArmour;
|
import com.minelittlepony.model.armour.IArmour;
|
||||||
import com.minelittlepony.model.armour.IArmourTextureResolver;
|
import com.minelittlepony.model.armour.IArmourTextureResolver;
|
||||||
import com.minelittlepony.util.Color;
|
|
||||||
|
|
||||||
import net.minecraft.client.render.OverlayTexture;
|
import net.minecraft.client.render.OverlayTexture;
|
||||||
import net.minecraft.client.render.RenderLayer;
|
import net.minecraft.client.render.RenderLayer;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.minelittlepony.client.transform;
|
package com.minelittlepony.client.transform;
|
||||||
|
|
||||||
|
import com.minelittlepony.common.util.animation.MotionCompositor;
|
||||||
import com.minelittlepony.model.IModel;
|
import com.minelittlepony.model.IModel;
|
||||||
import com.minelittlepony.util.MotionCompositor;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.minelittlepony.client.transform;
|
package com.minelittlepony.client.transform;
|
||||||
|
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
|
||||||
import com.minelittlepony.model.IModel;
|
import com.minelittlepony.model.IModel;
|
||||||
|
@ -8,15 +9,15 @@ import com.minelittlepony.model.IModel;
|
||||||
public class PostureSwimming extends PostureFlight {
|
public class PostureSwimming extends PostureFlight {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calculateRoll(PlayerEntity player, double motionX, double motionY, double motionZ) {
|
public double calculateRoll(LivingEntity entity, double motionX, double motionY, double motionZ) {
|
||||||
motionX *= 2;
|
motionX *= 2;
|
||||||
motionZ *= 2;
|
motionZ *= 2;
|
||||||
|
|
||||||
return super.calculateRoll(player, motionX, motionY, motionZ);
|
return super.calculateRoll(entity, motionX, motionY, motionZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calculateIncline(PlayerEntity player, double motionX, double motionY, double motionZ) {
|
public double calculateIncline(LivingEntity entity, double motionX, double motionY, double motionZ) {
|
||||||
return 90; // mojang handles this
|
return 90; // mojang handles this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
package com.minelittlepony.util;
|
|
||||||
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
|
||||||
import com.google.common.cache.CacheLoader;
|
|
||||||
import com.google.common.cache.LoadingCache;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class BasicEasingInterpolator implements IInterpolator {
|
|
||||||
|
|
||||||
private static LoadingCache<UUID, BasicEasingInterpolator> instanceCache = CacheBuilder.newBuilder()
|
|
||||||
.expireAfterAccess(30, TimeUnit.SECONDS)
|
|
||||||
.build(CacheLoader.from(BasicEasingInterpolator::new));
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets or creates a new basic, linear interpolator for the provided id.
|
|
||||||
*/
|
|
||||||
public static IInterpolator getInstance(UUID id) {
|
|
||||||
return instanceCache.getUnchecked(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Map<String, Float> 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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
package com.minelittlepony.util;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Colouration Utilities
|
|
||||||
*/
|
|
||||||
public interface Color {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the ALPHA channel for the given colour hex code.
|
|
||||||
*/
|
|
||||||
static float a(int hex) {
|
|
||||||
return (hex >> 24 & 255) / 255F;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the RED channel for the given colour hex code.
|
|
||||||
*/
|
|
||||||
static float r(int hex) {
|
|
||||||
return (hex >> 16 & 255) / 255F;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the GREEN channel for the given colour hex code.
|
|
||||||
*/
|
|
||||||
static float g(int hex) {
|
|
||||||
return (hex >> 8 & 255) / 255F;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the BLUE channel for the given colour hex code.
|
|
||||||
*/
|
|
||||||
static float b(int hex) {
|
|
||||||
return (hex & 255) / 255F;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts the given rgb floats on a range of 0-1 into a colour hex code.
|
|
||||||
*/
|
|
||||||
static int argbToHex(float a, float r, float g, float b) {
|
|
||||||
return argbToHex((int)(a * 255), (int) (r * 255), (int) (g * 255), (int) (b * 255));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts the given rbg int on a range of 0-255 into a colour hex code.
|
|
||||||
*/
|
|
||||||
static int argbToHex(int a, int r, int g, int b) {
|
|
||||||
return (a << 24) | (r << 16) | (g << 8) | (b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a colour hex code from BGR to RGB (and back).
|
|
||||||
*/
|
|
||||||
static int abgrToArgb(int color) {
|
|
||||||
return argbToHex(a(color), b(color), g(color), r(color));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package com.minelittlepony.util;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
}
|
|
|
@ -16,15 +16,6 @@ public class MathUtil {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
public static float interpolateDegress(float prev, float current, float partialTicks) {
|
||||||
float difference = current - prev;
|
float difference = current - prev;
|
||||||
|
|
||||||
|
@ -34,10 +25,6 @@ public class MathUtil {
|
||||||
return prev + partialTicks * difference;
|
return prev + partialTicks * difference;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float interpolateRadians(float prev, float current, float partialTicks) {
|
|
||||||
return (float)Math.toRadians(interpolateDegress(prev, current, partialTicks));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean compareFloats(float a, float b) {
|
public static boolean compareFloats(float a, float b) {
|
||||||
return Math.abs(a - b) <= 0.001F;
|
return Math.abs(a - b) <= 0.001F;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
package com.minelittlepony.util;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates roll and incline for a player based on their motion vectors.
|
|
||||||
*
|
|
||||||
* @author Polyakovich - Big thank you to this dude and his meta-physics friend for working this all out.
|
|
||||||
*/
|
|
||||||
public abstract class MotionCompositor {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the angle of horizontal roll in degrees based on the player's vertical and horizontal motion.
|
|
||||||
*/
|
|
||||||
protected double calculateRoll(PlayerEntity 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.prevBodyYaw - player.bodyYaw);
|
|
||||||
double horMotion = Math.sqrt(motionX * motionX + motionZ * motionZ);
|
|
||||||
float modelYaw = MathUtil.sensibleAngle(player.bodyYaw);
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the angle of inclination in degrees based on the player's vertical and horizontal motion.
|
|
||||||
*/
|
|
||||||
protected double calculateIncline(PlayerEntity player, double motionX, double motionY, double motionZ) {
|
|
||||||
double dist = Math.sqrt(motionX * motionX + motionZ * motionZ);
|
|
||||||
double angle = Math.atan2(motionY, dist);
|
|
||||||
|
|
||||||
if (!player.abilities.allowFlying) {
|
|
||||||
angle /= 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
angle = MathUtil.clampLimit(angle, Math.PI / 3);
|
|
||||||
|
|
||||||
return Math.toDegrees(angle);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in a new issue