WorldGenLakes .java

net.minecraft.world.gen.feature.WorldGenLakes (class, 174 lines): members: block, generate. imports: EnumSkyBlock, BiomeGenBase, Block, Material.

net.minecraft.world.gen.featureclass174 linescommonextends WorldGenerator6.8 KB

API Surface (1)

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

Fields & Constants (1)

block

Code Graph: Dependencies (8)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

WorldGenLakes.java174 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.material.Material;
6
import net.minecraft.init.Blocks;
7
import net.minecraft.util.BlockPos;
8
import net.minecraft.world.EnumSkyBlock;
9
import net.minecraft.world.World;
10
import net.minecraft.world.biome.BiomeGenBase;
11
12
public class WorldGenLakes extends WorldGenerator
13
{
14
    private Block block;
15
16
    public WorldGenLakes(Block blockIn)
17
    {
18
        this.block = blockIn;
19
    }
20
21
    public boolean generate(World worldIn, Random rand, BlockPos position)
22
    {
23
        for (position = position.add(-8, 0, -8); position.getY() > 5 && worldIn.isAirBlock(position); position = position.down())
24
        {
25
            ;
26
        }
27
28
        if (position.getY() <= 4)
29
        {
30
            return false;
31
        }
32
        else
33
        {
34
            position = position.down(4);
35
            boolean[] aboolean = new boolean[2048];
36
            int i = rand.nextInt(4) + 4;
37
38
            for (int j = 0; j < i; ++j)
39
            {
40
                double d0 = rand.nextDouble() * 6.0D + 3.0D;
41
                double d1 = rand.nextDouble() * 4.0D + 2.0D;
42
                double d2 = rand.nextDouble() * 6.0D + 3.0D;
43
                double d3 = rand.nextDouble() * (16.0D - d0 - 2.0D) + 1.0D + d0 / 2.0D;
44
                double d4 = rand.nextDouble() * (8.0D - d1 - 4.0D) + 2.0D + d1 / 2.0D;
45
                double d5 = rand.nextDouble() * (16.0D - d2 - 2.0D) + 1.0D + d2 / 2.0D;
46
47
                for (int l = 1; l < 15; ++l)
48
                {
49
                    for (int i1 = 1; i1 < 15; ++i1)
50
                    {
51
                        for (int j1 = 1; j1 < 7; ++j1)
52
                        {
53
                            double d6 = ((double)l - d3) / (d0 / 2.0D);
54
                            double d7 = ((double)j1 - d4) / (d1 / 2.0D);
55
                            double d8 = ((double)i1 - d5) / (d2 / 2.0D);
56
                            double d9 = d6 * d6 + d7 * d7 + d8 * d8;
57
58
                            if (d9 < 1.0D)
59
                            {
60
                                aboolean[(l * 16 + i1) * 8 + j1] = true;
61
                            }
62
                        }
63
                    }
64
                }
65
            }
66
67
            for (int k1 = 0; k1 < 16; ++k1)
68
            {
69
                for (int l2 = 0; l2 < 16; ++l2)
70
                {
71
                    for (int k = 0; k < 8; ++k)
72
                    {
73
                        boolean flag = !aboolean[(k1 * 16 + l2) * 8 + k] && (k1 < 15 && aboolean[((k1 + 1) * 16 + l2) * 8 + k] || k1 > 0 && aboolean[((k1 - 1) * 16 + l2) * 8 + k] || l2 < 15 && aboolean[(k1 * 16 + l2 + 1) * 8 + k] || l2 > 0 && aboolean[(k1 * 16 + (l2 - 1)) * 8 + k] || k < 7 && aboolean[(k1 * 16 + l2) * 8 + k + 1] || k > 0 && aboolean[(k1 * 16 + l2) * 8 + (k - 1)]);
74
75
                        if (flag)
76
                        {
77
                            Material material = worldIn.getBlockState(position.add(k1, k, l2)).getBlock().getMaterial();
78
79
                            if (k >= 4 && material.isLiquid())
80
                            {
81
                                return false;
82
                            }
83
84
                            if (k < 4 && !material.isSolid() && worldIn.getBlockState(position.add(k1, k, l2)).getBlock() != this.block)
85
                            {
86
                                return false;
87
                            }
88
                        }
89
                    }
90
                }
91
            }
92
93
            for (int l1 = 0; l1 < 16; ++l1)
94
            {
95
                for (int i3 = 0; i3 < 16; ++i3)
96
                {
97
                    for (int i4 = 0; i4 < 8; ++i4)
98
                    {
99
                        if (aboolean[(l1 * 16 + i3) * 8 + i4])
100
                        {
101
                            worldIn.setBlockState(position.add(l1, i4, i3), i4 >= 4 ? Blocks.air.getDefaultState() : this.block.getDefaultState(), 2);
102
                        }
103
                    }
104
                }
105
            }
106
107
            for (int i2 = 0; i2 < 16; ++i2)
108
            {
109
                for (int j3 = 0; j3 < 16; ++j3)
110
                {
111
                    for (int j4 = 4; j4 < 8; ++j4)
112
                    {
113
                        if (aboolean[(i2 * 16 + j3) * 8 + j4])
114
                        {
115
                            BlockPos blockpos = position.add(i2, j4 - 1, j3);
116
117
                            if (worldIn.getBlockState(blockpos).getBlock() == Blocks.dirt && worldIn.getLightFor(EnumSkyBlock.SKY, position.add(i2, j4, j3)) > 0)
118
                            {
119
                                BiomeGenBase biomegenbase = worldIn.getBiomeGenForCoords(blockpos);
120
121
                                if (biomegenbase.topBlock.getBlock() == Blocks.mycelium)
122
                                {
123
                                    worldIn.setBlockState(blockpos, Blocks.mycelium.getDefaultState(), 2);
124
                                }
125
                                else
126
                                {
127
                                    worldIn.setBlockState(blockpos, Blocks.grass.getDefaultState(), 2);
128
                                }
129
                            }
130
                        }
131
                    }
132
                }
133
            }
134
135
            if (this.block.getMaterial() == Material.lava)
136
            {
137
                for (int j2 = 0; j2 < 16; ++j2)
138
                {
139
                    for (int k3 = 0; k3 < 16; ++k3)
140
                    {
141
                        for (int k4 = 0; k4 < 8; ++k4)
142
                        {
143
                            boolean flag1 = !aboolean[(j2 * 16 + k3) * 8 + k4] && (j2 < 15 && aboolean[((j2 + 1) * 16 + k3) * 8 + k4] || j2 > 0 && aboolean[((j2 - 1) * 16 + k3) * 8 + k4] || k3 < 15 && aboolean[(j2 * 16 + k3 + 1) * 8 + k4] || k3 > 0 && aboolean[(j2 * 16 + (k3 - 1)) * 8 + k4] || k4 < 7 && aboolean[(j2 * 16 + k3) * 8 + k4 + 1] || k4 > 0 && aboolean[(j2 * 16 + k3) * 8 + (k4 - 1)]);
144
145
                            if (flag1 && (k4 < 4 || rand.nextInt(2) != 0) && worldIn.getBlockState(position.add(j2, k4, k3)).getBlock().getMaterial().isSolid())
146
                            {
147
                                worldIn.setBlockState(position.add(j2, k4, k3), Blocks.stone.getDefaultState(), 2);
148
                            }
149
                        }
150
                    }
151
                }
152
            }
153
154
            if (this.block.getMaterial() == Material.water)
155
            {
156
                for (int k2 = 0; k2 < 16; ++k2)
157
                {
158
                    for (int l3 = 0; l3 < 16; ++l3)
159
                    {
160
                        int l4 = 4;
161
162
                        if (worldIn.canBlockFreezeWater(position.add(k2, l4, l3)))
163
                        {
164
                            worldIn.setBlockState(position.add(k2, l4, l3), Blocks.ice.getDefaultState(), 2);
165
                        }
166
                    }
167
                }
168
            }
169
170
            return true;
171
        }
172
    }
173
}
174

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