WorldGenTrees .java

net.minecraft.world.gen.feature.WorldGenTrees (class): members: field_181653_a, field_181654_b, minTreeHeight, metaLeaves, vinesGrow, metaWood, generate.

net.minecraft.world.gen.featureclass263 linescommonextends WorldGenAbstractTree11.5 KB

API Surface (1)

boolean generate(World worldIn, Random rand, BlockPos position)

Fields & Constants (6)

field_181653_a
field_181654_b
minTreeHeight
vinesGrow
metaWood
metaLeaves

Full Source

WorldGenTrees.java263 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.world.gen.feature;
2
3
import java.util.Random;
4
import net.minecraft.block.Block;
5
import net.minecraft.block.BlockCocoa;
6
import net.minecraft.block.BlockLeaves;
7
import net.minecraft.block.BlockOldLeaf;
8
import net.minecraft.block.BlockOldLog;
9
import net.minecraft.block.BlockPlanks;
10
import net.minecraft.block.BlockVine;
11
import net.minecraft.block.material.Material;
12
import net.minecraft.block.properties.PropertyBool;
13
import net.minecraft.block.state.IBlockState;
14
import net.minecraft.init.Blocks;
15
import net.minecraft.util.BlockPos;
16
import net.minecraft.util.EnumFacing;
17
import net.minecraft.world.World;
18
19
public class WorldGenTrees extends WorldGenAbstractTree
20
{
21
    private static final IBlockState field_181653_a = Blocks.log.getDefaultState().withProperty(BlockOldLog.VARIANT, BlockPlanks.EnumType.OAK);
22
    private static final IBlockState field_181654_b = Blocks.leaves.getDefaultState().withProperty(BlockOldLeaf.VARIANT, BlockPlanks.EnumType.OAK).withProperty(BlockLeaves.CHECK_DECAY, Boolean.valueOf(false));
23
24
    /** The minimum height of a generated tree. */
25
    private final int minTreeHeight;
26
27
    /** True if this tree should grow Vines. */
28
    private final boolean vinesGrow;
29
30
    /** The metadata value of the wood to use in tree generation. */
31
    private final IBlockState metaWood;
32
33
    /** The metadata value of the leaves to use in tree generation. */
34
    private final IBlockState metaLeaves;
35
36
    public WorldGenTrees(boolean p_i2027_1_)
37
    {
38
        this(p_i2027_1_, 4, field_181653_a, field_181654_b, false);
39
    }
40
41
    public WorldGenTrees(boolean p_i46446_1_, int p_i46446_2_, IBlockState p_i46446_3_, IBlockState p_i46446_4_, boolean p_i46446_5_)
42
    {
43
        super(p_i46446_1_);
44
        this.minTreeHeight = p_i46446_2_;
45
        this.metaWood = p_i46446_3_;
46
        this.metaLeaves = p_i46446_4_;
47
        this.vinesGrow = p_i46446_5_;
48
    }
49
50
    public boolean generate(World worldIn, Random rand, BlockPos position)
51
    {
52
        int i = rand.nextInt(3) + this.minTreeHeight;
53
        boolean flag = true;
54
55
        if (position.getY() >= 1 && position.getY() + i + 1 <= 256)
56
        {
57
            for (int j = position.getY(); j <= position.getY() + 1 + i; ++j)
58
            {
59
                int k = 1;
60
61
                if (j == position.getY())
62
                {
63
                    k = 0;
64
                }
65
66
                if (j >= position.getY() + 1 + i - 2)
67
                {
68
                    k = 2;
69
                }
70
71
                BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
72
73
                for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l)
74
                {
75
                    for (int i1 = position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1)
76
                    {
77
                        if (j >= 0 && j < 256)
78
                        {
79
                            if (!this.func_150523_a(worldIn.getBlockState(blockpos$mutableblockpos.set(l, j, i1)).getBlock()))
80
                            {
81
                                flag = false;
82
                            }
83
                        }
84
                        else
85
                        {
86
                            flag = false;
87
                        }
88
                    }
89
                }
90
            }
91
92
            if (!flag)
93
            {
94
                return false;
95
            }
96
            else
97
            {
98
                Block block1 = worldIn.getBlockState(position.down()).getBlock();
99
100
                if ((block1 == Blocks.grass || block1 == Blocks.dirt || block1 == Blocks.farmland) && position.getY() < 256 - i - 1)
101
                {
102
                    this.func_175921_a(worldIn, position.down());
103
                    int k2 = 3;
104
                    int l2 = 0;
105
106
                    for (int i3 = position.getY() - k2 + i; i3 <= position.getY() + i; ++i3)
107
                    {
108
                        int i4 = i3 - (position.getY() + i);
109
                        int j1 = l2 + 1 - i4 / 2;
110
111
                        for (int k1 = position.getX() - j1; k1 <= position.getX() + j1; ++k1)
112
                        {
113
                            int l1 = k1 - position.getX();
114
115
                            for (int i2 = position.getZ() - j1; i2 <= position.getZ() + j1; ++i2)
116
                            {
117
                                int j2 = i2 - position.getZ();
118
119
                                if (Math.abs(l1) != j1 || Math.abs(j2) != j1 || rand.nextInt(2) != 0 && i4 != 0)
120
                                {
121
                                    BlockPos blockpos = new BlockPos(k1, i3, i2);
122
                                    Block block = worldIn.getBlockState(blockpos).getBlock();
123
124
                                    if (block.getMaterial() == Material.air || block.getMaterial() == Material.leaves || block.getMaterial() == Material.vine)
125
                                    {
126
                                        this.setBlockAndNotifyAdequately(worldIn, blockpos, this.metaLeaves);
127
                                    }
128
                                }
129
                            }
130
                        }
131
                    }
132
133
                    for (int j3 = 0; j3 < i; ++j3)
134
                    {
135
                        Block block2 = worldIn.getBlockState(position.up(j3)).getBlock();
136
137
                        if (block2.getMaterial() == Material.air || block2.getMaterial() == Material.leaves || block2.getMaterial() == Material.vine)
138
                        {
139
                            this.setBlockAndNotifyAdequately(worldIn, position.up(j3), this.metaWood);
140
141
                            if (this.vinesGrow && j3 > 0)
142
                            {
143
                                if (rand.nextInt(3) > 0 && worldIn.isAirBlock(position.add(-1, j3, 0)))
144
                                {
145
                                    this.func_181651_a(worldIn, position.add(-1, j3, 0), BlockVine.EAST);
146
                                }
147
148
                                if (rand.nextInt(3) > 0 && worldIn.isAirBlock(position.add(1, j3, 0)))
149
                                {
150
                                    this.func_181651_a(worldIn, position.add(1, j3, 0), BlockVine.WEST);
151
                                }
152
153
                                if (rand.nextInt(3) > 0 && worldIn.isAirBlock(position.add(0, j3, -1)))
154
                                {
155
                                    this.func_181651_a(worldIn, position.add(0, j3, -1), BlockVine.SOUTH);
156
                                }
157
158
                                if (rand.nextInt(3) > 0 && worldIn.isAirBlock(position.add(0, j3, 1)))
159
                                {
160
                                    this.func_181651_a(worldIn, position.add(0, j3, 1), BlockVine.NORTH);
161
                                }
162
                            }
163
                        }
164
                    }
165
166
                    if (this.vinesGrow)
167
                    {
168
                        for (int k3 = position.getY() - 3 + i; k3 <= position.getY() + i; ++k3)
169
                        {
170
                            int j4 = k3 - (position.getY() + i);
171
                            int k4 = 2 - j4 / 2;
172
                            BlockPos.MutableBlockPos blockpos$mutableblockpos1 = new BlockPos.MutableBlockPos();
173
174
                            for (int l4 = position.getX() - k4; l4 <= position.getX() + k4; ++l4)
175
                            {
176
                                for (int i5 = position.getZ() - k4; i5 <= position.getZ() + k4; ++i5)
177
                                {
178
                                    blockpos$mutableblockpos1.set(l4, k3, i5);
179
180
                                    if (worldIn.getBlockState(blockpos$mutableblockpos1).getBlock().getMaterial() == Material.leaves)
181
                                    {
182
                                        BlockPos blockpos2 = blockpos$mutableblockpos1.west();
183
                                        BlockPos blockpos3 = blockpos$mutableblockpos1.east();
184
                                        BlockPos blockpos4 = blockpos$mutableblockpos1.north();
185
                                        BlockPos blockpos1 = blockpos$mutableblockpos1.south();
186
187
                                        if (rand.nextInt(4) == 0 && worldIn.getBlockState(blockpos2).getBlock().getMaterial() == Material.air)
188
                                        {
189
                                            this.func_181650_b(worldIn, blockpos2, BlockVine.EAST);
190
                                        }
191
192
                                        if (rand.nextInt(4) == 0 && worldIn.getBlockState(blockpos3).getBlock().getMaterial() == Material.air)
193
                                        {
194
                                            this.func_181650_b(worldIn, blockpos3, BlockVine.WEST);
195
                                        }
196
197
                                        if (rand.nextInt(4) == 0 && worldIn.getBlockState(blockpos4).getBlock().getMaterial() == Material.air)
198
                                        {
199
                                            this.func_181650_b(worldIn, blockpos4, BlockVine.SOUTH);
200
                                        }
201
202
                                        if (rand.nextInt(4) == 0 && worldIn.getBlockState(blockpos1).getBlock().getMaterial() == Material.air)
203
                                        {
204
                                            this.func_181650_b(worldIn, blockpos1, BlockVine.NORTH);
205
                                        }
206
                                    }
207
                                }
208
                            }
209
                        }
210
211
                        if (rand.nextInt(5) == 0 && i > 5)
212
                        {
213
                            for (int l3 = 0; l3 < 2; ++l3)
214
                            {
215
                                for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
216
                                {
217
                                    if (rand.nextInt(4 - l3) == 0)
218
                                    {
219
                                        EnumFacing enumfacing1 = enumfacing.getOpposite();
220
                                        this.func_181652_a(worldIn, rand.nextInt(3), position.add(enumfacing1.getFrontOffsetX(), i - 5 + l3, enumfacing1.getFrontOffsetZ()), enumfacing);
221
                                    }
222
                                }
223
                            }
224
                        }
225
                    }
226
227
                    return true;
228
                }
229
                else
230
                {
231
                    return false;
232
                }
233
            }
234
        }
235
        else
236
        {
237
            return false;
238
        }
239
    }
