Advertisement
Redsword

Untitled

Mar 4th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. package redsword.mub.blocks;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.block.material.Material;
  5. import net.minecraft.block.properties.IProperty;
  6. import net.minecraft.block.properties.PropertyEnum;
  7. import net.minecraft.block.state.BlockStateContainer;
  8. import net.minecraft.block.state.IBlockState;
  9. import net.minecraft.creativetab.CreativeTabs;
  10. import net.minecraft.item.Item;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.util.IStringSerializable;
  13. import net.minecraft.util.NonNullList;
  14. import net.minecraft.util.ResourceLocation;
  15. import redsword.mub.Reference;
  16.  
  17. public class BlockMeta extends Block
  18. {
  19.  
  20. public static final PropertyEnum<BlockMeta.EnumType> VARIANT = PropertyEnum.<BlockMeta.EnumType>create("variant", BlockMeta.EnumType.class);
  21.  
  22. public BlockMeta(String unlocalizedName) {
  23. this.setUnlocalizedName(unlocalizedName);
  24. this.setRegistryName(new ResourceLocation(Reference.MODID, unlocalizedName));
  25. this.setHardness(3);
  26. this.setResistance(20);
  27. setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockMeta.EnumType.FIRST));
  28.  
  29. setResistance(5.0F);
  30. setHardness(3.0F);
  31.  
  32. }
  33.  
  34.  
  35. public int damageDropped(IBlockState state)
  36. {
  37. return state.getValue(VARIANT).getMetadata();
  38. }
  39.  
  40. public void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list)
  41. {
  42. for (BlockMeta.EnumType type : BlockMeta.EnumType.values()) {
  43. list.add(new ItemStack(itemIn, 1, type.getMetadata()));
  44. }
  45. }
  46.  
  47. public IBlockState getStateFromMeta(int meta)
  48. {
  49. return this.getDefaultState().withProperty(VARIANT, BlockMeta.EnumType.byMetadata(meta));
  50. }
  51.  
  52. public int getMetaFromState(IBlockState state)
  53. {
  54. return ((BlockMeta.EnumType)state.getValue(VARIANT)).getMetadata();
  55. }
  56.  
  57. protected BlockStateContainer createBlockState()
  58. {
  59. return new BlockStateContainer(this, new IProperty[] {VARIANT});
  60. }
  61.  
  62. public static enum EnumType implements IStringSerializable
  63. {
  64. FIRST(0, "tutorial", "tutorial_block"),
  65. SECOND(1, "tutorial2", "tutorial_block_m1");
  66.  
  67. private static final BlockMeta.EnumType[] META_LOOKUP = new BlockMeta.EnumType[values().length];
  68. private final int meta;
  69. private final String name;
  70. private final String unlocalizedName;
  71.  
  72. private EnumType(int metaIn, String nameIn, String unlocalizedIn)
  73. {
  74. this.meta = metaIn;
  75. this.name = nameIn;
  76. this.unlocalizedName = unlocalizedIn;
  77. }
  78.  
  79. public static String[] getUnlocalizedNames()
  80. {
  81. String[] names = new String[values().length];
  82.  
  83. for (int i = 0; i < META_LOOKUP.length; i++)
  84. names[i] = META_LOOKUP[i].unlocalizedName;
  85.  
  86. return names;
  87. }
  88.  
  89. public int getMetadata()
  90. {
  91. return this.meta;
  92. }
  93.  
  94. public static BlockMeta.EnumType byMetadata(int meta)
  95. {
  96. if (meta < 0 || meta >= META_LOOKUP.length)
  97. {
  98. meta = 0;
  99. }
  100.  
  101. return META_LOOKUP[meta];
  102. }
  103.  
  104. public String toString()
  105. {
  106. return this.name;
  107. }
  108.  
  109. public String getName()
  110. {
  111. return this.name;
  112. }
  113.  
  114. static
  115. {
  116. for (BlockMeta.EnumType type : values())
  117. {
  118. META_LOOKUP[type.getMetadata()] = type;
  119. }
  120. }
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement