summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/WorldGenTrees.java
blob: 021560fc33bfbbf75a8ec9379fb5e3b639ef3893 (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
package net.minecraft.server;

import java.util.Random;

import org.bukkit.BlockChangeDelegate; // CraftBukkit

public class WorldGenTrees extends WorldGenerator {

    public WorldGenTrees() {}

    public boolean a(World world, Random random, int i, int j, int k) {
        // CraftBukkit start
        // sk: The idea is to have (our) WorldServer implement
        // BlockChangeDelegate and then we can implicitly cast World to
        // WorldServer (a safe cast, AFAIK) and no code will be broken. This
        // then allows plugins to catch manually-invoked generation events
        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) + 4;
        boolean flag = true;

        if (j >= 1) {
            int k1000 = j + l + 1;

            world.getClass();
            if (k1000 <= 128) {
                int j1;
                int k1;
                int l1;
                int i2;

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

                    if (j1 == j) {
                        b0 = 0;
                    }

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

                    for (k1 = i - b0; k1 <= i + b0 && flag; ++k1) {
                        for (l1 = k - b0; l1 <= k + b0 && flag; ++l1) {
                            if (j1 >= 0) {
                                world.getClass();
                                if (j1 < 128) {
                                    i2 = world.getTypeId(k1, j1, l1);
                                    if (i2 != 0 && i2 != Block.LEAVES.id) {
                                        flag = false;
                                    }
                                    continue;
                                }
                            }

                            flag = false;
                        }
                    }
                }

                if (!flag) {
                    return false;
                }

                j1 = world.getTypeId(i, j - 1, k);
                if (j1 == Block.GRASS.id || j1 == Block.DIRT.id) {
                    world.getClass();
                    if (j < 128 - l - 1) {
                        world.setRawTypeId(i, j - 1, k, Block.DIRT.id);

                        int j2;

                        for (j2 = j - 3 + l; j2 <= j + l; ++j2) {
                            k1 = j2 - (j + l);
                            l1 = 1 - k1 / 2;

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

                                for (int l2 = k - l1; l2 <= k + l1; ++l2) {
                                    int i3 = l2 - k;

                                    if ((Math.abs(k2) != l1 || Math.abs(i3) != l1 || random.nextInt(2) != 0 && k1 != 0) && !Block.o[world.getTypeId(i2, j2, l2)]) {
                                        world.setRawTypeId(i2, j2, l2, Block.LEAVES.id);
                                    }
                                }
                            }
                        }

                        for (j2 = 0; j2 < l; ++j2) {
                            k1 = world.getTypeId(i, j + j2, k);
                            if (k1 == 0 || k1 == Block.LEAVES.id) {
                                world.setRawTypeId(i, j + j2, k, Block.LOG.id);
                            }
                        }

                        return true;
                    }
                }

                return false;
            }
        }

        return false;
    }
}