MapGenCaves .java

net.minecraft.world.gen.MapGenCaves (class): members: func_175793_a, func_180702_a, func_180703_a, recursiveGenerate. imports: BlockSand, Objects.

net.minecraft.world.genclass268 linescommonextends MapGenBase12.1 KB

API Surface (4)

void func_180703_a(long p_180703_1_, int p_180703_3_, int p_180703_4_, ChunkPrimer p_180703_5_, double p_180703_6_, double p_180703_8_, double p_180703_10_)
void func_180702_a(long p_180702_1_, int p_180702_3_, int p_180702_4_, ChunkPrimer p_180702_5_, double p_180702_6_, double p_180702_8_, double p_180702_10_, float p_180702_12_, float p_180702_13_, float p_180702_14_, int p_180702_15_, int p_180702_16_, double p_180702_17_)
boolean func_175793_a(IBlockState p_175793_1_, IBlockState p_175793_2_)
void recursiveGenerate(World worldIn, int chunkX, int chunkZ, int p_180701_4_, int p_180701_5_, ChunkPrimer chunkPrimerIn)

Full Source

MapGenCaves.java268 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.world.gen;
2
3
import com.google.common.base.Objects;
4
import java.util.Random;
5
import net.minecraft.block.BlockSand;
6
import net.minecraft.block.material.Material;
7
import net.minecraft.block.state.IBlockState;
8
import net.minecraft.init.Blocks;
9
import net.minecraft.util.BlockPos;
10
import net.minecraft.util.MathHelper;
11
import net.minecraft.world.World;
12
import net.minecraft.world.chunk.ChunkPrimer;
13
14
public class MapGenCaves extends MapGenBase
15
{
16
    protected void func_180703_a(long p_180703_1_, int p_180703_3_, int p_180703_4_, ChunkPrimer p_180703_5_, double p_180703_6_, double p_180703_8_, double p_180703_10_)
17
    {
18
        this.func_180702_a(p_180703_1_, p_180703_3_, p_180703_4_, p_180703_5_, p_180703_6_, p_180703_8_, p_180703_10_, 1.0F + this.rand.nextFloat() * 6.0F, 0.0F, 0.0F, -1, -1, 0.5D);
19
    }
20
21
    protected void func_180702_a(long p_180702_1_, int p_180702_3_, int p_180702_4_, ChunkPrimer p_180702_5_, double p_180702_6_, double p_180702_8_, double p_180702_10_, float p_180702_12_, float p_180702_13_, float p_180702_14_, int p_180702_15_, int p_180702_16_, double p_180702_17_)
22
    {
23
        double d0 = (double)(p_180702_3_ * 16 + 8);
24
        double d1 = (double)(p_180702_4_ * 16 + 8);
25
        float f = 0.0F;
26
        float f1 = 0.0F;
27
        Random random = new Random(p_180702_1_);
28
29
        if (p_180702_16_ <= 0)
30
        {
31
            int i = this.range * 16 - 16;
32
            p_180702_16_ = i - random.nextInt(i / 4);
33
        }
34
35
        boolean flag2 = false;
36
37
        if (p_180702_15_ == -1)
38
        {
39
            p_180702_15_ = p_180702_16_ / 2;
40
            flag2 = true;
41
        }
42
43
        int j = random.nextInt(p_180702_16_ / 2) + p_180702_16_ / 4;
44
45
        for (boolean flag = random.nextInt(6) == 0; p_180702_15_ < p_180702_16_; ++p_180702_15_)
46
        {
47
            double d2 = 1.5D + (double)(MathHelper.sin((float)p_180702_15_ * (float)Math.PI / (float)p_180702_16_) * p_180702_12_ * 1.0F);
48
            double d3 = d2 * p_180702_17_;
49
            float f2 = MathHelper.cos(p_180702_14_);
50
            float f3 = MathHelper.sin(p_180702_14_);
51
            p_180702_6_ += (double)(MathHelper.cos(p_180702_13_) * f2);
52
            p_180702_8_ += (double)f3;
53
            p_180702_10_ += (double)(MathHelper.sin(p_180702_13_) * f2);
54
55
            if (flag)
56
            {
57
                p_180702_14_ = p_180702_14_ * 0.92F;
58
            }
59
            else
60
            {
61
                p_180702_14_ = p_180702_14_ * 0.7F;
62
            }
63
64
            p_180702_14_ = p_180702_14_ + f1 * 0.1F;
65
            p_180702_13_ += f * 0.1F;
66
            f1 = f1 * 0.9F;
67
            f = f * 0.75F;
68
            f1 = f1 + (random.nextFloat() - random.nextFloat()) * random.nextFloat() * 2.0F;
69
            f = f + (random.nextFloat() - random.nextFloat()) * random.nextFloat() * 4.0F;
70
71
            if (!flag2 && p_180702_15_ == j && p_180702_12_ > 1.0F && p_180702_16_ > 0)
72
            {
73
                this.func_180702_a(random.nextLong(), p_180702_3_, p_180702_4_, p_180702_5_, p_180702_6_, p_180702_8_, p_180702_10_, random.nextFloat() * 0.5F + 0.5F, p_180702_13_ - ((float)Math.PI / 2F), p_180702_14_ / 3.0F, p_180702_15_, p_180702_16_, 1.0D);
74
                this.func_180702_a(random.nextLong(), p_180702_3_, p_180702_4_, p_180702_5_, p_180702_6_, p_180702_8_, p_180702_10_, random.nextFloat() * 0.5F + 0.5F, p_180702_13_ + ((float)Math.PI / 2F), p_180702_14_ / 3.0F, p_180702_15_, p_180702_16_, 1.0D);
75
                return;
76
            }
77
78
            if (flag2 || random.nextInt(4) != 0)
79
            {
80
                double d4 = p_180702_6_ - d0;
81
                double d5 = p_180702_10_ - d1;
82
                double d6 = (double)(p_180702_16_ - p_180702_15_);
83
                double d7 = (double)(p_180702_12_ + 2.0F + 16.0F);
84
85
                if (d4 * d4 + d5 * d5 - d6 * d6 > d7 * d7)
86
                {
87
                    return;
88
                }
89
90
                if (p_180702_6_ >= d0 - 16.0D - d2 * 2.0D && p_180702_10_ >= d1 - 16.0D - d2 * 2.0D && p_180702_6_ <= d0 + 16.0D + d2 * 2.0D && p_180702_10_ <= d1 + 16.0D + d2 * 2.0D)
91
                {
92
                    int k2 = MathHelper.floor_double(p_180702_6_ - d2) - p_180702_3_ * 16 - 1;
93
                    int k = MathHelper.floor_double(p_180702_6_ + d2) - p_180702_3_ * 16 + 1;
94
                    int l2 = MathHelper.floor_double(p_180702_8_ - d3) - 1;
95
                    int l = MathHelper.floor_double(p_180702_8_ + d3) + 1;
96
                    int i3 = MathHelper.floor_double(p_180702_10_ - d2) - p_180702_4_ * 16 - 1;
97
                    int i1 = MathHelper.floor_double(p_180702_10_ + d2) - p_180702_4_ * 16 + 1;
98
99
                    if (k2 < 0)
100
                    {
101
                        k2 = 0;
102
                    }
103
104
                    if (k > 16)
105
                    {
106
                        k = 16;
107
                    }
108
109
                    if (l2 < 1)
110
                    {
111
                        l2 = 1;
112
                    }
113
114
                    if (l > 248)
115
                    {
116
                        l = 248;
117
                    }
118
119
                    if (i3 < 0)
120
                    {
121
                        i3 = 0;
122
                    }
123
124
                    if (i1 > 16)
125
                    {
126
                        i1 = 16;
127
                    }
128
129
                    boolean flag3 = false;
130
131
                    for (int j1 = k2; !flag3 && j1 < k; ++j1)
132
                    {
133
                        for (int k1 = i3; !flag3 && k1 < i1; ++k1)
134
                        {
135
                            for (int l1 = l + 1; !flag3 && l1 >= l2 - 1; --l1)
136
                            {
137
                                if (l1 >= 0 && l1 < 256)
138
                                {
139
                                    IBlockState iblockstate = p_180702_5_.getBlockState(j1, l1, k1);
140
141
                                    if (iblockstate.getBlock() == Blocks.flowing_water || iblockstate.getBlock() == Blocks.water)
142
                                    {
143
                                        flag3 = true;
144
                                    }
145
146
                                    if (l1 != l2 - 1 && j1 != k2 && j1 != k - 1 && k1 != i3 && k1 != i1 - 1)
147
                                    {
148
                                        l1 = l2;
149
                                    }
150
                                }
151
                            }
152
                        }
153
                    }
154
155
                    if (!flag3)
156
                    {
157
                        BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
158
159
                        for (int j3 = k2; j3 < k; ++j3)
160
                        {
161
                            double d10 = ((double)(j3 + p_180702_3_ * 16) + 0.5D - p_180702_6_) / d2;
162
163
                            for (int i2 = i3; i2 < i1; ++i2)
164
                            {
165
                                double d8 = ((double)(i2 + p_180702_4_ * 16) + 0.5D - p_180702_10_) / d2;
166
                                boolean flag1 = false;
167
168
                                if (d10 * d10 + d8 * d8 < 1.0D)
169
                                {
170
                                    for (int j2 = l; j2 > l2; --j2)
171
                                    {
172
                                        double d9 = ((double)(j2 - 1) + 0.5D - p_180702_8_) / d3;
173
174
                                        if (d9 > -0.7D && d10 * d10 + d9 * d9 + d8 * d8 < 1.0D)
175
                                        {
176
                                            IBlockState iblockstate1 = p_180702_5_.getBlockState(j3, j2, i2);
177
                                            IBlockState iblockstate2 = (IBlockState)Objects.firstNonNull(p_180702_5_.getBlockState(j3, j2 + 1, i2), Blocks.air.getDefaultState());
178
179
                                            if (iblockstate1.getBlock() == Blocks.grass || iblockstate1.getBlock() == Blocks.mycelium)
180
                                            {
181
                                                flag1 = true;
182
                                            }
183
184
                                            if (this.func_175793_a(iblockstate1, iblockstate2))
185
                                            {
186
                                                if (j2 - 1 < 10)
187
                                                {
188
                                                    p_180702_5_.setBlockState(j3, j2, i2, Blocks.lava.getDefaultState());
189
                                                }
190
                                                else
191
                                                {
192
                                                    p_180702_5_.setBlockState(j3, j2, i2, Blocks.air.getDefaultState());
193
194
                                                    if (iblockstate2.getBlock() == Blocks.sand)
195
                                                    {
196
                                                        p_180702_5_.setBlockState(j3, j2 + 1, i2, iblockstate2.getValue(BlockSand.VARIANT) == BlockSand.EnumType.RED_SAND ? Blocks.red_sandstone.getDefaultState() : Blocks.sandstone.getDefaultState());
197
                                                    }
198
199
                                                    if (flag1 && p_180702_5_.getBlockState(j3, j2 - 1, i2).getBlock() == Blocks.dirt)
200
                                                    {
201
                                                        blockpos$mutableblockpos.set(j3 + p_180702_3_ * 16, 0, i2 + p_180702_4_ * 16);
202
                                                        p_180702_5_.setBlockState(j3, j2 - 1, i2, this.worldObj.getBiomeGenForCoords(blockpos$mutableblockpos).topBlock.getBlock().getDefaultState());
203
                                                    }
204
                                                }
205
                                            }
206
                                        }
207
                                    }
208
                                }
209
                            }
210
                        }
211
212
                        if (flag2)
213
                        {
214
                            break;
215
                        }
216
                    }
217
                }
218
            }
219
        }
220
    }
221
222
    protected boolean func_175793_a(IBlockState p_175793_1_, IBlockState p_175793_2_)
223
    {
224
        return p_175793_1_.getBlock() == Blocks.stone ? true : (p_175793_1_.getBlock() == Blocks.dirt ? true : (p_175793_1_.getBlock() == Blocks.grass ? true : (p_175793_1_.getBlock() == Blocks.hardened_clay ? true : (p_175793_1_.getBlock() == Blocks.stained_hardened_clay ? true : (p_175793_1_.getBlock() == Blocks.sandstone ? true : (p_175793_1_.getBlock() == Blocks.red_sandstone ? true : (p_175793_1_.getBlock() == Blocks.mycelium ? true : (p_175793_1_.getBlock() == Blocks.snow_layer ? true : (p_175793_1_.getBlock() == Blocks.sand || p_175793_1_.getBlock() == Blocks.gravel) && p_175793_2_.getBlock().getMaterial() != Material.water))))))));
225
    }
226
227
    /**
228
     * Recursively called by generate()
229
     */
230
    protected void recursiveGenerate(World worldIn, int chunkX, int chunkZ, int p_180701_4_, int p_180701_5_, ChunkPrimer chunkPrimerIn)
231
    {
232
        int i = this.rand.nextInt(this.rand.nextInt(this.rand.nextInt(15) + 1) + 1);
233
234
        if (this.rand.nextInt(7) != 0)
235
        {
236
            i = 0;
237
        }
238
239
        for (int j = 0; j < i; ++j)
240
        {
241
            double d0 = (double)(chunkX * 16 + this.rand.nextInt(16));
242
            double d1 = (double)this.rand.nextInt(this.rand.nextInt(120) + 8);
243
            double d2 = (double)(chunkZ * 16 + this.rand.nextInt(16));
244
            int k = 1;
245
246
            if (this.rand.nextInt(4) == 0)
247
            {
248
                this.func_180703_a(this.rand.nextLong(), p_180701_4_, p_180701_5_, chunkPrimerIn, d0, d1, d2);
249
                k += this.rand.nextInt(4);
250
            }
251
252
            for (int l = 0; l < k; ++l)
253
            {
254
                float f = this.rand.nextFloat() * (float)Math.PI * 2.0F;
255
                float f1 = (this.rand.nextFloat() - 0.5F) * 2.0F / 8.0F;
256
                float f2 = this.rand.nextFloat() * 2.0F + this.rand.nextFloat();
257
258
                if (this.rand.nextInt(10) == 0)
259
                {
260
                    f2 *= this.rand.nextFloat() * this.rand.nextFloat() * 3.0F + 1.0F;
261
                }
262
263
                this.func_180702_a(this.rand.nextLong(), p_180701_4_, p_180701_5_, chunkPrimerIn, d0, d1, d2, f2, f, f1, 0, 0, 1.0D);
264
            }
265
        }
266
    }
267
}
268

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