summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/WorldGenMegaTree.java
blob: 736e63b3acec885e6a12e2930f72ac13ed76f533 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package net.minecraft.server;

import java.util.Random;

import org.bukkit.BlockChangeDelegate; // CraftBukkit

public class WorldGenMegaTree extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit add interface

    private final int a;
    private final int b;
    private final int c;

    public WorldGenMegaTree(boolean flag, int i, int j, int k) {
        super(flag);
        this.a = i;
        this.b = j;
        this.c = k;
    }

    public boolean a(World world, Random random, int i, int j, int k) {
        // CraftBukkit start
        return this.generate((BlockChangeDelegate) world, random, i, j, k);
    }

    public boolean generate(BlockChangeDelegate world, Random random, int i, int j, int k) {
        // CraftBukkit end
        int l = random.nextInt(3) + this.a;
        boolean flag = true;

        if (j >= 1 && j + l + 1 <= 256) {
            int i1;
            int j1;
            int k1;
            int l1;

            for (i1 = j; i1 <= j + 1 + l; ++i1) {
                byte b0 = 2;

                if (i1 == j) {
                    b0 = 1;
                }

                if (i1 >= j + 1 + l - 2) {
                    b0 = 2;
                }

                for (j1 = i - b0; j1 <= i + b0 && flag; ++j1) {
                    for (k1 = k - b0; k1 <= k + b0 && flag; ++k1) {
                        if (i1 >= 0 && i1 < 256) {
                            l1 = world.getTypeId(j1, i1, k1);
                            if (l1 != 0 && l1 != Block.LEAVES.id && l1 != Block.GRASS.id && l1 != Block.DIRT.id && l1 != Block.LOG.id && l1 != Block.SAPLING.id) {
                                flag = false;
                            }
                        } else {
                            flag = false;
                        }
                    }
                }
            }

            if (!flag) {
                return false;
            } else {
                i1 = world.getTypeId(i, j - 1, k);
                if ((i1 == Block.GRASS.id || i1 == Block.DIRT.id) && j < 256 - l - 1) {
                    world.setRawTypeId(i, j - 1, k, Block.DIRT.id);
                    world.setRawTypeId(i + 1, j - 1, k, Block.DIRT.id);
                    world.setRawTypeId(i, j - 1, k + 1, Block.DIRT.id);
                    world.setRawTypeId(i + 1, j - 1, k + 1, Block.DIRT.id);
                    this.a(world, i, k, j + l, 2, random);

                    for (int i2 = j + l - 2 - random.nextInt(4); i2 > j + l / 2; i2 -= 2 + random.nextInt(4)) {
                        float f = random.nextFloat() * 3.1415927F * 2.0F;

                        k1 = i + (int) (0.5F + MathHelper.cos(f) * 4.0F);
                        l1 = k + (int) (0.5F + MathHelper.sin(f) * 4.0F);
                        this.a(world, k1, l1, i2, 0, random);

                        for (int j2 = 0; j2 < 5; ++j2) {
                            k1 = i + (int) (1.5F + MathHelper.cos(f) * (float) j2);
                            l1 = k + (int) (1.5F + MathHelper.sin(f) * (float) j2);
                            this.setTypeAndData(world, k1, i2 - 3 + j2 / 2, l1, Block.LOG.id, this.b);
                        }
                    }

                    for (j1 = 0; j1 < l; ++j1) {
                        k1 = world.getTypeId(i, j + j1, k);
                        if (k1 == 0 || k1 == Block.LEAVES.id) {
                            this.setTypeAndData(world, i, j + j1, k, Block.LOG.id, this.b);
                            if (j1 > 0) {
                                if (random.nextInt(3) > 0 && world.isEmpty(i - 1, j + j1, k)) {
                                    this.setTypeAndData(world, i - 1, j + j1, k, Block.VINE.id, 8);
                                }

                                if (random.nextInt(3) > 0 && world.isEmpty(i, j + j1, k - 1)) {
                                    this.setTypeAndData(world, i, j + j1, k - 1, Block.VINE.id, 1);
                                }
                            }
                        }

                        if (j1 < l - 1) {
                            k1 = world.getTypeId(i + 1, j + j1, k);
                            if (k1 == 0 || k1 == Block.LEAVES.id) {
                                this.setTypeAndData(world, i + 1, j + j1, k, Block.LOG.id, this.b);
                                if (j1 > 0) {
                                    if (random.nextInt(3) > 0 && world.isEmpty(i + 2, j + j1, k)) {
                                        this.setTypeAndData(world, i + 2, j + j1, k, Block.VINE.id, 2);
                                    }

                                    if (random.nextInt(3) > 0 && world.isEmpty(i + 1, j + j1, k - 1)) {
                                        this.setTypeAndData(world, i + 1, j + j1, k - 1, Block.VINE.id, 1);
                                    }
                                }
                            }

                            k1 = world.getTypeId(i + 1, j + j1, k + 1);
                            if (k1 == 0 || k1 == Block.LEAVES.id) {
                                this.setTypeAndData(world, i + 1, j + j1, k + 1, Block.LOG.id, this.b);
                                if (j1 > 0) {
                                    if (random.nextInt(3) > 0 && world.isEmpty(i + 2, j + j1, k + 1)) {
                                        this.setTypeAndData(world, i + 2, j + j1, k + 1, Block.VINE.id, 2);
                                    }

                                    if (random.nextInt(3) > 0 && world.isEmpty(i + 1, j + j1, k + 2)) {
                                        this.setTypeAndData(world, i + 1, j + j1, k + 2, Block.VINE.id, 4);
                                    }
                                }
                            }

                            k1 = world.getTypeId(i, j + j1, k + 1);
                            if (k1 == 0 || k1 == Block.LEAVES.id) {
                                this.setTypeAndData(world, i, j + j1, k + 1, Block.LOG.id, this.b);
                                if (j1 > 0) {
                                    if (random.nextInt(3) > 0 && world.isEmpty(i - 1, j + j1, k + 1)) {
                                        this.setTypeAndData(world, i - 1, j + j1, k + 1, Block.VINE.id, 8);
                                    }

                                    if (random.nextInt(3) > 0 && world.isEmpty(i, j + j1, k + 2)) {
                                        this.setTypeAndData(world, i, j + j1, k + 2, Block.VINE.id, 4);
                                    }
                                }
                            }
                        }
                    }

                    return true;
                } else {
                    return false;
                }
            }
        } else {
            return false;
        }
    }

    // CraftBukkit - Changed signature
    private void a(BlockChangeDelegate world, int i, int j, int k, int l, Random random) {
        byte b0 = 2;

        for (int i1 = k - b0; i1 <= k; ++i1) {
            int j1 = i1 - k;
            int k1 = l + 1 - j1;

            for (int l1 = i - k1; l1 <= i + k1 + 1; ++l1) {
                int i2 = l1 - i;

                for (int j2 = j - k1; j2 <= j + k1 + 1; ++j2) {
                    int k2 = j2 - j;

                    if ((i2 >= 0 || k2 >= 0 || i2 * i2 + k2 * k2 <= k1 * k1) && (i2 <= 0 && k2 <= 0 || i2 * i2 + k2 * k2 <= (k1 + 1) * (k1 + 1)) && (random.nextInt(4) != 0 || i2 * i2 + k2 * k2 <= (k1 - 1) * (k1 - 1)) && !Block.n[world.getTypeId(l1, i1, j2)]) {
                        this.setTypeAndData(world, l1, i1, j2, Block.LEAVES.id, this.c);
                    }
                }
            }
        }
    }
}