Guest User

EnumDragonBreed J

a guest
Jul 1st, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. import com.google.common.collect.BiMap;
  2. import com.google.common.collect.ImmutableBiMap;
  3. import java.util.Arrays;
  4. import java.util.function.Function;
  5. import java.util.function.Supplier;
  6. import java.util.stream.Collectors;
  7.  
  8. import net.minecraft.item.EnumDyeColor;
  9. import net.minecraft.util.IStringSerializable;
  10.  
  11. public enum EnumDragonBreed implements IStringSerializable {
  12.  
  13. AMETHYST(0, DragonBreedAmethyst::new),
  14. END(1, DragonBreedEnd::new),
  15. RUBY(2, DragonBreedRuby::new),
  16. JADE(3, DragonBreedJade::new),
  17. NETHER(4, DragonBreedNether::new),
  18. SAPPHIRE(5, DragonBreedSapphire::new),
  19. GARNET(6, DragonBreedGarnet::new);
  20.  
  21. // create static bimap between enums and meta data for faster and easier
  22. // lookups
  23. public static final BiMap<EnumDragonBreed, Integer> META_MAPPING =
  24. ImmutableBiMap.copyOf(Arrays.asList(values()).stream()
  25. .collect(Collectors.toMap(Function.identity(), EnumDragonBreed::getMeta)));
  26.  
  27. private final DragonBreed breed;
  28.  
  29. // this field is used for block metadata and is technically the same as
  30. // ordinal(), but it is saved separately to make sure the values stay
  31. // constant after adding more breeds in unexpected orders
  32. private final int meta;
  33.  
  34. private EnumDragonBreed(int meta, Supplier<DragonBreed> factory) {
  35. this.breed = factory.get();
  36. this.meta = meta;
  37. }
  38.  
  39. public DragonBreed getBreed() {
  40. return breed;
  41. }
  42.  
  43. public int getMeta() {
  44. return meta;
  45. }
  46.  
  47. @Override
  48. public String getName() {
  49. return name().toLowerCase();
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment