diff --git a/src/main/java/com/minelittlepony/api/model/IModel.java b/src/main/java/com/minelittlepony/api/model/IModel.java index 6a748c87..e5e7d7a6 100644 --- a/src/main/java/com/minelittlepony/api/model/IModel.java +++ b/src/main/java/com/minelittlepony/api/model/IModel.java @@ -53,7 +53,7 @@ public interface IModel { } default Race getRace() { - return PonyConfig.getEffectiveRace(getMetadata().getRace()); + return PonyConfig.getEffectiveRace(getMetadata().race()); } /** diff --git a/src/main/java/com/minelittlepony/api/model/IUnicorn.java b/src/main/java/com/minelittlepony/api/model/IUnicorn.java index 749ff695..c8e981f1 100644 --- a/src/main/java/com/minelittlepony/api/model/IUnicorn.java +++ b/src/main/java/com/minelittlepony/api/model/IUnicorn.java @@ -25,6 +25,6 @@ public interface IUnicorn extends IModel { * Gets the preferred magic color for this mode. */ default int getMagicColor() { - return getMetadata().getGlowColor(); + return getMetadata().glowColor(); } } diff --git a/src/main/java/com/minelittlepony/api/pony/IPony.java b/src/main/java/com/minelittlepony/api/pony/IPony.java index 7db5185d..3671415a 100644 --- a/src/main/java/com/minelittlepony/api/pony/IPony.java +++ b/src/main/java/com/minelittlepony/api/pony/IPony.java @@ -42,14 +42,14 @@ public interface IPony extends Comparable { * Gets the race associated with this pony. */ default Race race() { - return PonyConfig.getEffectiveRace(metadata().getRace()); + return PonyConfig.getEffectiveRace(metadata().race()); } /** * Returns true if and only if this metadata represents a pony that can cast magic. */ default boolean hasMagic() { - return race().hasHorn() && metadata().getGlowColor() != 0; + return race().hasHorn() && metadata().glowColor() != 0; } /** diff --git a/src/main/java/com/minelittlepony/api/pony/IPonyData.java b/src/main/java/com/minelittlepony/api/pony/IPonyData.java index ee00acf4..2f35d990 100644 --- a/src/main/java/com/minelittlepony/api/pony/IPonyData.java +++ b/src/main/java/com/minelittlepony/api/pony/IPonyData.java @@ -19,37 +19,37 @@ public interface IPonyData extends Comparable { * * This is the actual race value. For the effective race, prefer going through {@link IPony#race} */ - Race getRace(); + Race race(); /** * Gets the length of the pony's tail. */ - TailLength getTailLength(); + TailLength tailLength(); /** * Gets the shape of the pony's tail. */ - TailShape getTailShape(); + TailShape tailShape(); /** * Get the pony's gender (usually female). */ - Gender getGender(); + Gender gender(); /** * Gets the current pony size. */ - Size getSize(); + Size size(); /** * Gets the magical glow colour for magic-casting races. Returns 0 otherwise. */ - int getGlowColor(); + int glowColor(); /** * Returns an array of wearables that this pony is carrying. */ - Wearable[] getGear(); + Wearable[] gear(); /** * Checks it this pony is wearing the given accessory. @@ -59,22 +59,24 @@ public interface IPonyData extends Comparable { /** * Gets an interpolator for interpolating values. */ - Interpolator getInterpolator(UUID interpolatorId); + default Interpolator getInterpolator(UUID interpolatorId) { + return Interpolator.linear(interpolatorId); + } /** * Gets the trigger pixel values as they appeared in the underlying image. */ - Map> getTriggerPixels(); + Map> attributes(); @Override default int compareTo(@Nullable IPonyData o) { return o == this ? 0 : o == null ? 1 : ComparisonChain.start() - .compare(getRace(), o.getRace()) - .compare(getTailLength(), o.getTailLength()) - .compare(getGender(), o.getGender()) - .compare(getSize().ordinal(), o.getSize().ordinal()) - .compare(getGlowColor(), o.getGlowColor()) - .compare(0, Arrays.compare(getGear(), o.getGear())) + .compare(race(), o.race()) + .compare(tailLength(), o.tailLength()) + .compare(gender(), o.gender()) + .compare(size().ordinal(), o.size().ordinal()) + .compare(glowColor(), o.glowColor()) + .compare(0, Arrays.compare(gear(), o.gear())) .result(); } } diff --git a/src/main/java/com/minelittlepony/api/pony/TriggerPixelSet.java b/src/main/java/com/minelittlepony/api/pony/TriggerPixelSet.java deleted file mode 100644 index c5abc300..00000000 --- a/src/main/java/com/minelittlepony/api/pony/TriggerPixelSet.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.minelittlepony.api.pony; - -import java.util.List; - -@SuppressWarnings("unchecked") -public class TriggerPixelSet & TriggerPixelType> extends TriggerPixelValue { - - private final T def; - - public TriggerPixelSet(int color, T def, boolean[] value) { - super(color, value); - this.def = def; - } - - @Override - public List> getOptions() { - return def.getOptions(); - } - - @Override - public boolean matches(Object o) { - return o.getClass() == def.getClass() && getValue()[((Enum)o).ordinal()]; - } -} diff --git a/src/main/java/com/minelittlepony/api/pony/TriggerPixelType.java b/src/main/java/com/minelittlepony/api/pony/TriggerPixelType.java index e2851993..578ea03e 100644 --- a/src/main/java/com/minelittlepony/api/pony/TriggerPixelType.java +++ b/src/main/java/com/minelittlepony/api/pony/TriggerPixelType.java @@ -1,5 +1,6 @@ package com.minelittlepony.api.pony; +import java.util.Arrays; import java.util.List; /** @@ -9,13 +10,13 @@ public interface TriggerPixelType { /** * Gets the pixel colour matching this enum value. */ - int getColorCode(); + int colorCode(); /** * Gets the pixel colour matching this enum value, adjusted to fill all three channels. */ default int getChannelAdjustedColorCode() { - return getColorCode(); + return colorCode(); } /** @@ -26,7 +27,7 @@ public interface TriggerPixelType { } default String getHexValue() { - return toHex(getColorCode()); + return toHex(colorCode()); } /** @@ -55,7 +56,7 @@ public interface TriggerPixelType { @SuppressWarnings("unchecked") static > T getByTriggerPixel(T type, int pixelValue) { return (T)type.getOptions().stream() - .filter(i -> i.getColorCode() == pixelValue) + .filter(i -> i.colorCode() == pixelValue) .findFirst() .orElse(type); } @@ -71,4 +72,43 @@ public interface TriggerPixelType { } return "#" + v; } + + public record Flags & TriggerPixelType> ( + int colorCode, + T def, + boolean[] value + ) implements TriggerPixelType { + @Override + public String name() { + return "[Flags " + Arrays.toString(value) + "]"; + } + + @SuppressWarnings("unchecked") + @Override + public List> getOptions() { + return def.getOptions(); + } + + @Override + public boolean matches(Object o) { + return o.getClass() == def.getClass() && value()[((Enum)o).ordinal()]; + } + } + + public record Value ( + int colorCode, + T value + ) implements TriggerPixelType { + + @Override + public String name() { + return value instanceof TriggerPixelType t ? t.name() : TriggerPixelType.super.name(); + } + + @SuppressWarnings("unchecked") + @Override + public