| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import java.util.Random;
|
| 5 | import net.minecraft.block.material.Material;
|
| 6 | import net.minecraft.block.properties.IProperty;
|
| 7 | import net.minecraft.block.properties.PropertyEnum;
|
| 8 | import net.minecraft.block.state.BlockState;
|
| 9 | import net.minecraft.block.state.IBlockState;
|
| 10 | import net.minecraft.creativetab.CreativeTabs;
|
| 11 | import net.minecraft.entity.player.EntityPlayer;
|
| 12 | import net.minecraft.init.Blocks;
|
| 13 | import net.minecraft.init.Items;
|
| 14 | import net.minecraft.item.Item;
|
| 15 | import net.minecraft.item.ItemStack;
|
| 16 | import net.minecraft.stats.StatList;
|
| 17 | import net.minecraft.tileentity.TileEntity;
|
| 18 | import net.minecraft.util.BlockPos;
|
| 19 | import net.minecraft.util.IStringSerializable;
|
| 20 | import net.minecraft.world.ColorizerGrass;
|
| 21 | import net.minecraft.world.IBlockAccess;
|
| 22 | import net.minecraft.world.World;
|
| 23 |
|
| 24 | public class BlockTallGrass extends BlockBush implements IGrowable
|
| 25 | {
|
| 26 | public static final PropertyEnum<BlockTallGrass.EnumType> TYPE = PropertyEnum.<BlockTallGrass.EnumType>create("type", BlockTallGrass.EnumType.class);
|
| 27 |
|
| 28 | protected BlockTallGrass()
|
| 29 | {
|
| 30 | super(Material.vine);
|
| 31 | this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, BlockTallGrass.EnumType.DEAD_BUSH));
|
| 32 | float f = 0.4F;
|
| 33 | this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.8F, 0.5F + f);
|
| 34 | }
|
| 35 |
|
| 36 | public int getBlockColor()
|
| 37 | {
|
| 38 | return ColorizerGrass.getGrassColor(0.5D, 1.0D);
|
| 39 | }
|
| 40 |
|
| 41 | public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
|
| 42 | {
|
| 43 | return this.canPlaceBlockOn(worldIn.getBlockState(pos.down()).getBlock());
|
| 44 | }
|
| 45 |
|
| 46 | /**
|
| 47 | * Whether this Block can be replaced directly by other blocks (true for e.g. tall grass)
|
| 48 | */
|
| 49 | public boolean isReplaceable(World worldIn, BlockPos pos)
|
| 50 | {
|
| 51 | return true;
|
| 52 | }
|
| 53 |
|
| 54 | public int getRenderColor(IBlockState state)
|
| 55 | {
|
| 56 | if (state.getBlock() != this)
|
| 57 | {
|
| 58 | return super.getRenderColor(state);
|
| 59 | }
|
| 60 | else
|
| 61 | {
|
| 62 | BlockTallGrass.EnumType blocktallgrass$enumtype = (BlockTallGrass.EnumType)state.getValue(TYPE);
|
| 63 | return blocktallgrass$enumtype == BlockTallGrass.EnumType.DEAD_BUSH ? 16777215 : ColorizerGrass.getGrassColor(0.5D, 1.0D);
|
| 64 | }
|
| 65 | }
|
| 66 |
|
| 67 | public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
|
| 68 | {
|
| 69 | return worldIn.getBiomeGenForCoords(pos).getGrassColorAtPos(pos);
|
| 70 | }
|
| 71 |
|
| 72 | /**
|
| 73 | * Get the Item that this Block should drop when harvested.
|
| 74 | */
|
| 75 | public Item getItemDropped(IBlockState state, Random rand, int fortune)
|
| 76 | {
|
| 77 | return rand.nextInt(8) == 0 ? Items.wheat_seeds : null;
|
| 78 | }
|
| 79 |
|
| 80 | /**
|
| 81 | * Get the quantity dropped based on the given fortune level
|
| 82 | */
|
| 83 | public int quantityDroppedWithBonus(int fortune, Random random)
|
| 84 | {
|
| 85 | return 1 + random.nextInt(fortune * 2 + 1);
|
| 86 | }
|
| 87 |
|
| 88 | public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
|
| 89 | {
|
| 90 | if (!worldIn.isRemote && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears)
|
| 91 | {
|
| 92 | player.triggerAchievement(StatList.mineBlockStatArray[Block.getIdFromBlock(this)]);
|
| 93 | spawnAsEntity(worldIn, pos, new ItemStack(Blocks.tallgrass, 1, ((BlockTallGrass.EnumType)state.getValue(TYPE)).getMeta()));
|
| 94 | }
|
| 95 | else
|
| 96 | {
|
| 97 | super.harvestBlock(worldIn, player, pos, state, te);
|
| 98 | }
|
| 99 | }
|
| 100 |
|
| 101 | /**
|
| 102 | * Gets the meta to use for the Pick Block ItemStack result
|
| 103 | */
|
| 104 | public int getDamageValue(World worldIn, BlockPos pos)
|
| 105 | {
|
| 106 | IBlockState iblockstate = worldIn.getBlockState(pos);
|
| 107 | return iblockstate.getBlock().getMetaFromState(iblockstate);
|
| 108 | }
|
| 109 |
|
| 110 | /**
|
| 111 | * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
|
| 112 | */
|
| 113 | public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
|
| 114 | {
|
| 115 | for (int i = 1; i < 3; ++i)
|
| 116 | {
|
| 117 | list.add(new ItemStack(itemIn, 1, i));
|
| 118 | }
|
| 119 | }
|
| 120 |
|
| 121 | /**
|
| 122 | * Whether this IGrowable can grow
|
| 123 | */
|
| 124 | public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
|
| 125 | {
|
| 126 | return state.getValue(TYPE) != BlockTallGrass.EnumType.DEAD_BUSH;
|
| 127 | }
|
| 128 |
|
| 129 | public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
|
| 130 | {
|
| 131 | return true;
|
| 132 | }
|
| 133 |
|
| 134 | public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
|
| 135 | {
|
| 136 | BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = BlockDoublePlant.EnumPlantType.GRASS;
|
| 137 |
|
| 138 | if (state.getValue(TYPE) == BlockTallGrass.EnumType.FERN)
|
| 139 | {
|
| 140 | blockdoubleplant$enumplanttype = BlockDoublePlant.EnumPlantType.FERN;
|
| 141 | }
|
| 142 |
|
| 143 | if (Blocks.double_plant.canPlaceBlockAt(worldIn, pos))
|
| 144 | {
|
| 145 | Blocks.double_plant.placeAt(worldIn, pos, blockdoubleplant$enumplanttype, 2);
|
| 146 | }
|
| 147 | }
|
| 148 |
|
| 149 | /**
|
| 150 | * Convert the given metadata into a BlockState for this Block
|
| 151 | */
|
| 152 | public IBlockState getStateFromMeta(int meta)
|
| 153 | {
|
| 154 | return this.getDefaultState().withProperty(TYPE, BlockTallGrass.EnumType.byMetadata(meta));
|
| 155 | }
|
| 156 |
|
| 157 | /**
|
| 158 | * Convert the BlockState into the correct metadata value
|
| 159 | */
|
| 160 | public int getMetaFromState(IBlockState state)
|
| 161 | {
|
| 162 | return ((BlockTallGrass.EnumType)state.getValue(TYPE)).getMeta();
|
| 163 | }
|
| 164 |
|
| 165 | protected BlockState createBlockState()
|
| 166 | {
|
| 167 | return new BlockState(this, new IProperty[] {TYPE});
|
| 168 | }
|
| 169 |
|
| 170 | /**
|
| 171 | * Get the OffsetType for this Block. Determines if the model is rendered slightly offset.
|
| 172 | */
|
| 173 | public Block.EnumOffsetType getOffsetType()
|
| 174 | {
|
| 175 | return Block.EnumOffsetType.XYZ;
|
| 176 | }
|
| 177 |
|
| 178 | public static enum EnumType implements IStringSerializable
|
| 179 | {
|
| 180 | DEAD_BUSH(0, "dead_bush"),
|
| 181 | GRASS(1, "tall_grass"),
|
| 182 | FERN(2, "fern");
|
| 183 |
|
| 184 | private static final BlockTallGrass.EnumType[] META_LOOKUP = new BlockTallGrass.EnumType[values().length];
|
| 185 | private final int meta;
|
| 186 | private final String name;
|
| 187 |
|
| 188 | private EnumType(int meta, String name)
|
| 189 | {
|
| 190 | this.meta = meta;
|
| 191 | this.name = name;
|
| 192 | }
|
| 193 |
|
| 194 | public int getMeta()
|
| 195 | {
|
| 196 | return this.meta;
|
| 197 | }
|
| 198 |
|
| 199 | public String toString()
|
| 200 | {
|
| 201 | return this.name;
|
| 202 | }
|
| 203 |
|
| 204 | public static BlockTallGrass.EnumType byMetadata(int meta)
|
| 205 | {
|
| 206 | if (meta < 0 || meta >= META_LOOKUP.length)
|
| 207 | {
|
| 208 | meta = 0;
|
| 209 | }
|
| 210 |
|
| 211 | return META_LOOKUP[meta];
|
| 212 | }
|
| 213 |
|
| 214 | public String getName()
|
| 215 | {
|
| 216 | return this.name;
|
| 217 | }
|
| 218 |
|
| 219 | static {
|
| 220 | for (BlockTallGrass.EnumType blocktallgrass$enumtype : values())
|
| 221 | {
|
| 222 | META_LOOKUP[blocktallgrass$enumtype.getMeta()] = blocktallgrass$enumtype;
|
| 223 | }
|
| 224 | }
|
| 225 | }
|
| 226 | }
|
| 227 |
|