Guest User

Untitled

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