| 1 | package net.minecraft.world.gen.feature;
|
| 2 |
|
| 3 | import java.util.Random;
|
| 4 | import net.minecraft.block.Block;
|
| 5 | import net.minecraft.block.BlockOldLeaf;
|
| 6 | import net.minecraft.block.BlockOldLog;
|
| 7 | import net.minecraft.block.BlockPlanks;
|
| 8 | import net.minecraft.block.material.Material;
|
| 9 | import net.minecraft.block.state.IBlockState;
|
| 10 | import net.minecraft.init.Blocks;
|
| 11 | import net.minecraft.util.BlockPos;
|
| 12 | import net.minecraft.world.World;
|
| 13 |
|
| 14 | public class WorldGenForest extends WorldGenAbstractTree
|
| 15 | {
|
| 16 | private static final IBlockState field_181629_a = Blocks.log.getDefaultState().withProperty(BlockOldLog.VARIANT, BlockPlanks.EnumType.BIRCH);
|
| 17 | private static final IBlockState field_181630_b = Blocks.leaves.getDefaultState().withProperty(BlockOldLeaf.VARIANT, BlockPlanks.EnumType.BIRCH).withProperty(BlockOldLeaf.CHECK_DECAY, Boolean.valueOf(false));
|
| 18 | private boolean useExtraRandomHeight;
|
| 19 |
|
| 20 | public WorldGenForest(boolean p_i45449_1_, boolean p_i45449_2_)
|
| 21 | {
|
| 22 | super(p_i45449_1_);
|
| 23 | this.useExtraRandomHeight = p_i45449_2_;
|
| 24 | }
|
| 25 |
|
| 26 | public boolean generate(World worldIn, Random rand, BlockPos position)
|
| 27 | {
|
| 28 | int i = rand.nextInt(3) + 5;
|
| 29 |
|
| 30 | if (this.useExtraRandomHeight)
|
| 31 | {
|
| 32 | i += rand.nextInt(7);
|
| 33 | }
|
| 34 |
|
| 35 | boolean flag = true;
|
| 36 |
|
| 37 | if (position.getY() >= 1 && position.getY() + i + 1 <= 256)
|
| 38 | {
|
| 39 | for (int j = position.getY(); j <= position.getY() + 1 + i; ++j)
|
| 40 | {
|
| 41 | int k = 1;
|
| 42 |
|
| 43 | if (j == position.getY())
|
| 44 | {
|
| 45 | k = 0;
|
| 46 | }
|
| 47 |
|
| 48 | if (j >= position.getY() + 1 + i - 2)
|
| 49 | {
|
| 50 | k = 2;
|
| 51 | }
|
| 52 |
|
| 53 | BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
|
| 54 |
|
| 55 | for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l)
|
| 56 | {
|
| 57 | for (int i1 = position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1)
|
| 58 | {
|
| 59 | if (j >= 0 && j < 256)
|
| 60 | {
|
| 61 | if (!this.func_150523_a(worldIn.getBlockState(blockpos$mutableblockpos.set(l, j, i1)).getBlock()))
|
| 62 | {
|
| 63 | flag = false;
|
| 64 | }
|
| 65 | }
|
| 66 | else
|
| 67 | {
|
| 68 | flag = false;
|
| 69 | }
|
| 70 | }
|
| 71 | }
|
| 72 | }
|
| 73 |
|
| 74 | if (!flag)
|
| 75 | {
|
| 76 | return false;
|
| 77 | }
|
| 78 | else
|
| 79 | {
|
| 80 | Block block1 = worldIn.getBlockState(position.down()).getBlock();
|
| 81 |
|
| 82 | if ((block1 == Blocks.grass || block1 == Blocks.dirt || block1 == Blocks.farmland) && position.getY() < 256 - i - 1)
|
| 83 | {
|
| 84 | this.func_175921_a(worldIn, position.down());
|
| 85 |
|
| 86 | for (int i2 = position.getY() - 3 + i; i2 <= position.getY() + i; ++i2)
|
| 87 | {
|
| 88 | int k2 = i2 - (position.getY() + i);
|
| 89 | int l2 = 1 - k2 / 2;
|
| 90 |
|
| 91 | for (int i3 = position.getX() - l2; i3 <= position.getX() + l2; ++i3)
|
| 92 | {
|
| 93 | int j1 = i3 - position.getX();
|
| 94 |
|
| 95 | for (int k1 = position.getZ() - l2; k1 <= position.getZ() + l2; ++k1)
|
| 96 | {
|
| 97 | int l1 = k1 - position.getZ();
|
| 98 |
|
| 99 | if (Math.abs(j1) != l2 || Math.abs(l1) != l2 || rand.nextInt(2) != 0 && k2 != 0)
|
| 100 | {
|
| 101 | BlockPos blockpos = new BlockPos(i3, i2, k1);
|
| 102 | Block block = worldIn.getBlockState(blockpos).getBlock();
|
| 103 |
|
| 104 | if (block.getMaterial() == Material.air || block.getMaterial() == Material.leaves)
|
| 105 | {
|
| 106 | this.setBlockAndNotifyAdequately(worldIn, blockpos, field_181630_b);
|
| 107 | }
|
| 108 | }
|
| 109 | }
|
| 110 | }
|
| 111 | }
|
| 112 |
|
| 113 | for (int j2 = 0; j2 < i; ++j2)
|
| 114 | {
|
| 115 | Block block2 = worldIn.getBlockState(position.up(j2)).getBlock();
|
| 116 |
|
| 117 | if (block2.getMaterial() == Material.air || block2.getMaterial() == Material.leaves)
|
| 118 | {
|
| 119 | this.setBlockAndNotifyAdequately(worldIn, position.up(j2), field_181629_a);
|
| 120 | }
|
| 121 | }
|
| 122 |
|
| 123 | return true;
|
| 124 | }
|
| 125 | else
|
| 126 | {
|
| 127 | return false;
|
| 128 | }
|
| 129 | }
|
| 130 | }
|
| 131 | else
|
| 132 | {
|
| 133 | return false;
|
| 134 | }
|
| 135 | }
|
| 136 | }
|
| 137 |
|