| 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.ColorizerFoliage;
|
| 18 | import net.minecraft.world.IBlockAccess;
|
| 19 | import net.minecraft.world.World;
|
| 20 |
|
| 21 | public class BlockOldLeaf extends BlockLeaves
|
| 22 | {
|
| 23 | public static final PropertyEnum<BlockPlanks.EnumType> VARIANT = PropertyEnum.<BlockPlanks.EnumType>create("variant", BlockPlanks.EnumType.class, new Predicate<BlockPlanks.EnumType>()
|
| 24 | {
|
| 25 | public boolean apply(BlockPlanks.EnumType p_apply_1_)
|
| 26 | {
|
| 27 | return p_apply_1_.getMetadata() < 4;
|
| 28 | }
|
| 29 | });
|
| 30 |
|
| 31 | public BlockOldLeaf()
|
| 32 | {
|
| 33 | this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockPlanks.EnumType.OAK).withProperty(CHECK_DECAY, Boolean.valueOf(true)).withProperty(DECAYABLE, Boolean.valueOf(true)));
|
| 34 | }
|
| 35 |
|
| 36 | public int getRenderColor(IBlockState state)
|
| 37 | {
|
| 38 | if (state.getBlock() != this)
|
| 39 | {
|
| 40 | return super.getRenderColor(state);
|
| 41 | }
|
| 42 | else
|
| 43 | {
|
| 44 | BlockPlanks.EnumType blockplanks$enumtype = (BlockPlanks.EnumType)state.getValue(VARIANT);
|
| 45 | return blockplanks$enumtype == BlockPlanks.EnumType.SPRUCE ? ColorizerFoliage.getFoliageColorPine() : (blockplanks$enumtype == BlockPlanks.EnumType.BIRCH ? ColorizerFoliage.getFoliageColorBirch() : super.getRenderColor(state));
|
| 46 | }
|
| 47 | }
|
| 48 |
|
| 49 | public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
|
| 50 | {
|
| 51 | IBlockState iblockstate = worldIn.getBlockState(pos);
|
| 52 |
|
| 53 | if (iblockstate.getBlock() == this)
|
| 54 | {
|
| 55 | BlockPlanks.EnumType blockplanks$enumtype = (BlockPlanks.EnumType)iblockstate.getValue(VARIANT);
|
| 56 |
|
| 57 | if (blockplanks$enumtype == BlockPlanks.EnumType.SPRUCE)
|
| 58 | {
|
| 59 | return ColorizerFoliage.getFoliageColorPine();
|
| 60 | }
|
| 61 |
|
| 62 | if (blockplanks$enumtype == BlockPlanks.EnumType.BIRCH)
|
| 63 | {
|
| 64 | return ColorizerFoliage.getFoliageColorBirch();
|
| 65 | }
|
| 66 | }
|
| 67 |
|
| 68 | return super.colorMultiplier(worldIn, pos, renderPass);
|
| 69 | }
|
| 70 |
|
| 71 | protected void dropApple(World worldIn, BlockPos pos, IBlockState state, int chance)
|
| 72 | {
|
| 73 | if (state.getValue(VARIANT) == BlockPlanks.EnumType.OAK && worldIn.rand.nextInt(chance) == 0)
|
| 74 | {
|
| 75 | spawnAsEntity(worldIn, pos, new ItemStack(Items.apple, 1, 0));
|
| 76 | }
|
| 77 | }
|
| 78 |
|
| 79 | protected int getSaplingDropChance(IBlockState state)
|
| 80 | {
|
| 81 | return state.getValue(VARIANT) == BlockPlanks.EnumType.JUNGLE ? 40 : super.getSaplingDropChance(state);
|
| 82 | }
|
| 83 |
|
| 84 | /**
|
| 85 | * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
|
| 86 | */
|
| 87 | public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
|
| 88 | {
|
| 89 | list.add(new ItemStack(itemIn, 1, BlockPlanks.EnumType.OAK.getMetadata()));
|
| 90 | list.add(new ItemStack(itemIn, 1, BlockPlanks.EnumType.SPRUCE.getMetadata()));
|
| 91 | list.add(new ItemStack(itemIn, 1, BlockPlanks.EnumType.BIRCH.getMetadata()));
|
| 92 | list.add(new ItemStack(itemIn, 1, BlockPlanks.EnumType.JUNGLE.getMetadata()));
|
| 93 | }
|
| 94 |
|
| 95 | protected ItemStack createStackedBlock(IBlockState state)
|
| 96 | {
|
| 97 | return new ItemStack(Item.getItemFromBlock(this), 1, ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata());
|
| 98 | }
|
| 99 |
|
| 100 | /**
|
| 101 | * Convert the given metadata into a BlockState for this Block
|
| 102 | */
|
| 103 | public IBlockState getStateFromMeta(int meta)
|
| 104 | {
|
| 105 | return this.getDefaultState().withProperty(VARIANT, this.getWoodType(meta)).withProperty(DECAYABLE, Boolean.valueOf((meta & 4) == 0)).withProperty(CHECK_DECAY, Boolean.valueOf((meta & 8) > 0));
|
| 106 | }
|
| 107 |
|
| 108 | /**
|
| 109 | * Convert the BlockState into the correct metadata value
|
| 110 | */
|
| 111 | public int getMetaFromState(IBlockState state)
|
| 112 | {
|
| 113 | int i = 0;
|
| 114 | i = i | ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata();
|
| 115 |
|
| 116 | if (!((Boolean)state.getValue(DECAYABLE)).booleanValue())
|
| 117 | {
|
| 118 | i |= 4;
|
| 119 | }
|
| 120 |
|
| 121 | if (((Boolean)state.getValue(CHECK_DECAY)).booleanValue())
|
| 122 | {
|
| 123 | i |= 8;
|
| 124 | }
|
| 125 |
|
| 126 | return i;
|
| 127 | }
|
| 128 |
|
| 129 | public BlockPlanks.EnumType getWoodType(int meta)
|
| 130 | {
|
| 131 | return BlockPlanks.EnumType.byMetadata((meta & 3) % 4);
|
| 132 | }
|
| 133 |
|
| 134 | protected BlockState createBlockState()
|
| 135 | {
|
| 136 | return new BlockState(this, new IProperty[] {VARIANT, CHECK_DECAY, DECAYABLE});
|
| 137 | }
|
| 138 |
|
| 139 | /**
|
| 140 | * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
|
| 141 | * returns the metadata of the dropped item based on the old metadata of the block.
|
| 142 | */
|
| 143 | public int damageDropped(IBlockState state)
|
| 144 | {
|
| 145 | return ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata();
|
| 146 | }
|
| 147 |
|
| 148 | public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
|
| 149 | {
|
| 150 | if (!worldIn.isRemote && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears)
|
| 151 | {
|
| 152 | player.triggerAchievement(StatList.mineBlockStatArray[Block.getIdFromBlock(this)]);
|
| 153 | spawnAsEntity(worldIn, pos, new ItemStack(Item.getItemFromBlock(this), 1, ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata()));
|
| 154 | }
|
| 155 | else
|
| 156 | {
|
| 157 | super.harvestBlock(worldIn, player, pos, state, te);
|
| 158 | }
|
| 159 | }
|
| 160 | }
|
| 161 |
|