Unicopia/src/main/java/com/minelittlepony/unicopia/Affinity.java
2020-09-23 17:19:28 +02:00

69 lines
1.5 KiB
Java

package com.minelittlepony.unicopia;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
public enum Affinity {
GOOD(Formatting.BLUE, -1),
NEUTRAL(Formatting.WHITE, 0),
BAD(Formatting.RED, 1);
private final Formatting color;
private final int corruption;
private Affinity[] implications;
Affinity(Formatting color, int corruption) {
this.color = color;
this.corruption = corruption;
}
public Formatting getColourCode() {
return color;
}
public String getTranslationKey() {
return this == BAD ? "curse" : "spell";
}
public Text getName() {
return new TranslatableText("affinity." + getTranslationKey()).styled(s -> s.withColor(getColourCode()));
}
public int getCorruption() {
return corruption;
}
public boolean isNeutral() {
return this == NEUTRAL;
}
public boolean alignsWith(Affinity other) {
return isNeutral() || other.isNeutral() || this == other;
}
public Affinity[] getImplicators() {
if (implications != null) {
return implications;
}
if (this == NEUTRAL) {
implications = values();
} else {
implications = new Affinity[] { this };
}
return implications;
}
public static Affinity of(String s) {
try {
if (s != null)
return valueOf(s.toUpperCase());
} catch (Throwable e) {}
return Affinity.NEUTRAL;
}
}