Advertisement
TheWebExpert

Untitled

Oct 25th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.54 KB | None | 0 0
  1. public class Custom_Slab extends BlockSlab
  2. {
  3. public static final PropertyEnum<Custom_Slab.Variant> VARIANT = PropertyEnum.<Custom_Slab.Variant>create("variant", Custom_Slab.Variant.class);
  4. public Custom_Slab mySlab;
  5.  
  6. public Custom_Slab(String name, Custom_Slab slabIn, float hardness, float resistance, int harvestLevel)
  7. {
  8. super(Material.ROCK);
  9. setUnlocalizedName(name);
  10. setRegistryName(name);
  11. setSoundType(SoundType.STONE);
  12. setHardness(hardness);
  13. setResistance(resistance);
  14. setHarvestLevel("pickaxe", harvestLevel);
  15. setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
  16. IBlockState iblockstate = this.blockState.getBaseState();
  17. mySlab = slabIn;
  18. if (!this.isDouble())
  19. {
  20. iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM);
  21. }
  22. this.setDefaultState(iblockstate.withProperty(VARIANT, Custom_Slab.Variant.DEFAULT));
  23. this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
  24. }
  25. public Item getItemDropped(IBlockState state, Random rand, int fortune)
  26. {
  27. return Item.getItemFromBlock(mySlab);
  28. }
  29. public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
  30. {
  31. return new ItemStack(mySlab);
  32. }
  33. public IBlockState getStateFromMeta(int meta)
  34. {
  35. IBlockState iblockstate = this.getDefaultState().withProperty(VARIANT, Custom_Slab.Variant.DEFAULT);
  36. if (!this.isDouble())
  37. {
  38. iblockstate = iblockstate.withProperty(HALF, (meta & 8) == 0 ? BlockSlab.EnumBlockHalf.BOTTOM : BlockSlab.EnumBlockHalf.TOP);
  39. }
  40. return iblockstate;
  41. }
  42. public int getMetaFromState(IBlockState state)
  43. {
  44. int i = 0;
  45. if (!this.isDouble() && state.getValue(HALF) == BlockSlab.EnumBlockHalf.TOP)
  46. {
  47. i |= 8;
  48. }
  49. return i;
  50. }
  51. protected BlockStateContainer createBlockState()
  52. {
  53. return this.isDouble() ? new BlockStateContainer(this, new IProperty[] {VARIANT}) : new BlockStateContainer(this, new IProperty[] {HALF, VARIANT});
  54. }
  55. public String getUnlocalizedName(int meta)
  56. {
  57. return super.getUnlocalizedName();
  58. }
  59. public IProperty<?> getVariantProperty()
  60. {
  61. return VARIANT;
  62. }
  63. public Comparable<?> getTypeForItem(ItemStack stack)
  64. {
  65. return Custom_Slab.Variant.DEFAULT;
  66. }
  67. public static class Double extends Custom_Slab
  68. {
  69. public Double(String name, Custom_Slab slabIn, float hardness, float resistance, int harvestLevel)
  70. {
  71. super(name, slabIn, hardness, resistance, harvestLevel);
  72. }
  73. public boolean isDouble()
  74. {
  75. return true;
  76. }
  77. }
  78. public static class Half extends Custom_Slab
  79. {
  80. public Half(String name, Custom_Slab slabIn, float hardness, float resistance, int harvestLevel)
  81. {
  82. super(name, slabIn, hardness, resistance, harvestLevel);
  83. }
  84. public boolean isDouble()
  85. {
  86. return false;
  87. }
  88. }
  89. public static enum Variant implements IStringSerializable
  90. {
  91. DEFAULT;
  92. public String getName()
  93. {
  94. return "default";
  95. }
  96. }
  97. @Override
  98. public boolean isDouble()
  99. {
  100. IBlockState iblockstate = this.blockState.getBaseState();
  101. if (this.isDouble())
  102. {
  103. return true;
  104. }
  105. else
  106. {
  107. return false;
  108. }
  109. }
  110. }
  111. ....
  112. public class Init_Blocks
  113. {
  114. public static Custom_Slab endbrick_slab;
  115. public static Custom_Slab endbrick_double_slab;
  116.  
  117. @SubscribeEvent
  118. public static void registerBlocks(RegistryEvent.Register<Block> event)
  119. {
  120. //Harvest Levels:
  121. //0 - Wood 1 - Stone 2 - Iron 3 - Diamond 4 - Harder than Diamond
  122.  
  123. //Hardness Levels:
  124. //1 - Sign 2 - Wood 3 - Iron Ore 4 - Cobweb 5 - Block of Iron
  125.  
  126. //Resistance Levels:
  127. //5 - Sign 15 - Coal Ore 30 - Block of Iron 6000 - Obsidian
  128.  
  129. // Hardness Resistance HarvestLevel
  130. endbrick_slab = new Custom_Slab.Half("endbrick_slab", endbrick_slab, 0.8F, 10.0F, 2);
  131. endbrick_double_slab = new Custom_Slab.Double("endbrick_double_slab", endbrick_double_slab, 0.8F, 10.0F, 2);
  132. event.getRegistry().registerAll(endbrick_slab, endbrick_double_slab);
  133. }
  134. @SubscribeEvent
  135. @SideOnly(Side.CLIENT)
  136. public static void registerModels(ModelRegistryEvent event)
  137. {
  138. registerBlocks(endbrick_slab); registerBlocks(endbrick_double_slab);
  139. }
  140. public static void registerBlocks(Block block)
  141. {
  142. ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), "inventory"));
  143. }
  144. }
  145. ....
  146. @Mod.EventBusSubscriber
  147. public class Common_Event_Registry
  148. {
  149. @SubscribeEvent
  150. public static void registerBlocks(RegistryEvent.Register<Block> event)
  151. {
  152. Init_Blocks.registerBlocks(event);
  153. }
  154. }
  155. ....
  156. Blockstates:
  157. endbrick_slab:
  158. {
  159. "variants": {
  160. "half=bottom,variant=default": { "model": "megamod:half_slab_endbrick" },
  161. "half=top,variant=default": { "model": "megamod:upper_slab_endbrick" }
  162. }
  163. }
  164. ....
  165. endbrick_double_slab:
  166. {
  167. "variants": {
  168. "variant=default": { "model": "end_bricks" }
  169. }
  170. }
  171. ....
  172. en_us.lang:
  173. tile.endbrick_slab.name=Endbrick Slab
  174. ....
  175. models\block:
  176. half_slab_endbrick:
  177. {
  178. "parent": "block/half_slab",
  179. "textures": {
  180. "bottom": "blocks/end_bricks",
  181. "top": "blocks/end_bricks",
  182. "side": "blocks/end_bricks"
  183. }
  184. }
  185. ....
  186. upper_slab_endbrick:
  187. {
  188. "parent": "block/upper_slab",
  189. "textures": {
  190. "bottom": "blocks/end_bricks",
  191. "top": "blocks/end_bricks",
  192. "side": "blocks/end_bricks"
  193. }
  194. }
  195. ....
  196. models\item:
  197. endbrick_slab:
  198. {
  199. "parent": "megamod:block/half_slab_endbrick",
  200. "display": {
  201. "thirdperson": {
  202. "rotation": [ 10, -45, 170 ],
  203. "translation": [ 0, 1.5, -2.75 ],
  204. "scale": [ 0.375, 0.375, 0.375 ]
  205. }
  206. }
  207. }
  208. ....
  209. endbrick_double_slab:
  210. {
  211. "parent": "block/end_bricks"
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement