| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import java.util.Random;
|
| 4 | import net.minecraft.block.material.Material;
|
| 5 | import net.minecraft.block.properties.IProperty;
|
| 6 | import net.minecraft.block.properties.PropertyBool;
|
| 7 | import net.minecraft.block.state.BlockState;
|
| 8 | import net.minecraft.block.state.IBlockState;
|
| 9 | import net.minecraft.creativetab.CreativeTabs;
|
| 10 | import net.minecraft.init.Blocks;
|
| 11 | import net.minecraft.item.Item;
|
| 12 | import net.minecraft.util.BlockPos;
|
| 13 | import net.minecraft.util.EnumWorldBlockLayer;
|
| 14 | import net.minecraft.world.ColorizerGrass;
|
| 15 | import net.minecraft.world.IBlockAccess;
|
| 16 | import net.minecraft.world.World;
|
| 17 | import net.minecraft.world.biome.BiomeColorHelper;
|
| 18 |
|
| 19 | public class BlockGrass extends Block implements IGrowable
|
| 20 | {
|
| 21 | public static final PropertyBool SNOWY = PropertyBool.create("snowy");
|
| 22 |
|
| 23 | protected BlockGrass()
|
| 24 | {
|
| 25 | super(Material.grass);
|
| 26 | this.setDefaultState(this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)));
|
| 27 | this.setTickRandomly(true);
|
| 28 | this.setCreativeTab(CreativeTabs.tabBlock);
|
| 29 | }
|
| 30 |
|
| 31 | /**
|
| 32 | * Get the actual Block state of this Block at the given position. This applies properties not visible in the
|
| 33 | * metadata, such as fence connections.
|
| 34 | */
|
| 35 | public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
|
| 36 | {
|
| 37 | Block block = worldIn.getBlockState(pos.up()).getBlock();
|
| 38 | return state.withProperty(SNOWY, Boolean.valueOf(block == Blocks.snow || block == Blocks.snow_layer));
|
| 39 | }
|
| 40 |
|
| 41 | public int getBlockColor()
|
| 42 | {
|
| 43 | return ColorizerGrass.getGrassColor(0.5D, 1.0D);
|
| 44 | }
|
| 45 |
|
| 46 | public int getRenderColor(IBlockState state)
|
| 47 | {
|
| 48 | return this.getBlockColor();
|
| 49 | }
|
| 50 |
|
| 51 | public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
|
| 52 | {
|
| 53 | return BiomeColorHelper.getGrassColorAtPos(worldIn, pos);
|
| 54 | }
|
| 55 |
|
| 56 | public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
|
| 57 | {
|
| 58 | if (!worldIn.isRemote)
|
| 59 | {
|
| 60 | if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getBlock().getLightOpacity() > 2)
|
| 61 | {
|
| 62 | worldIn.setBlockState(pos, Blocks.dirt.getDefaultState());
|
| 63 | }
|
| 64 | else
|
| 65 | {
|
| 66 | if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
|
| 67 | {
|
| 68 | for (int i = 0; i < 4; ++i)
|
| 69 | {
|
| 70 | BlockPos blockpos = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);
|
| 71 | Block block = worldIn.getBlockState(blockpos.up()).getBlock();
|
| 72 | IBlockState iblockstate = worldIn.getBlockState(blockpos);
|
| 73 |
|
| 74 | if (iblockstate.getBlock() == Blocks.dirt && iblockstate.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && block.getLightOpacity() <= 2)
|
| 75 | {
|
| 76 | worldIn.setBlockState(blockpos, Blocks.grass.getDefaultState());
|
| 77 | }
|
| 78 | }
|
| 79 | }
|
| 80 | }
|
| 81 | }
|
| 82 | }
|
| 83 |
|
| 84 | /**
|
| 85 | * Get the Item that this Block should drop when harvested.
|
| 86 | */
|
| 87 | public Item getItemDropped(IBlockState state, Random rand, int fortune)
|
| 88 | {
|
| 89 | return Blocks.dirt.getItemDropped(Blocks.dirt.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT), rand, fortune);
|
| 90 | }
|
| 91 |
|
| 92 | /**
|
| 93 | * Whether this IGrowable can grow
|
| 94 | */
|
| 95 | public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
|
| 96 | {
|
| 97 | return true;
|
| 98 | }
|
| 99 |
|
| 100 | public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
|
| 101 | {
|
| 102 | return true;
|
| 103 | }
|
| 104 |
|
| 105 | public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
|
| 106 | {
|
| 107 | BlockPos blockpos = pos.up();
|
| 108 |
|
| 109 | for (int i = 0; i < 128; ++i)
|
| 110 | {
|
| 111 | BlockPos blockpos1 = blockpos;
|
| 112 | int j = 0;
|
| 113 |
|
| 114 | while (true)
|
| 115 | {
|
| 116 | if (j >= i / 16)
|
| 117 | {
|
| 118 | if (worldIn.getBlockState(blockpos1).getBlock().blockMaterial == Material.air)
|
| 119 | {
|
| 120 | if (rand.nextInt(8) == 0)
|
| 121 | {
|
| 122 | BlockFlower.EnumFlowerType blockflower$enumflowertype = worldIn.getBiomeGenForCoords(blockpos1).pickRandomFlower(rand, blockpos1);
|
| 123 | BlockFlower blockflower = blockflower$enumflowertype.getBlockType().getBlock();
|
| 124 | IBlockState iblockstate = blockflower.getDefaultState().withProperty(blockflower.getTypeProperty(), blockflower$enumflowertype);
|
| 125 |
|
| 126 | if (blockflower.canBlockStay(worldIn, blockpos1, iblockstate))
|
| 127 | {
|
| 128 | worldIn.setBlockState(blockpos1, iblockstate, 3);
|
| 129 | }
|
| 130 | }
|
| 131 | else
|
| 132 | {
|
| 133 | IBlockState iblockstate1 = Blocks.tallgrass.getDefaultState().withProperty(BlockTallGrass.TYPE, BlockTallGrass.EnumType.GRASS);
|
| 134 |
|
| 135 | if (Blocks.tallgrass.canBlockStay(worldIn, blockpos1, iblockstate1))
|
| 136 | {
|
| 137 | worldIn.setBlockState(blockpos1, iblockstate1, 3);
|
| 138 | }
|
| 139 | }
|
| 140 | }
|
| 141 |
|
| 142 | break;
|
| 143 | }
|
| 144 |
|
| 145 | blockpos1 = blockpos1.add(rand.nextInt(3) - 1, (rand.nextInt(3) - 1) * rand.nextInt(3) / 2, rand.nextInt(3) - 1);
|
| 146 |
|
| 147 | if (worldIn.getBlockState(blockpos1.down()).getBlock() != Blocks.grass || worldIn.getBlockState(blockpos1).getBlock().isNormalCube())
|
| 148 | {
|
| 149 | break;
|
| 150 | }
|
| 151 |
|
| 152 | ++j;
|
| 153 | }
|
| 154 | }
|
| 155 | }
|
| 156 |
|
| 157 | public EnumWorldBlockLayer getBlockLayer()
|
| 158 | {
|
| 159 | return EnumWorldBlockLayer.CUTOUT_MIPPED;
|
| 160 | }
|
| 161 |
|
| 162 | /**
|
| 163 | * Convert the BlockState into the correct metadata value
|
| 164 | */
|
| 165 | public int getMetaFromState(IBlockState state)
|
| 166 | {
|
| 167 | return 0;
|
| 168 | }
|
| 169 |
|
| 170 | protected BlockState createBlockState()
|
| 171 | {
|
| 172 | return new BlockState(this, new IProperty[] {SNOWY});
|
| 173 | }
|
| 174 | }
|
| 175 |
|