| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import java.util.Random;
|
| 4 | import net.minecraft.block.material.Material;
|
| 5 | import net.minecraft.block.state.IBlockState;
|
| 6 | import net.minecraft.creativetab.CreativeTabs;
|
| 7 | import net.minecraft.entity.item.EntityFallingBlock;
|
| 8 | import net.minecraft.init.Blocks;
|
| 9 | import net.minecraft.util.BlockPos;
|
| 10 | import net.minecraft.world.World;
|
| 11 |
|
| 12 | public class BlockFalling extends Block
|
| 13 | {
|
| 14 | public static boolean fallInstantly;
|
| 15 |
|
| 16 | public BlockFalling()
|
| 17 | {
|
| 18 | super(Material.sand);
|
| 19 | this.setCreativeTab(CreativeTabs.tabBlock);
|
| 20 | }
|
| 21 |
|
| 22 | public BlockFalling(Material materialIn)
|
| 23 | {
|
| 24 | super(materialIn);
|
| 25 | }
|
| 26 |
|
| 27 | public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
|
| 28 | {
|
| 29 | worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
|
| 30 | }
|
| 31 |
|
| 32 | /**
|
| 33 | * Called when a neighboring block changes.
|
| 34 | */
|
| 35 | public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
|
| 36 | {
|
| 37 | worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
|
| 38 | }
|
| 39 |
|
| 40 | public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
|
| 41 | {
|
| 42 | if (!worldIn.isRemote)
|
| 43 | {
|
| 44 | this.checkFallable(worldIn, pos);
|
| 45 | }
|
| 46 | }
|
| 47 |
|
| 48 | private void checkFallable(World worldIn, BlockPos pos)
|
| 49 | {
|
| 50 | if (canFallInto(worldIn, pos.down()) && pos.getY() >= 0)
|
| 51 | {
|
| 52 | int i = 32;
|
| 53 |
|
| 54 | if (!fallInstantly && worldIn.isAreaLoaded(pos.add(-i, -i, -i), pos.add(i, i, i)))
|
| 55 | {
|
| 56 | if (!worldIn.isRemote)
|
| 57 | {
|
| 58 | EntityFallingBlock entityfallingblock = new EntityFallingBlock(worldIn, (double)pos.getX() + 0.5D, (double)pos.getY(), (double)pos.getZ() + 0.5D, worldIn.getBlockState(pos));
|
| 59 | this.onStartFalling(entityfallingblock);
|
| 60 | worldIn.spawnEntityInWorld(entityfallingblock);
|
| 61 | }
|
| 62 | }
|
| 63 | else
|
| 64 | {
|
| 65 | worldIn.setBlockToAir(pos);
|
| 66 | BlockPos blockpos;
|
| 67 |
|
| 68 | for (blockpos = pos.down(); canFallInto(worldIn, blockpos) && blockpos.getY() > 0; blockpos = blockpos.down())
|
| 69 | {
|
| 70 | ;
|
| 71 | }
|
| 72 |
|
| 73 | if (blockpos.getY() > 0)
|
| 74 | {
|
| 75 | worldIn.setBlockState(blockpos.up(), this.getDefaultState());
|
| 76 | }
|
| 77 | }
|
| 78 | }
|
| 79 | }
|
| 80 |
|
| 81 | protected void onStartFalling(EntityFallingBlock fallingEntity)
|
| 82 | {
|
| 83 | }
|
| 84 |
|
| 85 | /**
|
| 86 | * How many world ticks before ticking
|
| 87 | */
|
| 88 | public int tickRate(World worldIn)
|
| 89 | {
|
| 90 | return 2;
|
| 91 | }
|
| 92 |
|
| 93 | public static boolean canFallInto(World worldIn, BlockPos pos)
|
| 94 | {
|
| 95 | Block block = worldIn.getBlockState(pos).getBlock();
|
| 96 | Material material = block.blockMaterial;
|
| 97 | return block == Blocks.fire || material == Material.air || material == Material.water || material == Material.lava;
|
| 98 | }
|
| 99 |
|
| 100 | public void onEndFalling(World worldIn, BlockPos pos)
|
| 101 | {
|
| 102 | }
|
| 103 | }
|
| 104 |
|