WorldGenCanopyTree .java

net.minecraft.world.gen.feature.WorldGenCanopyTree (class): members: field_181640_a, field_181641_b, generate. imports: BlockNewLeaf, BlockNewLog, Block.

net.minecraft.world.gen.featureclass220 linescommonextends WorldGenAbstractTree8.1 KB

API Surface (1)

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

Fields & Constants (2)

field_181640_a
field_181641_b

Full Source

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

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