Guest User

Untitled

a guest
Feb 22nd, 2017
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. public class RubberLeaves extends BlockLeaves {
  2.  
  3. public RubberLeaves() {
  4. this.setTickRandomly(true);
  5. this.setCreativeTab(TechExpansion.TechExpansion);
  6. this.setHardness(0.2F);
  7. this.setLightOpacity(1);
  8. this.setSoundType(SoundType.PLANT);
  9. this.setUnlocalizedName("rubber_leaves");
  10. this.setDefaultState(this.blockState.getBaseState().withProperty(CHECK_DECAY, Boolean.valueOf(true)).withProperty(DECAYABLE, Boolean.valueOf(true)));
  11. GameRegistry.register(this.setRegistryName("rubber_leaves"));
  12. GameRegistry.register(new ItemBlock(this).setRegistryName(this.getRegistryName()));
  13. }
  14.  
  15. @Override
  16. public Item getItemDropped(IBlockState state, Random rand, int fortune)
  17. {
  18. return Item.getItemFromBlock(ModBlocks.RubberSapling);
  19. }
  20.  
  21. protected void dropRubber(World worldIn, BlockPos pos, IBlockState state, int chance)
  22. {
  23. spawnAsEntity(worldIn, pos, new ItemStack(ModItems.RawRubber, 1));
  24. }
  25.  
  26. @Override
  27. protected int getSaplingDropChance(IBlockState state)
  28. {
  29. return 20;
  30. }
  31.  
  32. @Override
  33. public boolean isOpaqueCube(IBlockState state)
  34. {
  35. return false;
  36. }
  37.  
  38. @Override
  39. @SideOnly(Side.CLIENT)
  40. public BlockRenderLayer getBlockLayer()
  41. {
  42. return BlockRenderLayer.CUTOUT_MIPPED;
  43. }
  44.  
  45. @Override
  46. public BlockPlanks.EnumType getWoodType(int meta) {
  47. return null;
  48. }
  49.  
  50. @Override public boolean isShearable(ItemStack item, IBlockAccess world, BlockPos pos){
  51. return true;
  52. }
  53.  
  54. @Override
  55. public List<ItemStack> onSheared(@Nonnull ItemStack item, IBlockAccess world, BlockPos pos, int fortune) {
  56. List<ItemStack> ret = new java.util.ArrayList<ItemStack>();
  57. ret.add(new ItemStack(ModBlocks.RubberLeaves, 1));
  58. return ret;
  59. }
  60.  
  61. @Override
  62. public boolean isLeaves(IBlockState state, IBlockAccess world, BlockPos pos) {
  63. return true;
  64. }
  65.  
  66. @Override
  67. public java.util.List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
  68. {
  69. java.util.List<ItemStack> ret = new java.util.ArrayList<ItemStack>();
  70. Random rand = world instanceof World ? ((World)world).rand : new Random();
  71. int chance = this.getSaplingDropChance(state);
  72.  
  73. if (fortune > 0)
  74. {
  75. chance -= 2 << fortune;
  76. if (chance < 10) chance = 10;
  77. }
  78.  
  79. if (rand.nextInt(chance) == 0)
  80. {
  81. ItemStack drop = new ItemStack(getItemDropped(state, rand, fortune), 1, damageDropped(state));
  82. if (!drop.isEmpty())
  83. ret.add(drop);
  84. }
  85.  
  86. chance = 200;
  87. if (fortune > 0)
  88. {
  89. chance -= 10 << fortune;
  90. if (chance < 40) chance = 40;
  91. }
  92.  
  93. this.captureDrops(true);
  94. if (world instanceof World)
  95. this.dropRubber((World)world, pos, state, chance);
  96. ret.addAll(this.captureDrops(false));
  97. return ret;
  98. }
  99.  
  100. @Override
  101. protected BlockStateContainer createBlockState() {
  102. return new BlockStateContainer(this, new IProperty[]{DECAYABLE, CHECK_DECAY});
  103. }
  104.  
  105. @Override
  106. public int getMetaFromState(IBlockState state) {
  107. int i = 0;
  108.  
  109. if (!state.getValue(DECAYABLE).booleanValue()) {
  110. i |= 4;
  111. }
  112.  
  113. if (state.getValue(CHECK_DECAY).booleanValue()) {
  114. i |= 8;
  115. }
  116.  
  117. return i;
  118. }
  119.  
  120. @Override
  121. public IBlockState getStateFromMeta(int meta) {
  122. return this.getDefaultState().withProperty(DECAYABLE, Boolean.valueOf((meta & 4) == 0)).withProperty(CHECK_DECAY, Boolean.valueOf((meta & 8) > 0));
  123. }
  124. }
Add Comment
Please, Sign In to add comment