| 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.PropertyInteger;
|
| 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.Entity;
|
| 11 | import net.minecraft.init.Blocks;
|
| 12 | import net.minecraft.util.AxisAlignedBB;
|
| 13 | import net.minecraft.util.BlockPos;
|
| 14 | import net.minecraft.util.DamageSource;
|
| 15 | import net.minecraft.util.EnumFacing;
|
| 16 | import net.minecraft.util.EnumWorldBlockLayer;
|
| 17 | import net.minecraft.world.World;
|
| 18 |
|
| 19 | public class BlockCactus extends Block
|
| 20 | {
|
| 21 | public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 15);
|
| 22 |
|
| 23 | protected BlockCactus()
|
| 24 | {
|
| 25 | super(Material.cactus);
|
| 26 | this.setDefaultState(this.blockState.getBaseState().withProperty(AGE, Integer.valueOf(0)));
|
| 27 | this.setTickRandomly(true);
|
| 28 | this.setCreativeTab(CreativeTabs.tabDecorations);
|
| 29 | }
|
| 30 |
|
| 31 | public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
|
| 32 | {
|
| 33 | BlockPos blockpos = pos.up();
|
| 34 |
|
| 35 | if (worldIn.isAirBlock(blockpos))
|
| 36 | {
|
| 37 | int i;
|
| 38 |
|
| 39 | for (i = 1; worldIn.getBlockState(pos.down(i)).getBlock() == this; ++i)
|
| 40 | {
|
| 41 | ;
|
| 42 | }
|
| 43 |
|
| 44 | if (i < 3)
|
| 45 | {
|
| 46 | int j = ((Integer)state.getValue(AGE)).intValue();
|
| 47 |
|
| 48 | if (j == 15)
|
| 49 | {
|
| 50 | worldIn.setBlockState(blockpos, this.getDefaultState());
|
| 51 | IBlockState iblockstate = state.withProperty(AGE, Integer.valueOf(0));
|
| 52 | worldIn.setBlockState(pos, iblockstate, 4);
|
| 53 | this.onNeighborBlockChange(worldIn, blockpos, iblockstate, this);
|
| 54 | }
|
| 55 | else
|
| 56 | {
|
| 57 | worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(j + 1)), 4);
|
| 58 | }
|
| 59 | }
|
| 60 | }
|
| 61 | }
|
| 62 |
|
| 63 | public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
|
| 64 | {
|
| 65 | float f = 0.0625F;
|
| 66 | return new AxisAlignedBB((double)((float)pos.getX() + f), (double)pos.getY(), (double)((float)pos.getZ() + f), (double)((float)(pos.getX() + 1) - f), (double)((float)(pos.getY() + 1) - f), (double)((float)(pos.getZ() + 1) - f));
|
| 67 | }
|
| 68 |
|
| 69 | public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos)
|
| 70 | {
|
| 71 | float f = 0.0625F;
|
| 72 | return new AxisAlignedBB((double)((float)pos.getX() + f), (double)pos.getY(), (double)((float)pos.getZ() + f), (double)((float)(pos.getX() + 1) - f), (double)(pos.getY() + 1), (double)((float)(pos.getZ() + 1) - f));
|
| 73 | }
|
| 74 |
|
| 75 | public boolean isFullCube()
|
| 76 | {
|
| 77 | return false;
|
| 78 | }
|
| 79 |
|
| 80 | /**
|
| 81 | * Used to determine ambient occlusion and culling when rebuilding chunks for render
|
| 82 | */
|
| 83 | public boolean isOpaqueCube()
|
| 84 | {
|
| 85 | return false;
|
| 86 | }
|
| 87 |
|
| 88 | public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
|
| 89 | {
|
| 90 | return super.canPlaceBlockAt(worldIn, pos) ? this.canBlockStay(worldIn, pos) : false;
|
| 91 | }
|
| 92 |
|
| 93 | /**
|
| 94 | * Called when a neighboring block changes.
|
| 95 | */
|
| 96 | public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
|
| 97 | {
|
| 98 | if (!this.canBlockStay(worldIn, pos))
|
| 99 | {
|
| 100 | worldIn.destroyBlock(pos, true);
|
| 101 | }
|
| 102 | }
|
| 103 |
|
| 104 | public boolean canBlockStay(World worldIn, BlockPos pos)
|
| 105 | {
|
| 106 | for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
|
| 107 | {
|
| 108 | if (worldIn.getBlockState(pos.offset(enumfacing)).getBlock().getMaterial().isSolid())
|
| 109 | {
|
| 110 | return false;
|
| 111 | }
|
| 112 | }
|
| 113 |
|
| 114 | Block block = worldIn.getBlockState(pos.down()).getBlock();
|
| 115 | return block == Blocks.cactus || block == Blocks.sand;
|
| 116 | }
|
| 117 |
|
| 118 | /**
|
| 119 | * Called When an Entity Collided with the Block
|
| 120 | */
|
| 121 | public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
|
| 122 | {
|
| 123 | entityIn.attackEntityFrom(DamageSource.cactus, 1.0F);
|
| 124 | }
|
| 125 |
|
| 126 | public EnumWorldBlockLayer getBlockLayer()
|
| 127 | {
|
| 128 | return EnumWorldBlockLayer.CUTOUT;
|
| 129 | }
|
| 130 |
|
| 131 | /**
|
| 132 | * Convert the given metadata into a BlockState for this Block
|
| 133 | */
|
| 134 | public IBlockState getStateFromMeta(int meta)
|
| 135 | {
|
| 136 | return this.getDefaultState().withProperty(AGE, Integer.valueOf(meta));
|
| 137 | }
|
| 138 |
|
| 139 | /**
|
| 140 | * Convert the BlockState into the correct metadata value
|
| 141 | */
|
| 142 | public int getMetaFromState(IBlockState state)
|
| 143 | {
|
| 144 | return ((Integer)state.getValue(AGE)).intValue();
|
| 145 | }
|
| 146 |
|
| 147 | protected BlockState createBlockState()
|
| 148 | {
|
| 149 | return new BlockState(this, new IProperty[] {AGE});
|
| 150 | }
|
| 151 | }
|
| 152 |
|