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

115 lines
2.8 KiB
Java
Raw Normal View History

2018-09-12 01:29:49 +02:00
package com.minelittlepony.unicopia;
import java.util.HashMap;
import java.util.Map;
2018-09-12 01:29:49 +02:00
import com.google.common.base.Strings;
import com.minelittlepony.pony.data.PonyRace;
2018-09-12 01:29:49 +02:00
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2018-09-12 01:29:49 +02:00
public enum Race {
HUMAN(false, false, false),
EARTH(false, false, true),
UNICORN(true, false, false),
PEGASUS(false, true, false),
ALICORN(true, true, true),
CHANGELING(false, true, false);
private final boolean magic;
private final boolean flight;
private final boolean earth;
private final static Map<Integer, Race> raceIdMap = new HashMap<>();
static {
for (Race race : values()) {
raceIdMap.put(race.ordinal(), race);
}
}
2018-09-12 01:29:49 +02:00
Race(boolean magic, boolean flight, boolean earth) {
this.magic = magic;
this.flight = flight;
this.earth = earth;
}
public boolean isDefault() {
return this == HUMAN;
}
public boolean canFly() {
return flight;
}
public boolean canCast() {
return magic;
}
public boolean canUseEarth() {
return earth;
}
public boolean canInteractWithClouds() {
return canFly() && this != CHANGELING;
}
2018-09-12 01:29:49 +02:00
public String getDisplayString() {
return I18n.format(getTranslationString());
}
public String getTranslationString() {
return String.format("unicopia.race.%s", name().toLowerCase());
2018-09-12 01:29:49 +02:00
}
public boolean isSameAs(String s) {
return name().equalsIgnoreCase(s)
|| getTranslationString().equalsIgnoreCase(s)
|| getDisplayString().equalsIgnoreCase(s);
}
public static Race fromName(String s, Race def) {
2018-09-12 01:29:49 +02:00
if (!Strings.isNullOrEmpty(s)) {
for (Race i : values()) {
if (i.isSameAs(s)) return i;
}
}
try {
return fromId(Integer.parseInt(s));
2018-09-12 01:29:49 +02:00
} catch (NumberFormatException e) { }
return def;
2018-09-12 01:29:49 +02:00
}
@SideOnly(Side.CLIENT)
public static Race fromPonyRace(PonyRace ponyRace) {
switch (ponyRace) {
case ALICORN:
return ALICORN;
case CHANGELING:
case REFORMED_CHANGELING:
return CHANGELING;
case ZEBRA:
case EARTH:
return EARTH;
case GRIFFIN:
case HIPPOGRIFF:
case PEGASUS:
case BATPONY:
return PEGASUS;
case SEAPONY:
case UNICORN:
return UNICORN;
default:
return HUMAN;
}
}
public static Race fromId(int id) {
return raceIdMap.getOrDefault(id, HUMAN);
}
2018-09-12 01:29:49 +02:00
}