WorldChunkManager .java

net.minecraft.world.biome.WorldChunkManager (class): members: getTemperatureAtHeight, getBiomesToSpawnIn, biomeIndexLayer, biomesToSpawnIn, biomeCache.

net.minecraft.world.biomeclass280 linescommon9.7 KB

API Surface (11)

List<BiomeGenBase> getBiomesToSpawnIn()
BiomeGenBase getBiomeGenerator(BlockPos pos)
BiomeGenBase getBiomeGenerator(BlockPos pos, BiomeGenBase biomeGenBaseIn)
float[] getRainfall(float[] listToReuse, int x, int z, int width, int length)
float getTemperatureAtHeight(float p_76939_1_, int p_76939_2_)
BiomeGenBase[] getBiomesForGeneration(BiomeGenBase[] biomes, int x, int z, int width, int height)
BiomeGenBase[] loadBlockGeneratorData(BiomeGenBase[] oldBiomeList, int x, int z, int width, int depth)
BiomeGenBase[] getBiomeGenAt(BiomeGenBase[] listToReuse, int x, int z, int width, int length, boolean cacheFlag)
boolean areBiomesViable(int p_76940_1_, int p_76940_2_, int p_76940_3_, List<BiomeGenBase> p_76940_4_)
BlockPos findBiomePosition(int x, int z, int range, List<BiomeGenBase> biomes, Random random)
void cleanupCache()

Fields & Constants (5)

genBiomes
biomeIndexLayer
biomeCache
biomesToSpawnIn
generatorOptions

String literals (9)

"Invalid Biome id"
"DownfallBlock"
"biome id"
"downfalls[] size"
"RawBiomeBlock"
"biomes[] size"
"Layer"
"radius"
"allowed"

Full Source

