shane020482

Untitled

May 25th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. public class BlockOres extends Block implements IHasModel, IMetaName
  2. {
  3. replace
  4. public static final PropertyEnum<EnumHandler.EnumType> VARIANT = PropertyEnum.<EnumHandler.EnumType>create("variant", EnumHandler.EnumType.class);
  5.  
  6. with and change to fit you mod watch out i use TYPE so you may want to change that to VARIANT
  7. public static final PropertyEnum<BlockTestEnum.EnumType> TYPE = PropertyEnum.<BlockTestEnum.EnumType>create("type", BlockTestEnum.EnumType.class);
  8.  
  9. private String name, dimension;
  10.  
  11. public BlockOres(String name, String dimension)
  12. {
  13. super(Material.ROCK);
  14. setUnlocalizedName(name);
  15. setRegistryName(name);
  16. setCreativeTab(Main.HTTYDHeadTab);
  17. setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, EnumHandler.EnumType.GRONKLE_IRON));
  18.  
  19. this.name = name;
  20. this.dimension = dimension;
  21.  
  22. ModBlocks.BLOCKS.add(this);
  23. ModItems.ITEMS.add(new ItemBlockVariants(this).setRegistryName(this.getRegistryName()));
  24. }
  25.  
  26. @Override
  27. public int damageDropped(IBlockState state) {
  28. return ((EnumHandler.EnumType)state.getValue(VARIANT)).getMeta();
  29. }
  30.  
  31. @Override
  32. public int getMetaFromState(IBlockState state)
  33. {
  34. return ((EnumHandler.EnumType)state.getValue(VARIANT)).getMeta();
  35. }
  36.  
  37. @Override
  38. public IBlockState getStateFromMeta(int meta)
  39. {
  40. return this.getDefaultState().withProperty(VARIANT, EnumHandler.EnumType.byMetadata(meta));
  41. }
  42.  
  43. @Override
  44. public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos,EntityPlayer player)
  45. {
  46. return new ItemStack(Item.getItemFromBlock(this), 1, getMetaFromState(world.getBlockState(pos)));
  47. }
  48.  
  49. @Override
  50. public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
  51. {
  52. for(EnumHandler.EnumType variant : EnumHandler.EnumType.values())
  53. {
  54. items.add(new ItemStack(this, 1, variant.getMeta()));
  55. }
  56. }
  57.  
  58. @Override
  59. protected BlockStateContainer createBlockState()
  60. {
  61. return new BlockStateContainer(this, new IProperty[ ] {VARIANT});
  62. }
  63.  
  64. @Override
  65. public String getSpecialName(ItemStack stack) {
  66. return EnumHandler.EnumType.values()[stack.getItemDamage()].getName();
  67. }
  68.  
  69. @Override
  70. public void registerModels()
  71. {
  72. for(int i = 0; i < EnumHandler.EnumType.values().length; i++)
  73. {
  74. Main.proxy.registerVariantRenderer(Item.getItemFromBlock(this), i, "ore_" + this.dimension + "_" + EnumHandler.EnumType.values()[i].getName(), "inventory");
  75. }
  76. }
  77.  
  78.  
  79. using my code here but you can change to fit your need
  80. public static enum EnumType implements IStringSerializable
  81. {
  82. texture0(0, "texture0"),
  83. texture1(1, "texture1"),
  84. texture2(2, "texture2"),
  85. texture3(3, "texture3"),
  86. texture4(4, "texture4"),
  87. texture5(5, "texture5"),
  88. texture6(6, "texture6"),
  89. texture7(7, "texture7"),
  90. texture8(8, "texture8"),
  91. texture9(9, "texture9"),
  92. texture10(10, "texture10"),
  93. texture11(11, "texture11"),
  94. texture12(12, "texture12");
  95.  
  96. private static final BlockTestEnum.EnumType[] META_LOOKUP = new BlockTestEnum.EnumType[values().length];
  97. private final int metadata;
  98. private final String name;
  99. private String unlocalizedName;
  100.  
  101.  
  102. private EnumType(int meta, String name)
  103. {
  104. this.metadata = meta;
  105. this.name = name;
  106. this.unlocalizedName = name;
  107. }
  108.  
  109. public int getMetadata()
  110. {
  111. return this.metadata;
  112. }
  113.  
  114. public String toString()
  115. {
  116. return this.name;
  117. }
  118.  
  119. /**
  120. * Returns the matching EnumType for the given metadata.
  121. */
  122. public static BlockTestEnum.EnumType byMetadata(int meta)
  123. {
  124. if (meta < 0 || meta >= META_LOOKUP.length)
  125. {
  126. meta = 0;
  127. }
  128.  
  129. return META_LOOKUP[meta];
  130. }
  131.  
  132. public String getName()
  133. {
  134. return this.name;
  135. }
  136.  
  137. public String getUnlocalizedName()
  138. {
  139. return this.unlocalizedName;
  140. }
  141.  
  142. static
  143. {
  144. for (BlockTestEnum.EnumType blocksandstone$enumtype : values())
  145. {
  146. META_LOOKUP[blocksandstone$enumtype.getMetadata()] = blocksandstone$enumtype;
  147. }
  148. }
  149. }
  150.  
  151.  
  152. }
Advertisement
Add Comment
Please, Sign In to add comment