Unicopia/src/main/java/com/minelittlepony/unicopia/Affinity.java

71 lines
1.8 KiB
Java
Raw Normal View History

2020-09-23 17:19:28 +02:00
package com.minelittlepony.unicopia;
2024-04-08 21:45:46 +02:00
import java.util.Locale;
import net.minecraft.text.Text;
2020-01-16 12:35:46 +01:00
import net.minecraft.util.Formatting;
2024-04-08 21:45:46 +02:00
import net.minecraft.util.StringIdentifiable;
import net.minecraft.util.Util;
2024-04-08 21:45:46 +02:00
public enum Affinity implements StringIdentifiable {
GOOD(Formatting.BLUE, -1, 0),
NEUTRAL(Formatting.LIGHT_PURPLE, 0, 0.5F),
BAD(Formatting.RED, 1, 1);
2024-04-12 02:23:43 +02:00
@SuppressWarnings("deprecation")
2024-04-08 21:45:46 +02:00
public static final Codec<Affinity> CODEC = StringIdentifiable.createCodec(Affinity::values);
2020-01-16 12:35:46 +01:00
private final Formatting color;
private final int corruption;
private final float alignment;
2021-03-02 14:40:37 +01:00
public static final Affinity[] VALUES = values();
private final String translationKey;
Affinity(Formatting color, int corruption, float alignment) {
this.color = color;
this.corruption = corruption;
this.alignment = alignment;
this.translationKey = Util.createTranslationKey("affinity", Unicopia.id(name().toLowerCase(Locale.ROOT)));
}
2024-04-08 21:45:46 +02:00
@Override
public String asString() {
return name().toLowerCase(Locale.ROOT);
}
2021-03-02 14:40:37 +01:00
public Formatting getColor() {
return color;
}
public String getTranslationKey() {
return translationKey;
}
public Text getDisplayName() {
return Text.translatable(getTranslationKey()).formatted(getColor());
}
public int getCorruption() {
return corruption;
}
public float getAlignment() {
return alignment;
}
public boolean isNeutral() {
return this == NEUTRAL;
}
2020-09-23 17:19:28 +02:00
public boolean alignsWith(Affinity other) {
return isNeutral() || other.isNeutral() || this == other;
}
2021-03-02 14:40:37 +01:00
public static Affinity of(int ordinal, Affinity fallback) {
return ordinal < 0 || ordinal >= VALUES.length ? fallback : VALUES[ordinal];
2019-02-08 16:56:28 +01:00
}
}