| 1 | package net.minecraft.world.gen.feature;
|
| 2 |
|
| 3 | import java.util.Random;
|
| 4 | import net.minecraft.block.Block;
|
| 5 | import net.minecraft.block.BlockLeaves;
|
| 6 | import net.minecraft.block.BlockNewLeaf;
|
| 7 | import net.minecraft.block.BlockNewLog;
|
| 8 | import net.minecraft.block.BlockPlanks;
|
| 9 | import net.minecraft.block.material.Material;
|
| 10 | import net.minecraft.block.state.IBlockState;
|
| 11 | import net.minecraft.init.Blocks;
|
| 12 | import net.minecraft.util.BlockPos;
|
| 13 | import net.minecraft.util.EnumFacing;
|
| 14 | import net.minecraft.world.World;
|
| 15 |
|
| 16 | public class WorldGenSavannaTree extends WorldGenAbstractTree
|
| 17 | {
|
| 18 | private static final IBlockState field_181643_a = Blocks.log2.getDefaultState().withProperty(BlockNewLog.VARIANT, BlockPlanks.EnumType.ACACIA);
|
| 19 | private static final IBlockState field_181644_b = Blocks.leaves2.getDefaultState().withProperty(BlockNewLeaf.VARIANT, BlockPlanks.EnumType.ACACIA).withProperty(BlockLeaves.CHECK_DECAY, Boolean.valueOf(false));
|
| 20 |
|
| 21 | public WorldGenSavannaTree(boolean p_i45463_1_)
|
| 22 | {
|
| 23 | super(p_i45463_1_);
|
| 24 | }
|
| 25 |
|
| 26 | public boolean generate(World worldIn, Random rand, BlockPos position)
|
| 27 | {
|
| 28 | int i = rand.nextInt(3) + rand.nextInt(3) + 5;
|
| 29 | boolean flag = true;
|
| 30 |
|
| 31 | if (position.getY() >= 1 && position.getY() + i + 1 <= 256)
|
| 32 | {
|
| 33 | for (int j = position.getY(); j <= position.getY() + 1 + i; ++j)
|
| 34 | {
|
| 35 | int k = 1;
|
| 36 |
|
| 37 | if (j == position.getY())
|
| 38 | {
|
| 39 | k = 0;
|
| 40 | }
|
| 41 |
|
| 42 | if (j >= position.getY() + 1 + i - 2)
|
| 43 | {
|
| 44 | k = 2;
|
| 45 | }
|
| 46 |
|
| 47 | BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
|
| 48 |
|
| 49 | for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l)
|
| 50 | {
|
| 51 | for (int i1 = position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1)
|
| 52 | {
|
| 53 | if (j >= 0 && j < 256)
|
| 54 | {
|
| 55 | if (!this.func_150523_a(worldIn.getBlockState(blockpos$mutableblockpos.set(l, j, i1)).getBlock()))
|
| 56 | {
|
| 57 | flag = false;
|
| 58 | }
|
| 59 | }
|
| 60 | else
|
| 61 | {
|
| 62 | flag = false;
|
| 63 | }
|
| 64 | }
|
| 65 | }
|
| 66 | }
|
| 67 |
|
| 68 | if (!flag)
|
| 69 | {
|
| 70 | return false;
|
| 71 | }
|
| 72 | else
|
| 73 | {
|
| 74 | Block block = worldIn.getBlockState(position.down()).getBlock();
|
| 75 |
|
| 76 | if ((block == Blocks.grass || block == Blocks.dirt) && position.getY() < 256 - i - 1)
|
| 77 | {
|
| 78 | this.func_175921_a(worldIn, position.down());
|
| 79 | EnumFacing enumfacing = EnumFacing.Plane.HORIZONTAL.random(rand);
|
| 80 | int k2 = i - rand.nextInt(4) - 1;
|
| 81 | int l2 = 3 - rand.nextInt(3);
|
| 82 | int i3 = position.getX();
|
| 83 | int j1 = position.getZ();
|
| 84 | int k1 = 0;
|
| 85 |
|
| 86 | for (int l1 = 0; l1 < i; ++l1)
|
| 87 | {
|
| 88 | int i2 = position.getY() + l1;
|
| 89 |
|
| 90 | if (l1 >= k2 && l2 > 0)
|
| 91 | {
|
| 92 | i3 += enumfacing.getFrontOffsetX();
|
| 93 | j1 += enumfacing.getFrontOffsetZ();
|
| 94 | --l2;
|
| 95 | }
|
| 96 |
|
| 97 | BlockPos blockpos = new BlockPos(i3, i2, j1);
|
| 98 | Material material = worldIn.getBlockState(blockpos).getBlock().getMaterial();
|
| 99 |
|
| 100 | if (material == Material.air || material == Material.leaves)
|
| 101 | {
|
| 102 | this.func_181642_b(worldIn, blockpos);
|
| 103 | k1 = i2;
|
| 104 | }
|
| 105 | }
|
| 106 |
|
| 107 | BlockPos blockpos2 = new BlockPos(i3, k1, j1);
|
| 108 |
|
| 109 | for (int j3 = -3; j3 <= 3; ++j3)
|
| 110 | {
|
| 111 | for (int i4 = -3; i4 <= 3; ++i4)
|
| 112 | {
|
| 113 | if (Math.abs(j3) != 3 || Math.abs(i4) != 3)
|
| 114 | {
|
| 115 | this.func_175924_b(worldIn, blockpos2.add(j3, 0, i4));
|
| 116 | }
|
| 117 | }
|
| 118 | }
|
| 119 |
|
| 120 | blockpos2 = blockpos2.up();
|
| 121 |
|
| 122 | for (int k3 = -1; k3 <= 1; ++k3)
|
| 123 | {
|
| 124 | for (int j4 = -1; j4 <= 1; ++j4)
|
| 125 | {
|
| 126 | this.func_175924_b(worldIn, blockpos2.add(k3, 0, j4));
|
| 127 | }
|
| 128 | }
|
| 129 |
|
| 130 | this.func_175924_b(worldIn, blockpos2.east(2));
|
| 131 | this.func_175924_b(worldIn, blockpos2.west(2));
|
| 132 | this.func_175924_b(worldIn, blockpos2.south(2));
|
| 133 | this.func_175924_b(worldIn, blockpos2.north(2));
|
| 134 | i3 = position.getX();
|
| 135 | j1 = position.getZ();
|
| 136 | EnumFacing enumfacing1 = EnumFacing.Plane.HORIZONTAL.random(rand);
|
| 137 |
|
| 138 | if (enumfacing1 != enumfacing)
|
| 139 | {
|
| 140 | int l3 = k2 - rand.nextInt(2) - 1;
|
| 141 | int k4 = 1 + rand.nextInt(3);
|
| 142 | k1 = 0;
|
| 143 |
|
| 144 | for (int l4 = l3; l4 < i && k4 > 0; --k4)
|
| 145 | {
|
| 146 | if (l4 >= 1)
|
| 147 | {
|
| 148 | int j2 = position.getY() + l4;
|
| 149 | i3 += enumfacing1.getFrontOffsetX();
|
| 150 | j1 += enumfacing1.getFrontOffsetZ();
|
| 151 | BlockPos blockpos1 = new BlockPos(i3, j2, j1);
|
| 152 | Material material1 = worldIn.getBlockState(blockpos1).getBlock().getMaterial();
|
| 153 |
|
| 154 | if (material1 == Material.air || material1 == Material.leaves)
|
| 155 | {
|
| 156 | this.func_181642_b(worldIn, blockpos1);
|
| 157 | k1 = j2;
|
| 158 | }
|
| 159 | }
|
| 160 |
|
| 161 | ++l4;
|
| 162 | }
|
| 163 |
|
| 164 | if (k1 > 0)
|
| 165 | {
|
| 166 | BlockPos blockpos3 = new BlockPos(i3, k1, j1);
|
| 167 |
|
| 168 | for (int i5 = -2; i5 <= 2; ++i5)
|
| 169 | {
|
| 170 | for (int k5 = -2; k5 <= 2; ++k5)
|
| 171 | {
|
| 172 | if (Math.abs(i5) != 2 || Math.abs(k5) != 2)
|
| 173 | {
|
| 174 | this.func_175924_b(worldIn, blockpos3.add(i5, 0, k5));
|
| 175 | }
|
| 176 | }
|
| 177 | }
|
| 178 |
|
| 179 | blockpos3 = blockpos3.up();
|
| 180 |
|
| 181 | for (int j5 = -1; j5 <= 1; ++j5)
|
| 182 | {
|
| 183 | for (int l5 = -1; l5 <= 1; ++l5)
|
| 184 | {
|
| 185 | this.func_175924_b(worldIn, blockpos3.add(j5, 0, l5));
|
| 186 | }
|
| 187 | }
|
| 188 | }
|
| 189 | }
|
| 190 |
|
| 191 | return true;
|
| 192 | }
|
| 193 | else
|
| 194 | {
|
| 195 | return false;
|
| 196 | }
|
| 197 | }
|
| 198 | }
|
| 199 | else
|
| 200 | {
|
| 201 | return false;
|
| 202 | }
|
| 203 | }
|
| 204 |
|
| 205 | private void func_181642_b(World p_181642_1_, BlockPos p_181642_2_)
|
| 206 | {
|
| 207 | this.setBlockAndNotifyAdequately(p_181642_1_, p_181642_2_, field_181643_a);
|
| 208 | }
|
| 209 |
|
| 210 | private void func_175924_b(World worldIn, BlockPos p_175924_2_)
|
| 211 | {
|
| 212 | Material material = worldIn.getBlockState(p_175924_2_).getBlock().getMaterial();
|
| 213 |
|
| 214 | if (material == Material.air || material == Material.leaves)
|
| 215 | {
|
| 216 | this.setBlockAndNotifyAdequately(worldIn, p_175924_2_, field_181644_b);
|
| 217 | }
|
| 218 | }
|
| 219 | }
|
| 220 |
|