Advertisement
Guest User

EnumDragonBreed

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