Created
July 7, 2015 00:06
-
-
Save ElvishJerricco/8cdb03ce816f15a39547 to your computer and use it in GitHub Desktop.
Part Factories with Enums
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PartFactoryOfEnum<E extends Enum<E> & IEnumPartFactory> implements MultiPartRegistry.IPartFactory2 { | |
private final Class<E> enumClass; | |
private final String[] types; | |
private final Map<String, E> typesToParts = new HashMap<String, E>(); | |
public PartFactoryOfEnum(Class<E> enumClass) { | |
this.enumClass = enumClass; | |
E[] enumConstants = enumClass.getEnumConstants(); | |
this.types = new String[enumConstants.length]; | |
for (E part : enumConstants) { | |
String name = part.getPartType(); | |
this.types[part.ordinal()] = name; | |
this.typesToParts.put(name, part); | |
} | |
} | |
@Override | |
public TMultiPart createPart(String type, NBTTagCompound nbt) { | |
return typesToParts.get(type).createPart(nbt); | |
} | |
@Override | |
public TMultiPart createPart(String type, MCDataInput packet) { | |
return typesToParts.get(type).createPart(packet); | |
} | |
public String[] getPartTypes() { | |
return types; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment