ChunkProviderFlat .java

net.minecraft.world.gen.ChunkProviderFlat (class): members: structureGenerators, waterLakeGenerator, lavaLakeGenerator, flatWorldGenInfo, cachedBlockIDs.

net.minecraft.world.genclass316 linescommon10.3 KB

Implements

API Surface (14)

Chunk provideChunk(int x, int z)
boolean chunkExists(int x, int z)
void populate(IChunkProvider chunkProvider, int x, int z)
boolean populateChunk(IChunkProvider chunkProvider, Chunk chunkIn, int x, int z)
boolean saveChunks(boolean saveAllChunks, IProgressUpdate progressCallback)
void saveExtraData()
boolean unloadQueuedChunks()
boolean canSave()
String makeString()
List<BiomeGenBase.SpawnListEntry> getPossibleCreatures(EnumCreatureType creatureType, BlockPos pos)
BlockPos getStrongholdGen(World worldIn, String structureName, BlockPos position)
int getLoadedChunkCount()
void recreateStructures(Chunk chunkIn, int x, int z)
Chunk provideChunk(BlockPos blockPosIn)

Fields & Constants (9)

worldObj
random
cachedBlockIDs
flatWorldGenInfo
structureGenerators
hasDecoration
hasDungeons
waterLakeGenerator
lavaLakeGenerator

String literals (12)

"village"
"size"
"biome_1"
"mineshaft"
"stronghold"
"oceanmonument"
"lake"
"lava_lake"
"dungeon"
"decoration"
"FlatLevelSource"
"Stronghold"

Full Source

