BiomeCache .java

net.minecraft.world.biome.BiomeCache (class): members: getBiomeCacheBlock, getCachedBiomes, lastCleanupTime, func_180284_a, chunkManager, cacheMap, Block.

net.minecraft.world.biomeclass107 linescommon3.4 KB

API Surface (5)

BiomeCache.Block getBiomeCacheBlock(int x, int z)
BiomeGenBase func_180284_a(int x, int z, BiomeGenBase p_180284_3_)
void cleanupCache()
BiomeGenBase[] getCachedBiomes(int x, int z)
BiomeGenBase getBiomeGenAt(int x, int z)

Fields & Constants (4)

chunkManager
lastCleanupTime
cacheMap
cache

Code Graph: Dependencies (4)

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

Full Source

BiomeCache.java107 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 net.minecraft.server.MinecraftServer;
6
import net.minecraft.util.LongHashMap;
7
8
public class BiomeCache
9
{
10
    /** Reference to the WorldChunkManager */
11
    private final WorldChunkManager chunkManager;
12
13
    /** The last time this BiomeCache was cleaned, in milliseconds. */
14
    private long lastCleanupTime;
15
    private LongHashMap<BiomeCache.Block> cacheMap = new LongHashMap();
16
    private List<BiomeCache.Block> cache = Lists.<BiomeCache.Block>newArrayList();
17
18
    public BiomeCache(WorldChunkManager chunkManagerIn)
19
    {
20
        this.chunkManager = chunkManagerIn;
21
    }
22
23
    /**
24
     * Returns a biome cache block at location specified.
25
     */
26
    public BiomeCache.Block getBiomeCacheBlock(int x, int z)
27
    {
28
        x = x >> 4;
29
        z = z >> 4;
30
        long i = (long)x & 4294967295L | ((long)z & 4294967295L) << 32;
31
        BiomeCache.Block biomecache$block = (BiomeCache.Block)this.cacheMap.getValueByKey(i);
32
33
        if (biomecache$block == null)
34
        {
35
            biomecache$block = new BiomeCache.Block(x, z);
36
            this.cacheMap.add(i, biomecache$block);
37
            this.cache.add(biomecache$block);
38
        }
39
40
        biomecache$block.lastAccessTime = MinecraftServer.getCurrentTimeMillis();
41
        return biomecache$block;
42
    }
43
44
    public BiomeGenBase func_180284_a(int x, int z, BiomeGenBase p_180284_3_)
45
    {
46
        BiomeGenBase biomegenbase = this.getBiomeCacheBlock(x, z).getBiomeGenAt(x, z);
47
        return biomegenbase == null ? p_180284_3_ : biomegenbase;
48
    }
49
50
    /**
51
     * Removes BiomeCacheBlocks from this cache that haven't been accessed in at least 30 seconds.
52
     */
53
    public void cleanupCache()
54
    {
55
        long i = MinecraftServer.getCurrentTimeMillis();
56
        long j = i - this.lastCleanupTime;
57
58
        if (j > 7500L || j < 0L)
59
        {
60
            this.lastCleanupTime = i;
61
62
            for (int k = 0; k < this.cache.size(); ++k)
63
            {
64
                BiomeCache.Block biomecache$block = (BiomeCache.Block)this.cache.get(k);
65
                long l = i - biomecache$block.lastAccessTime;
66
67
                if (l > 30000L || l < 0L)
68
                {
69
                    this.cache.remove(k--);
70
                    long i1 = (long)biomecache$block.xPosition & 4294967295L | ((long)biomecache$block.zPosition & 4294967295L) << 32;
71
                    this.cacheMap.remove(i1);
72
                }
73
            }
74
        }
75
    }
76
77
    /**
78
     * Returns the array of cached biome types in the BiomeCacheBlock at the given location.
79
     */
80
    public BiomeGenBase[] getCachedBiomes(int x, int z)
81
    {
82
        return this.getBiomeCacheBlock(x, z).biomes;
83
    }
84
85
    public class Block
86
    {
87
        public float[] rainfallValues = new float[256];
88
        public BiomeGenBase[] biomes = new BiomeGenBase[256];
89
        public int xPosition;
90
        public int zPosition;
91
        public long lastAccessTime;
92
93
        public Block(int x, int z)
94
        {
95
            this.xPosition = x;
96
            this.zPosition = z;
97
            BiomeCache.this.chunkManager.getRainfall(this.rainfallValues, x << 4, z << 4, 16, 16);
98
            BiomeCache.this.chunkManager.getBiomeGenAt(this.biomes, x << 4, z << 4, 16, 16, false);
99
        }
100
101
        public BiomeGenBase getBiomeGenAt(int x, int z)
102
        {
103
            return this.biomes[x & 15 | (z & 15) << 4];
104
        }
105
    }
106
}
107

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