WorldChunkManager.java280 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.world.biome;
2
3
import com.google.common.collect.Lists;
4
import java.util.List;
5
import java.util.Random;
6
import net.minecraft.crash.CrashReport;
7
import net.minecraft.crash.CrashReportCategory;
8
import net.minecraft.util.BlockPos;
9
import net.minecraft.util.ReportedException;
10
import net.minecraft.world.World;
11
import net.minecraft.world.WorldType;
12
import net.minecraft.world.gen.layer.GenLayer;
13
import net.minecraft.world.gen.layer.IntCache;
14
15
public class WorldChunkManager
16
{
17
    private GenLayer genBiomes;
18
19
    /** A GenLayer containing the indices into BiomeGenBase.biomeList[] */
20
    private GenLayer biomeIndexLayer;
21
22
    /** The biome list. */
23
    private BiomeCache biomeCache;
24
    private List<BiomeGenBase> biomesToSpawnIn;
25
    private String generatorOptions;
26
27
    protected WorldChunkManager()
28
    {
29
        this.biomeCache = new BiomeCache(this);
30
        this.generatorOptions = "";
31
        this.biomesToSpawnIn = Lists.<BiomeGenBase>newArrayList();
32
        this.biomesToSpawnIn.add(BiomeGenBase.forest);
33
        this.biomesToSpawnIn.add(BiomeGenBase.plains);
34
        this.biomesToSpawnIn.add(BiomeGenBase.taiga);
35
        this.biomesToSpawnIn.add(BiomeGenBase.taigaHills);
36
        this.biomesToSpawnIn.add(BiomeGenBase.forestHills);
37
        this.biomesToSpawnIn.add(BiomeGenBase.jungle);
38
        this.biomesToSpawnIn.add(BiomeGenBase.jungleHills);
39
    }
40
41
    public WorldChunkManager(long seed, WorldType worldTypeIn, String options)
42
    {
43
        this();
44
        this.generatorOptions = options;
45
        GenLayer[] agenlayer = GenLayer.initializeAllBiomeGenerators(seed, worldTypeIn, options);
46
        this.genBiomes = agenlayer[0];
47
        this.biomeIndexLayer = agenlayer[1];
48
    }
49
50
    public WorldChunkManager(World worldIn)
51
    {
52
        this(worldIn.getSeed(), worldIn.getWorldInfo().getTerrainType(), worldIn.getWorldInfo().getGeneratorOptions());
53
    }
54
55
    public List<BiomeGenBase> getBiomesToSpawnIn()
56
    {
57
        return this.biomesToSpawnIn;
58
    }
59
60
    /**
61
     * Returns the biome generator
62
     */
63
    public BiomeGenBase getBiomeGenerator(BlockPos pos)
64
    {
65
        return this.getBiomeGenerator(pos, (BiomeGenBase)null);
66
    }
67
68
    public BiomeGenBase getBiomeGenerator(BlockPos pos, BiomeGenBase biomeGenBaseIn)
69
    {
70
        return this.biomeCache.func_180284_a(pos.getX(), pos.getZ(), biomeGenBaseIn);
71
    }
72
73
    /**
74
     * Returns a list of rainfall values for the specified blocks. Args: listToReuse, x, z, width, length.
75
     */
76
    public float[] getRainfall(float[] listToReuse, int x, int z, int width, int length)
77
    {
78
        IntCache.resetIntCache();
79
80
        if (listToReuse == null || listToReuse.length < width * length)
81
        {
82
            listToReuse = new float[width * length];
83
        }
84
85
        int[] aint = this.biomeIndexLayer.getInts(x, z, width, length);
86
87
        for (int i = 0; i < width * length; ++i)
88
        {
89
            try
90
            {
91
                float f = (float)BiomeGenBase.getBiomeFromBiomeList(aint[i], BiomeGenBase.field_180279_ad).getIntRainfall() / 65536.0F;
92
93
                if (f > 1.0F)
94
                {
95
                    f = 1.0F;
96
                }
97
98
                listToReuse[i] = f;
99
            }
100
            catch (Throwable throwable)
101
            {
102
                CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Invalid Biome id");
103
                CrashReportCategory crashreportcategory = crashreport.makeCategory("DownfallBlock");
104
                crashreportcategory.addCrashSection("biome id", Integer.valueOf(i));
105
                crashreportcategory.addCrashSection("downfalls[] size", Integer.valueOf(listToReuse.length));
106
                crashreportcategory.addCrashSection("x", Integer.valueOf(x));
107
                crashreportcategory.addCrashSection("z", Integer.valueOf(z));
108
                crashreportcategory.addCrashSection("w", Integer.valueOf(width));
109
                crashreportcategory.addCrashSection("h", Integer.valueOf(length));
110
                throw new ReportedException(crashreport);
111
            }
112
        }
113
114
        return listToReuse;
115
    }
116
117
    /**
118
     * Return an adjusted version of a given temperature based on the y height
119
     */
120
    public float getTemperatureAtHeight(float p_76939_1_, int p_76939_2_)
121
    {
122
        return p_76939_1_;
123
    }
124
125
    /**
126
     * Returns an array of biomes for the location input.
127
     */
128
    public BiomeGenBase[] getBiomesForGeneration(BiomeGenBase[] biomes, int x, int z, int width, int height)
129
    {
130
        IntCache.resetIntCache();
131
132
        if (biomes == null || biomes.length < width * height)
133
        {
134
            biomes = new BiomeGenBase[width * height];
135
        }
136
137
        int[] aint = this.genBiomes.getInts(x, z, width, height);
138
139
        try
140
        {
141
            for (int i = 0; i < width * height; ++i)
142
            {
143
                biomes[i] = BiomeGenBase.getBiomeFromBiomeList(aint[i], BiomeGenBase.field_180279_ad);
144
            }
145
146
            return biomes;
147
        }
148
        catch (Throwable throwable)
149
        {
150
            CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Invalid Biome id");
151
            CrashReportCategory crashreportcategory = crashreport.makeCategory("RawBiomeBlock");
152
            crashreportcategory.addCrashSection("biomes[] size", Integer.valueOf(biomes.length));
153
            crashreportcategory.addCrashSection("x", Integer.valueOf(x));
154
            crashreportcategory.addCrashSection("z", Integer.valueOf(z));
155
            crashreportcategory.addCrashSection("w", Integer.valueOf(width));
156
            crashreportcategory.addCrashSection("h", Integer.valueOf(height));
157
            throw new ReportedException(crashreport);
158
        }
159
    }
160
161
    /**
162
     * Returns biomes to use for the blocks and loads the other data like temperature and humidity onto the
163
     * WorldChunkManager Args: oldBiomeList, x, z, width, depth
164
     */
165
    public BiomeGenBase[] loadBlockGeneratorData(BiomeGenBase[] oldBiomeList, int x, int z, int width, int depth)
166
    {
167
        return this.getBiomeGenAt(oldBiomeList, x, z, width, depth, true);
168
    }
169
170
    /**
171
     * Return a list of biomes for the specified blocks. Args: listToReuse, x, y, width, length, cacheFlag (if false,
172
     * don't check biomeCache to avoid infinite loop in BiomeCacheBlock)
173
     */
174
    public BiomeGenBase[] getBiomeGenAt(BiomeGenBase[] listToReuse, int x, int z, int width, int length, boolean cacheFlag)
175
    {
176
        IntCache.resetIntCache();
177
178
        if (listToReuse == null || listToReuse.length < width * length)
179
        {
180
            listToReuse = new BiomeGenBase[width * length];
181
        }
182
183
        if (cacheFlag && width == 16 && length == 16 && (x & 15) == 0 && (z & 15) == 0)
184
        {
185
            BiomeGenBase[] abiomegenbase = this.biomeCache.getCachedBiomes(x, z);
186
            System.arraycopy(abiomegenbase, 0, listToReuse, 0, width * length);
187
            return listToReuse;
188
        }
189
        else
190
        {
191
            int[] aint = this.biomeIndexLayer.getInts(x, z, width, length);
192
193
            for (int i = 0; i < width * length; ++i)
194
            {
195
                listToReuse[i] = BiomeGenBase.getBiomeFromBiomeList(aint[i], BiomeGenBase.field_180279_ad);
196
            }
197
198
            return listToReuse;
199
        }
200
    }
201
202
    /**
203
     * checks given Chunk's Biomes against List of allowed ones
204
     */
205
    public boolean areBiomesViable(int p_76940_1_, int p_76940_2_, int p_76940_3_, List<BiomeGenBase> p_76940_4_)
206
    {
207
        IntCache.resetIntCache();
208
        int i = p_76940_1_ - p_76940_3_ >> 2;
209
        int j = p_76940_2_ - p_76940_3_ >> 2;
210
        int k = p_76940_1_ + p_76940_3_ >> 2;
211
        int l = p_76940_2_ + p_76940_3_ >> 2;
212
        int i1 = k - i + 1;
213
        int j1 = l - j + 1;
214
        int[] aint = this.genBiomes.getInts(i, j, i1, j1);
215
216
        try
217
        {
218
            for (int k1 = 0; k1 < i1 * j1; ++k1)
219
            {
220
                BiomeGenBase biomegenbase = BiomeGenBase.getBiome(aint[k1]);
221
222
                if (!p_76940_4_.contains(biomegenbase))
223
                {
224
                    return false;
225
                }
226
            }
227
228
            return true;
229
        }
230
        catch (Throwable throwable)
231
        {
232
            CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Invalid Biome id");
233
            CrashReportCategory crashreportcategory = crashreport.makeCategory("Layer");
234
            crashreportcategory.addCrashSection("Layer", this.genBiomes.toString());
235
            crashreportcategory.addCrashSection("x", Integer.valueOf(p_76940_1_));
236
            crashreportcategory.addCrashSection("z", Integer.valueOf(p_76940_2_));
237
            crashreportcategory.addCrashSection("radius", Integer.valueOf(p_76940_3_));
238
            crashreportcategory.addCrashSection("allowed", p_76940_4_);
239
            throw new ReportedException(crashreport);
240
        }
241
    }
242
243
    public BlockPos findBiomePosition(int x, int z, int range, List<BiomeGenBase> biomes, Random random)
244
    {
245
        IntCache.resetIntCache();
246
        int i = x - range >> 2;
247
        int j = z - range >> 2;
248
        int k = x + range >> 2;
249
        int l = z + range >> 2;
250
        int i1 = k - i + 1;
251
        int j1 = l - j + 1;
252
        int[] aint = this.genBiomes.getInts(i, j, i1, j1);
253
        BlockPos blockpos = null;
254
        int k1 = 0;
255
256
        for (int l1 = 0; l1 < i1 * j1; ++l1)
257
        {
258
            int i2 = i + l1 % i1 << 2;
259
            int j2 = j + l1 / i1 << 2;
260
            BiomeGenBase biomegenbase = BiomeGenBase.getBiome(aint[l1]);
261
262
            if (biomes.contains(biomegenbase) && (blockpos == null || random.nextInt(k1 + 1) == 0))
263
            {
264
                blockpos = new BlockPos(i2, 0, j2);
265
                ++k1;
266
            }
267
        }
268
269
        return blockpos;
270
    }
271
272
    /**
273
     * Calls the WorldChunkManager's biomeCache.cleanupCache()
274
     */
275
    public void cleanupCache()
276
    {
277
        this.biomeCache.cleanupCache();
278
    }
279
}
280

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