diff options
Diffstat (limited to 'src/main/java/com/anthonyhilyard/iceberg/util')
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/util/Easing.java | 107 | ||||
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/util/ItemColor.java | 38 |
2 files changed, 145 insertions, 0 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/Easing.java b/src/main/java/com/anthonyhilyard/iceberg/util/Easing.java new file mode 100644 index 0000000..da41927 --- /dev/null +++ b/src/main/java/com/anthonyhilyard/iceberg/util/Easing.java @@ -0,0 +1,107 @@ +package com.anthonyhilyard.iceberg.util; + +/** + * Helper functions for smooth easing/interpolation. If you need linear, use net.minecraft.util.math.MathHelper.lerp instead. + */ +public final class Easing +{ + public static enum EasingType + { + None, // Produces step-wise interpolation. + Quad, + Cubic + } + + public static enum EasingDirection + { + In, + Out, + InOut + } + + public static float Ease(float a, float b, float t) + { + return Ease(a, b, t, EasingType.Quad); + } + + public static float Ease(float a, float b, float t, EasingType type) + { + return Ease(a, b, t, type, EasingDirection.InOut); + } + + public static float Ease(float a, float b, float t, EasingType type, EasingDirection direction) + { + switch (type) + { + case None: + default: + return None(a, b, t); + case Quad: + return Quad(a, b, t, direction); + case Cubic: + return Cubic(a, b, t, direction); + } + } + + private static float None(float a, float b, float t) + { + if (t < 0.5f) + { + return a; + } + else + { + return b; + } + } + + private static float Quad(float a, float b, float t, EasingDirection direction) + { + switch (direction) + { + case In: + return a + (b - a) * t * t; + case Out: + return a + (b - a) * (1.0f - (1.0f - t) * (1.0f - t)); + case InOut: + default: + { + t *= 2.0f; + if (t < 1.0f) + { + return a + (b - a) * 0.5f * t * t; + } + else + { + t -= 2.0f; + return a + (a - b) * 0.5f * (t * t - 2.0f); + } + } + } + } + + private static float Cubic(float a, float b, float t, EasingDirection direction) + { + switch (direction) + { + case In: + return a + (b - a) * t * t * t; + case Out: + return a + (b - a) * (1.0f - (1.0f - t) * (1.0f - t) * (1.0f - t)); + case InOut: + default: + { + t *= 2.0f; + if (t < 1.0f) + { + return a + (b - a) * 0.5f * t * t * t; + } + else + { + t -= 2.0f; + return a + (b - a) * 0.5f * (t * t * t + 2.0f); + } + } + } + } +}
\ No newline at end of file diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/ItemColor.java b/src/main/java/com/anthonyhilyard/iceberg/util/ItemColor.java new file mode 100644 index 0000000..a4625aa --- /dev/null +++ b/src/main/java/com/anthonyhilyard/iceberg/util/ItemColor.java @@ -0,0 +1,38 @@ +package com.anthonyhilyard.iceberg.util; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.text.Color; + +public class ItemColor +{ + public static Color getColorForItem(ItemStack item, Color defaultColor) + { + Color result = null; + + // Color based on rarity value. + result = item.getDisplayName().getStyle().getColor(); + + // Some mods override the getName() method of the Item class, so grab that color if it's there. + if (item.getItem() != null && + item.getItem().getName(item) != null && + item.getItem().getName(item).getStyle() != null && + item.getItem().getName(item).getStyle().getColor() != null) + { + result = item.getItem().getName(item).getStyle().getColor(); + } + + // Finally, if the item has a special hover name color (Stored in NBT), use that. + if (!item.getHoverName().getStyle().isEmpty() && item.getHoverName().getStyle().getColor() != null) + { + result = item.getHoverName().getStyle().getColor(); + } + + // Fallback to the default color if we somehow haven't found a single valid color. + if (result == null) + { + result = defaultColor; + } + + return result; + } +} |