diff --git a/src/main/java/com/minelittlepony/api/pony/IPonyData.java b/src/main/java/com/minelittlepony/api/pony/IPonyData.java index bf8ed9f8..2a19e5f2 100644 --- a/src/main/java/com/minelittlepony/api/pony/IPonyData.java +++ b/src/main/java/com/minelittlepony/api/pony/IPonyData.java @@ -7,6 +7,7 @@ import com.minelittlepony.api.pony.meta.TailLength; import com.minelittlepony.api.pony.meta.Wearable; import com.minelittlepony.common.util.animation.Interpolator; +import java.util.Map; import java.util.UUID; /** @@ -46,7 +47,9 @@ public interface IPonyData { /** * Returns true if and only if this metadata represents a pony that can cast magic. */ - boolean hasMagic(); + default boolean hasMagic() { + return hasHorn() && getGlowColor() != 0; + } /** * Returns an array of wearables that this pony is carrying. @@ -62,4 +65,9 @@ public interface IPonyData { * Gets an interpolator for interpolating values. */ Interpolator getInterpolator(UUID interpolatorId); + + /** + * Gets the trigger pixel values as they appeared in the underlying image. + */ + Map> getTriggerPixels(); } diff --git a/src/main/java/com/minelittlepony/api/pony/ITriggerPixelMapped.java b/src/main/java/com/minelittlepony/api/pony/ITriggerPixelMapped.java deleted file mode 100644 index 7075b440..00000000 --- a/src/main/java/com/minelittlepony/api/pony/ITriggerPixelMapped.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.minelittlepony.api.pony; - -/** - * Interface for enums that can be parsed from an image trigger pixel value. - */ -public interface ITriggerPixelMapped & ITriggerPixelMapped> { - /** - * Gets the pixel colour matching this enum value. - */ - int getTriggerPixel(); - - /** - * Gets the enum value corresponding to the given enum type and pixel value. - * If none are found, the first parameter is returned as the default. - * - * @param type Return type and default value. - * @param pixelValue The pixel colour to search for. - */ - @SuppressWarnings("unchecked") - static & ITriggerPixelMapped> T getByTriggerPixel(T type, int pixelValue) { - for (T i : (T[])type.getClass().getEnumConstants()) { - if (i.getTriggerPixel() == pixelValue) { - return i; - } - } - - return type; - } -} diff --git a/src/main/java/com/minelittlepony/api/pony/TriggerPixelSet.java b/src/main/java/com/minelittlepony/api/pony/TriggerPixelSet.java new file mode 100644 index 00000000..93866175 --- /dev/null +++ b/src/main/java/com/minelittlepony/api/pony/TriggerPixelSet.java @@ -0,0 +1,24 @@ +package com.minelittlepony.api.pony; + +import java.util.List; + +public class TriggerPixelSet & TriggerPixelType> extends TriggerPixelValue { + + private final T def; + + public TriggerPixelSet(int color, T def, boolean[] value) { + super(color, value); + this.def = def; + } + + @SuppressWarnings("unchecked") + @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 new file mode 100644 index 00000000..dafd1e04 --- /dev/null +++ b/src/main/java/com/minelittlepony/api/pony/TriggerPixelType.java @@ -0,0 +1,73 @@ +package com.minelittlepony.api.pony; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * Interface for enums that can be parsed from an image trigger pixel value. + */ +public interface TriggerPixelType { + /** + * Gets the pixel colour matching this enum value. + */ + int getColorCode(); + + /** + * Gets the pixel colour matching this enum value, adjusted to fill all three channels. + */ + default int getChannelAdjustedColorCode() { + return getColorCode(); + } + + /** + * Gets a string representation of this value. + */ + default String name() { + return "[Numeric " + getHexValue() + "]"; + } + + default String getHexValue() { + return toHex(getColorCode()); + } + + /** + * Returns a list of possible values this trigger pixel can accept. + */ + default