240
241
    private void func_181652_a(World p_181652_1_, int p_181652_2_, BlockPos p_181652_3_, EnumFacing p_181652_4_)
242
    {
243
        this.setBlockAndNotifyAdequately(p_181652_1_, p_181652_3_, Blocks.cocoa.getDefaultState().withProperty(BlockCocoa.AGE, Integer.valueOf(p_181652_2_)).withProperty(BlockCocoa.FACING, p_181652_4_));
244
    }
245
246
    private void func_181651_a(World p_181651_1_, BlockPos p_181651_2_, PropertyBool p_181651_3_)
247
    {
248
        this.setBlockAndNotifyAdequately(p_181651_1_, p_181651_2_, Blocks.vine.getDefaultState().withProperty(p_181651_3_, Boolean.valueOf(true)));
249
    }
250
251
    private void func_181650_b(World p_181650_1_, BlockPos p_181650_2_, PropertyBool p_181650_3_)
252
    {
253
        this.func_181651_a(p_181650_1_, p_181650_2_, p_181650_3_);
254
        int i = 4;
255
256
        for (p_181650_2_ = p_181650_2_.down(); p_181650_1_.getBlockState(p_181650_2_).getBlock().getMaterial() == Material.air && i > 0; --i)
257
        {
258
            this.func_181651_a(p_181650_1_, p_181650_2_, p_181650_3_);
259
            p_181650_2_ = p_181650_2_.down();
260
        }
261
    }
262
}
263

Deobfuscated MCP 1.8.9 source of WorldGenTrees from Marcelektro/MavenMCP-1.8.9 (net/minecraft/world/gen/feature/WorldGenTrees.java), stored verbatim.