EnumMetals.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package me.km.blocks;
  2. import me.km.items.ModItems;
  3. import net.minecraft.block.material.MapColor;
  4. import net.minecraft.init.Items;
  5. import net.minecraft.item.Item;
  6. import net.minecraft.util.IStringSerializable;
  7. public enum EnumMetals implements IStringSerializable
  8. {
  9. COPPER(0, "copper", MapColor.BROWN, ModItems.copperIngot),
  10. TIN(1, "tin", MapColor.SILVER, ModItems.tinIngot),
  11. BRONZE(2, "bronze", MapColor.YELLOW, ModItems.bronzeIngot),
  12. GOLD(3, "gold", MapColor.GOLD, Items.GOLD_INGOT),
  13. IRON(4, "iron", MapColor.IRON, Items.IRON_INGOT),
  14. SILVER(5, "silver", MapColor.SILVER, ModItems.silverIngot);
  15. private static final EnumMetals[] META_LOOKUP = new EnumMetals[values().length];
  16. private final int meta;
  17. private final String name;
  18. private final MapColor mapColor;
  19. private Item item;
  20. private EnumMetals(int meta, String name, MapColor mapColor, Item item)
  21. {
  22. this.meta = meta;
  23. this.name = name;
  24. this.mapColor = mapColor;
  25. this.item = item;
  26. }
  27. public Item getMetalIngot()
  28. {
  29. return item;
  30. }
  31. // items become null somehow
  32. public static void fixMetalIngots()
  33. {
  34. COPPER.item = ModItems.copperIngot;
  35. TIN.item = ModItems.tinIngot;
  36. BRONZE.item = ModItems.bronzeIngot;
  37. SILVER.item = ModItems.silverIngot;
  38. }
  39. public int getMetadata()
  40. {
  41. return this.meta;
  42. }
  43. public MapColor getMapColor()
  44. {
  45. return this.mapColor;
  46. }
  47. @Override
  48. public String toString()
  49. {
  50. return this.name;
  51. }
  52. public static EnumMetals byMetadata(int meta)
  53. {
  54. if (meta < 0 || meta >= META_LOOKUP.length)
  55. {
  56. meta = 0;
  57. }
  58. return META_LOOKUP[meta];
  59. }
  60. @Override
  61. public String getName()
  62. {
  63. return this.name;
  64. }
  65. public String getUnlocalizedName()
  66. {
  67. return this.name;
  68. }
  69. static
  70. {
  71. for(EnumMetals metal : values())
  72. {
  73. META_LOOKUP[metal.getMetadata()] = metal;
  74. }
  75. }
  76. }