| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import com.google.common.base.Predicate;
|
| 4 | import java.util.List;
|
| 5 | import net.minecraft.block.properties.IProperty;
|
| 6 | import net.minecraft.block.properties.PropertyEnum;
|
| 7 | import net.minecraft.block.state.BlockState;
|
| 8 | import net.minecraft.block.state.IBlockState;
|
| 9 | import net.minecraft.creativetab.CreativeTabs;
|
| 10 | import net.minecraft.entity.player.EntityPlayer;
|
| 11 | import net.minecraft.init.Items;
|
| 12 | import net.minecraft.item.Item;
|
| 13 | import net.minecraft.item.ItemStack;
|
| 14 | import net.minecraft.stats.StatList;
|
| 15 | import net.minecraft.tileentity.TileEntity;
|
| 16 | import net.minecraft.util.BlockPos;
|
| 17 | import net.minecraft.world.World;
|
| 18 |
|
| 19 | public class BlockNewLeaf extends BlockLeaves
|
| 20 | {
|
| 21 | public static final PropertyEnum<BlockPlanks.EnumType> VARIANT = PropertyEnum.<BlockPlanks.EnumType>create("variant", BlockPlanks.EnumType.class, new Predicate<BlockPlanks.EnumType>()
|
| 22 | {
|
| 23 | public boolean apply(BlockPlanks.EnumType p_apply_1_)
|
| 24 | {
|
| 25 | return p_apply_1_.getMetadata() >= 4;
|
| 26 | }
|
| 27 | });
|
| 28 |
|
| 29 | public BlockNewLeaf()
|
| 30 | {
|
| 31 | this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockPlanks.EnumType.ACACIA).withProperty(CHECK_DECAY, Boolean.valueOf(true)).withProperty(DECAYABLE, Boolean.valueOf(true)));
|
| 32 | }
|
| 33 |
|
| 34 | protected void dropApple(World worldIn, BlockPos pos, IBlockState state, int chance)
|
| 35 | {
|
| 36 | if (state.getValue(VARIANT) == BlockPlanks.EnumType.DARK_OAK && worldIn.rand.nextInt(chance) == 0)
|
| 37 | {
|
| 38 | spawnAsEntity(worldIn, pos, new ItemStack(Items.apple, 1, 0));
|
| 39 | }
|
| 40 | }
|
| 41 |
|
| 42 | /**
|
| 43 | * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
|
| 44 | * returns the metadata of the dropped item based on the old metadata of the block.
|
| 45 | */
|
| 46 | public int damageDropped(IBlockState state)
|
| 47 | {
|
| 48 | return ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata();
|
| 49 | }
|
| 50 |
|
| 51 | /**
|
| 52 | * Gets the meta to use for the Pick Block ItemStack result
|
| 53 | */
|
| 54 | public int getDamageValue(World worldIn, BlockPos pos)
|
| 55 | {
|
| 56 | IBlockState iblockstate = worldIn.getBlockState(pos);
|
| 57 | return iblockstate.getBlock().getMetaFromState(iblockstate) & 3;
|
| 58 | }
|
| 59 |
|
| 60 | /**
|
| 61 | * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
|
| 62 | */
|
| 63 | public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
|
| 64 | {
|
| 65 | list.add(new ItemStack(itemIn, 1, 0));
|
| 66 | list.add(new ItemStack(itemIn, 1, 1));
|
| 67 | }
|
| 68 |
|
| 69 | protected ItemStack createStackedBlock(IBlockState state)
|
| 70 | {
|
| 71 | return new ItemStack(Item.getItemFromBlock(this), 1, ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata() - 4);
|
| 72 | }
|
| 73 |
|
| 74 | /**
|
| 75 | * Convert the given metadata into a BlockState for this Block
|
| 76 | */
|
| 77 | public IBlockState getStateFromMeta(int meta)
|
| 78 | {
|
| 79 | return this.getDefaultState().withProperty(VARIANT, this.getWoodType(meta)).withProperty(DECAYABLE, Boolean.valueOf((meta & 4) == 0)).withProperty(CHECK_DECAY, Boolean.valueOf((meta & 8) > 0));
|
| 80 | }
|
| 81 |
|
| 82 | /**
|
| 83 | * Convert the BlockState into the correct metadata value
|
| 84 | */
|
| 85 | public int getMetaFromState(IBlockState state)
|
| 86 | {
|
| 87 | int i = 0;
|
| 88 | i = i | ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata() - 4;
|
| 89 |
|
| 90 | if (!((Boolean)state.getValue(DECAYABLE)).booleanValue())
|
| 91 | {
|
| 92 | i |= 4;
|
| 93 | }
|
| 94 |
|
| 95 | if (((Boolean)state.getValue(CHECK_DECAY)).booleanValue())
|
| 96 | {
|
| 97 | i |= 8;
|
| 98 | }
|
| 99 |
|
| 100 | return i;
|
| 101 | }
|
| 102 |
|
| 103 | public BlockPlanks.EnumType getWoodType(int meta)
|
| 104 | {
|
| 105 | return BlockPlanks.EnumType.byMetadata((meta & 3) + 4);
|
| 106 | }
|
| 107 |
|
| 108 | protected BlockState createBlockState()
|
| 109 | {
|
| 110 | return new BlockState(this, new IProperty[] {VARIANT, CHECK_DECAY, DECAYABLE});
|
| 111 | }
|
| 112 |
|
| 113 | public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
|
| 114 | {
|
| 115 | if (!worldIn.isRemote && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears)
|
| 116 | {
|
| 117 | player.triggerAchievement(StatList.mineBlockStatArray[Block.getIdFromBlock(this)]);
|
| 118 | spawnAsEntity(worldIn, pos, new ItemStack(Item.getItemFromBlock(this), 1, ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata() - 4));
|
| 119 | }
|
| 120 | else
|
| 121 | {
|
| 122 | super.harvestBlock(worldIn, player, pos, state, te);
|
| 123 | }
|
| 124 | }
|
| 125 | }
|
| 126 |
|