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

import java.util.Random;

import org.bukkit.craftbukkit.CraftBlockChangeDelegate; // CraftBukkit

public abstract class WorldGenMegaTreeAbstract extends WorldGenTreeAbstract {

    protected final int a;
    protected final int b;
    protected final int c;
    protected int d;

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

    protected int a(Random random) {
        int i = random.nextInt(3) + this.a;

        if (this.d > 1) {
            i += random.nextInt(this.d);
        }

        return i;
    }

    // CraftBukkit - Changed world to CraftBlockChangeDelegate
    private boolean b(CraftBlockChangeDelegate world, Random random, int i, int j, int k, int l) {
        boolean flag = true;

        if (j >= 1 && j + l + 1 <= 256) {
            for (int i1 = j; i1 <= j + 1 + l; ++i1) {
                byte b0 = 2;

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

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

                for (int j1 = i - b0; j1 <= i + b0 && flag; ++j1) {
                    for (int k1 = k - b0; k1 <= k + b0 && flag; ++k1) {
                        if (i1 >= 0 && i1 < 256) {
                            Block block = world.getType(j1, i1, k1);

                            // CraftBukkit - ignore our own saplings
                            if (block != Blocks.SAPLING && !this.a(block)) {
                                flag = false;
                            }
                        } else {
                            flag = false;
                        }
                    }
                }
            }

            return flag;
        } else {
            return false;
        }
    }

    // CraftBukkit - Change world to CraftBlockChangeDelegate
    private boolean c(CraftBlockChangeDelegate world, Random random, int i, int j, int k) {
        Block block = world.getType(i, j - 1, k);

        if ((block == Blocks.GRASS || block == Blocks.DIRT) && j >= 2) {
            world.setTypeAndData(i, j - 1, k, Blocks.DIRT, 0, 2);
            world.setTypeAndData(i + 1, j - 1, k, Blocks.DIRT, 0, 2);
            world.setTypeAndData(i, j - 1, k + 1, Blocks.DIRT, 0, 2);
            world.setTypeAndData(i + 1, j - 1, k + 1, Blocks.DIRT, 0, 2);
            return true;
        } else {
            return false;
        }
    }

    // CraftBukkit - Change world to CraftBlockChangeDelegate
    protected boolean a(CraftBlockChangeDelegate world, Random random, int i, int j, int k, int l) {
        return this.b(world, random, i, j, k, l) && this.c(world, random, i, j, k);
    }

    // CraftBukkit - Change world to CraftBlockChangeDelegate
    protected void a(CraftBlockChangeDelegate world, int i, int j, int k, int l, Random random) {
        int i1 = l * l;

        for (int j1 = i - l; j1 <= i + l + 1; ++j1) {
            int k1 = j1 - i;

            for (int l1 = k - l; l1 <= k + l + 1; ++l1) {
                int i2 = l1 - k;
                int j2 = k1 - 1;
                int k2 = i2 - 1;

                if (k1 * k1 + i2 * i2 <= i1 || j2 * j2 + k2 * k2 <= i1 || k1 * k1 + k2 * k2 <= i1 || j2 * j2 + i2 * i2 <= i1) {
                    Block block = world.getType(j1, j, l1);

                    if (block.getMaterial() == Material.AIR || block.getMaterial() == Material.LEAVES) {
                        this.setTypeAndData(world, j1, j, l1, Blocks.LEAVES, this.c);
                    }
                }
            }
        }
    }

    // CraftBukkit - Change world to CraftBlockChangeDelegate
    protected void b(CraftBlockChangeDelegate world, int i, int j, int k, int l, Random random) {
        int i1 = l * l;

        for (int j1 = i - l; j1 <= i + l; ++j1) {
            int k1 = j1 - i;

            for (int l1 = k - l; l1 <= k + l; ++l1) {
                int i2 = l1 - k;

                if (k1 * k1 + i2 * i2 <= i1) {
                    Block block = world.getType(j1, j, l1);

                    if (block.getMaterial() == Material.AIR || block.getMaterial() == Material.LEAVES) {
                        this.setTypeAndData(world, j1, j, l1, Blocks.LEAVES, this.c);
                    }
                }
            }
        }
    }
}