ChunkProviderFlat.java316 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.world.gen;
2
3
import com.google.common.collect.Lists;
4
import java.util.List;
5
import java.util.Map;
6
import java.util.Random;
7
import net.minecraft.block.state.IBlockState;
8
import net.minecraft.entity.EnumCreatureType;
9
import net.minecraft.init.Blocks;
10
import net.minecraft.util.BlockPos;
11
import net.minecraft.util.IProgressUpdate;
12
import net.minecraft.world.ChunkCoordIntPair;
13
import net.minecraft.world.World;
14
import net.minecraft.world.biome.BiomeGenBase;
15
import net.minecraft.world.chunk.Chunk;
16
import net.minecraft.world.chunk.ChunkPrimer;
17
import net.minecraft.world.chunk.IChunkProvider;
18
import net.minecraft.world.gen.feature.WorldGenDungeons;
19
import net.minecraft.world.gen.feature.WorldGenLakes;
20
import net.minecraft.world.gen.structure.MapGenMineshaft;
21
import net.minecraft.world.gen.structure.MapGenScatteredFeature;
22
import net.minecraft.world.gen.structure.MapGenStronghold;
23
import net.minecraft.world.gen.structure.MapGenStructure;
24
import net.minecraft.world.gen.structure.MapGenVillage;
25
import net.minecraft.world.gen.structure.StructureOceanMonument;
26
27
public class ChunkProviderFlat implements IChunkProvider
28
{
29
    private World worldObj;
30
    private Random random;
31
    private final IBlockState[] cachedBlockIDs = new IBlockState[256];
32
    private final FlatGeneratorInfo flatWorldGenInfo;
33
    private final List<MapGenStructure> structureGenerators = Lists.<MapGenStructure>newArrayList();
34
    private final boolean hasDecoration;
35
    private final boolean hasDungeons;
36
    private WorldGenLakes waterLakeGenerator;
37
    private WorldGenLakes lavaLakeGenerator;
38
39
    public ChunkProviderFlat(World worldIn, long seed, boolean generateStructures, String flatGeneratorSettings)
40
    {
41
        this.worldObj = worldIn;
42
        this.random = new Random(seed);
43
        this.flatWorldGenInfo = FlatGeneratorInfo.createFlatGeneratorFromString(flatGeneratorSettings);
44
45
        if (generateStructures)
46
        {
47
            Map<String, Map<String, String>> map = this.flatWorldGenInfo.getWorldFeatures();
48
49
            if (map.containsKey("village"))
50
            {
51
                Map<String, String> map1 = (Map)map.get("village");
52
53
                if (!map1.containsKey("size"))
54
                {
55
                    map1.put("size", "1");
56
                }
57
58
                this.structureGenerators.add(new MapGenVillage(map1));
59
            }
60
61
            if (map.containsKey("biome_1"))
62
            {
63
                this.structureGenerators.add(new MapGenScatteredFeature((Map)map.get("biome_1")));
64
            }
65
66
            if (map.containsKey("mineshaft"))
67
            {
68
                this.structureGenerators.add(new MapGenMineshaft((Map)map.get("mineshaft")));
69
            }
70
71
            if (map.containsKey("stronghold"))
72
            {
73
                this.structureGenerators.add(new MapGenStronghold((Map)map.get("stronghold")));
74
            }
75
76
            if (map.containsKey("oceanmonument"))
77
            {
78
                this.structureGenerators.add(new StructureOceanMonument((Map)map.get("oceanmonument")));
79
            }
80
        }
81
82
        if (this.flatWorldGenInfo.getWorldFeatures().containsKey("lake"))
83
        {
84
            this.waterLakeGenerator = new WorldGenLakes(Blocks.water);
85
        }
86
87
        if (this.flatWorldGenInfo.getWorldFeatures().containsKey("lava_lake"))
88
        {
89
            this.lavaLakeGenerator = new WorldGenLakes(Blocks.lava);
90
        }
91
92
        this.hasDungeons = this.flatWorldGenInfo.getWorldFeatures().containsKey("dungeon");
93
        int j = 0;
94
        int k = 0;
95
        boolean flag = true;
96
97
        for (FlatLayerInfo flatlayerinfo : this.flatWorldGenInfo.getFlatLayers())
98
        {
99
            for (int i = flatlayerinfo.getMinY(); i < flatlayerinfo.getMinY() + flatlayerinfo.getLayerCount(); ++i)
100
            {
101
                IBlockState iblockstate = flatlayerinfo.getLayerMaterial();
102
103
                if (iblockstate.getBlock() != Blocks.air)
104
                {
105
                    flag = false;
106
                    this.cachedBlockIDs[i] = iblockstate;
107
                }
108
            }
109
110
            if (flatlayerinfo.getLayerMaterial().getBlock() == Blocks.air)
111
            {
112
                k += flatlayerinfo.getLayerCount();
113
            }
114
            else
115
            {
116
                j += flatlayerinfo.getLayerCount() + k;
117
                k = 0;
118
            }
119
        }
120
121
        worldIn.setSeaLevel(j);
122
        this.hasDecoration = flag ? false : this.flatWorldGenInfo.getWorldFeatures().containsKey("decoration");
123
    }
124
125
    /**
126
     * Will return back a chunk, if it doesn't exist and its not a MP client it will generates all the blocks for the
127
     * specified chunk from the map seed and chunk seed
128
     */
129
    public Chunk provideChunk(int x, int z)
130
    {
131
        ChunkPrimer chunkprimer = new ChunkPrimer();
132
133
        for (int i = 0; i < this.cachedBlockIDs.length; ++i)
134
        {
135
            IBlockState iblockstate = this.cachedBlockIDs[i];
136
137
            if (iblockstate != null)
138
            {
139
                for (int j = 0; j < 16; ++j)
140
                {
141
                    for (int k = 0; k < 16; ++k)
142
                    {
143
                        chunkprimer.setBlockState(j, i, k, iblockstate);
144
                    }
145
                }
146
            }
147
        }
148
149
        for (MapGenBase mapgenbase : this.structureGenerators)
150
        {
151
            mapgenbase.generate(this, this.worldObj, x, z, chunkprimer);
152
        }
153
154
        Chunk chunk = new Chunk(this.worldObj, chunkprimer, x, z);
155
        BiomeGenBase[] abiomegenbase = this.worldObj.getWorldChunkManager().loadBlockGeneratorData((BiomeGenBase[])null, x * 16, z * 16, 16, 16);
156
        byte[] abyte = chunk.getBiomeArray();
157
158
        for (int l = 0; l < abyte.length; ++l)
159
        {
160
            abyte[l] = (byte)abiomegenbase[l].biomeID;
161
        }
162
163
        chunk.generateSkylightMap();
164
        return chunk;
165
    }
166
167
    /**
168
     * Checks to see if a chunk exists at x, z
169
     */
170
    public boolean chunkExists(int x, int z)
171
    {
172
        return true;
173
    }
174
175
    /**
176
     * Populates chunk with ores etc etc
177
     */
178
    public void populate(IChunkProvider chunkProvider, int x, int z)
179
    {
180
        int i = x * 16;
181
        int j = z * 16;
182
        BlockPos blockpos = new BlockPos(i, 0, j);
183
        BiomeGenBase biomegenbase = this.worldObj.getBiomeGenForCoords(new BlockPos(i + 16, 0, j + 16));
184
        boolean flag = false;
185
        this.random.setSeed(this.worldObj.getSeed());
186
        long k = this.random.nextLong() / 2L * 2L + 1L;
187
        long l = this.random.nextLong() / 2L * 2L + 1L;
188
        this.random.setSeed((long)x * k + (long)z * l ^ this.worldObj.getSeed());
189
        ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(x, z);
190
191
        for (MapGenStructure mapgenstructure : this.structureGenerators)
192
        {
193
            boolean flag1 = mapgenstructure.generateStructure(this.worldObj, this.random, chunkcoordintpair);
194
195
            if (mapgenstructure instanceof MapGenVillage)
196
            {
197
                flag |= flag1;
198
            }
199
        }
200
201
        if (this.waterLakeGenerator != null && !flag && this.random.nextInt(4) == 0)
202
        {
203
            this.waterLakeGenerator.generate(this.worldObj, this.random, blockpos.add(this.random.nextInt(16) + 8, this.random.nextInt(256), this.random.nextInt(16) + 8));
204
        }
205
206
        if (this.lavaLakeGenerator != null && !flag && this.random.nextInt(8) == 0)
207
        {
208
            BlockPos blockpos1 = blockpos.add(this.random.nextInt(16) + 8, this.random.nextInt(this.random.nextInt(248) + 8), this.random.nextInt(16) + 8);
209
210
            if (blockpos1.getY() < this.worldObj.getSeaLevel() || this.random.nextInt(10) == 0)
211
            {
212
                this.lavaLakeGenerator.generate(this.worldObj, this.random, blockpos1);
213
            }
214
        }
215
216
        if (this.hasDungeons)
217
        {
218
            for (int i1 = 0; i1 < 8; ++i1)
219
            {
220
                (new WorldGenDungeons()).generate(this.worldObj, this.random, blockpos.add(this.random.nextInt(16) + 8, this.random.nextInt(256), this.random.nextInt(16) + 8));
221
            }
222
        }
223
224
        if (this.hasDecoration)
225
        {
226
            biomegenbase.decorate(this.worldObj, this.random, blockpos);
227
        }
228
    }
229
230
    public boolean populateChunk(IChunkProvider chunkProvider, Chunk chunkIn, int x, int z)
231
    {
232
        return false;
233
    }
234
235
    /**
236
     * Two modes of operation: if passed true, save all Chunks in one go.  If passed false, save up to two chunks.
237
     * Return true if all chunks have been saved.
238
     */
239
    public boolean saveChunks(boolean saveAllChunks, IProgressUpdate progressCallback)
240
    {
241
        return true;
242
    }
243
244
    /**
245
     * Save extra data not associated with any Chunk.  Not saved during autosave, only during world unload.  Currently
246
     * unimplemented.
247
     */
248
    public void saveExtraData()
249
    {
250
    }
251
252
    /**
253
     * Unloads chunks that are marked to be unloaded. This is not guaranteed to unload every such chunk.
254
     */
255
    public boolean unloadQueuedChunks()
256
    {
257
        return false;
258
    }
259
260
    /**
261
     * Returns if the IChunkProvider supports saving.
262
     */
263
    public boolean canSave()
264
    {
265
        return true;
266
    }
267
268
    /**
269
     * Converts the instance data to a readable string.
270
     */
271
    public String makeString()
272
    {
273
        return "FlatLevelSource";
274
    }
275
276
    public List<BiomeGenBase.SpawnListEntry> getPossibleCreatures(EnumCreatureType creatureType, BlockPos pos)
277
    {
278
        BiomeGenBase biomegenbase = this.worldObj.getBiomeGenForCoords(pos);
279
        return biomegenbase.getSpawnableList(creatureType);
280
    }
281
282
    public BlockPos getStrongholdGen(World worldIn, String structureName, BlockPos position)
283
    {
284
        if ("Stronghold".equals(structureName))
285
        {
286
            for (MapGenStructure mapgenstructure : this.structureGenerators)
287
            {
288
                if (mapgenstructure instanceof MapGenStronghold)
289
                {
290
                    return mapgenstructure.getClosestStrongholdPos(worldIn, position);
291
                }
292
            }
293
        }
294
295
        return null;
296
    }
297
298
    public int getLoadedChunkCount()
299
    {
300
        return 0;
301
    }
302
303
    public void recreateStructures(Chunk chunkIn, int x, int z)
304
    {
305
        for (MapGenStructure mapgenstructure : this.structureGenerators)
306
        {
307
            mapgenstructure.generate(this, this.worldObj, x, z, (ChunkPrimer)null);
308
        }
309
    }
310
311
    public Chunk provideChunk(BlockPos blockPosIn)
312
    {
313
        return this.provideChunk(blockPosIn.getX() >> 4, blockPosIn.getZ() >> 4);
314
    }
315
}
316

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