| 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.init.Blocks;
|
| 7 | import net.minecraft.util.BlockPos;
|
| 8 | import net.minecraft.util.EnumFacing;
|
| 9 | import net.minecraft.world.World;
|
| 10 |
|
| 11 | public class BlockStaticLiquid extends BlockLiquid
|
| 12 | {
|
| 13 | protected BlockStaticLiquid(Material materialIn)
|
| 14 | {
|
| 15 | super(materialIn);
|
| 16 | this.setTickRandomly(false);
|
| 17 |
|
| 18 | if (materialIn == Material.lava)
|
| 19 | {
|
| 20 | this.setTickRandomly(true);
|
| 21 | }
|
| 22 | }
|
| 23 |
|
| 24 | /**
|
| 25 | * Called when a neighboring block changes.
|
| 26 | */
|
| 27 | public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
|
| 28 | {
|
| 29 | if (!this.checkForMixing(worldIn, pos, state))
|
| 30 | {
|
| 31 | this.updateLiquid(worldIn, pos, state);
|
| 32 | }
|
| 33 | }
|
| 34 |
|
| 35 | private void updateLiquid(World worldIn, BlockPos pos, IBlockState state)
|
| 36 | {
|
| 37 | BlockDynamicLiquid blockdynamicliquid = getFlowingBlock(this.blockMaterial);
|
| 38 | worldIn.setBlockState(pos, blockdynamicliquid.getDefaultState().withProperty(LEVEL, state.getValue(LEVEL)), 2);
|
| 39 | worldIn.scheduleUpdate(pos, blockdynamicliquid, this.tickRate(worldIn));
|
| 40 | }
|
| 41 |
|
| 42 | public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
|
| 43 | {
|
| 44 | if (this.blockMaterial == Material.lava)
|
| 45 | {
|
| 46 | if (worldIn.getGameRules().getBoolean("doFireTick"))
|
| 47 | {
|
| 48 | int i = rand.nextInt(3);
|
| 49 |
|
| 50 | if (i > 0)
|
| 51 | {
|
| 52 | BlockPos blockpos = pos;
|
| 53 |
|
| 54 | for (int j = 0; j < i; ++j)
|
| 55 | {
|
| 56 | blockpos = blockpos.add(rand.nextInt(3) - 1, 1, rand.nextInt(3) - 1);
|
| 57 | Block block = worldIn.getBlockState(blockpos).getBlock();
|
| 58 |
|
| 59 | if (block.blockMaterial == Material.air)
|
| 60 | {
|
| 61 | if (this.isSurroundingBlockFlammable(worldIn, blockpos))
|
| 62 | {
|
| 63 | worldIn.setBlockState(blockpos, Blocks.fire.getDefaultState());
|
| 64 | return;
|
| 65 | }
|
| 66 | }
|
| 67 | else if (block.blockMaterial.blocksMovement())
|
| 68 | {
|
| 69 | return;
|
| 70 | }
|
| 71 | }
|
| 72 | }
|
| 73 | else
|
| 74 | {
|
| 75 | for (int k = 0; k < 3; ++k)
|
| 76 | {
|
| 77 | BlockPos blockpos1 = pos.add(rand.nextInt(3) - 1, 0, rand.nextInt(3) - 1);
|
| 78 |
|
| 79 | if (worldIn.isAirBlock(blockpos1.up()) && this.getCanBlockBurn(worldIn, blockpos1))
|
| 80 | {
|
| 81 | worldIn.setBlockState(blockpos1.up(), Blocks.fire.getDefaultState());
|
| 82 | }
|
| 83 | }
|
| 84 | }
|
| 85 | }
|
| 86 | }
|
| 87 | }
|
| 88 |
|
| 89 | protected boolean isSurroundingBlockFlammable(World worldIn, BlockPos pos)
|
| 90 | {
|
| 91 | for (EnumFacing enumfacing : EnumFacing.values())
|
| 92 | {
|
| 93 | if (this.getCanBlockBurn(worldIn, pos.offset(enumfacing)))
|
| 94 | {
|
| 95 | return true;
|
| 96 | }
|
| 97 | }
|
| 98 |
|
| 99 | return false;
|
| 100 | }
|
| 101 |
|
| 102 | private boolean getCanBlockBurn(World worldIn, BlockPos pos)
|
| 103 | {
|
| 104 | return worldIn.getBlockState(pos).getBlock().getMaterial().getCanBurn();
|
| 105 | }
|
| 106 | }
|
| 107 |
|