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

import java.util.Random;

import org.bukkit.BlockChangeDelegate; // CraftBukkit

public class WorldGenTaiga1 extends WorldGenerator {

    public WorldGenTaiga1() {}

    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(5) + 7;
        int i1 = l - random.nextInt(2) - 3;
        int j1 = l - i1;
        int k1 = 1 + random.nextInt(j1 + 1);
        boolean flag = true;

        if (j >= 1 && j + l + 1 <= world.getHeight()) { // CraftBukkit
            int l1;
            int i2;
            int j2;
            int k2;
            int l2;

            for (l1 = j; l1 <= j + 1 + l && flag; ++l1) {
                boolean flag1 = true;

                if (l1 - j < i1) {
                    l2 = 0;
                } else {
                    l2 = k1;
                }

                for (i2 = i - l2; i2 <= i + l2 && flag; ++i2) {
                    for (j2 = k - l2; j2 <= k + l2 && flag; ++j2) {
                        if (l1 >= 0 && l1 < world.getHeight()) { // CraftBukkit
                            k2 = world.getTypeId(i2, l1, j2);
                            if (k2 != 0 && k2 != Block.LEAVES.id) {
                                flag = false;
                            }
                        } else {
                            flag = false;
                        }
                    }
                }
            }

            if (!flag) {
                return false;
            } else {
                l1 = world.getTypeId(i, j - 1, k);
                if ((l1 == Block.GRASS.id || l1 == Block.DIRT.id) && j < world.getHeight() - l - 1) { // CraftBukkit
                    world.setRawTypeId(i, j - 1, k, Block.DIRT.id);
                    l2 = 0;

                    for (i2 = j + l; i2 >= j + i1; --i2) {
                        for (j2 = i - l2; j2 <= i + l2; ++j2) {
                            k2 = j2 - i;

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

                                if ((Math.abs(k2) != l2 || Math.abs(j3) != l2 || l2 <= 0) && !Block.o[world.getTypeId(j2, i2, i3)]) {
                                    world.setRawTypeIdAndData(j2, i2, i3, Block.LEAVES.id, 1);
                                }
                            }
                        }

                        if (l2 >= 1 && i2 == j + i1 + 1) {
                            --l2;
                        } else if (l2 < k1) {
                            ++l2;
                        }
                    }

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

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