RegionFileCache .java

net.minecraft.world.chunk.storage.RegionFileCache (class): members: clearRegionFileReferences, createOrLoadRegionFile, getChunkOutputStream. imports: Maps.

net.minecraft.world.chunk.storageclass83 linescommon2.4 KB

API Surface (4)

RegionFile createOrLoadRegionFile(File worldDir, int chunkX, int chunkZ)
void clearRegionFileReferences()
DataInputStream getChunkInputStream(File worldDir, int chunkX, int chunkZ)
DataOutputStream getChunkOutputStream(File worldDir, int chunkX, int chunkZ)

Fields & Constants (1)

regionsByFilename

String literals (2)

"region"
".mca"

Code Graph: Dependencies (1)

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

Full Source

RegionFileCache.java83 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.world.chunk.storage;
2
3
import com.google.common.collect.Maps;
4
import java.io.DataInputStream;
5
import java.io.DataOutputStream;
6
import java.io.File;
7
import java.io.IOException;
8
import java.util.Map;
9
10
public class RegionFileCache
11
{
12
    private static final Map<File, RegionFile> regionsByFilename = Maps.<File, RegionFile>newHashMap();
13
14
    public static synchronized RegionFile createOrLoadRegionFile(File worldDir, int chunkX, int chunkZ)
15
    {
16
        File file1 = new File(worldDir, "region");
17
        File file2 = new File(file1, "r." + (chunkX >> 5) + "." + (chunkZ >> 5) + ".mca");
18
        RegionFile regionfile = (RegionFile)regionsByFilename.get(file2);
19
20
        if (regionfile != null)
21
        {
22
            return regionfile;
23
        }
24
        else
25
        {
26
            if (!file1.exists())
27
            {
28
                file1.mkdirs();
29
            }
30
31
            if (regionsByFilename.size() >= 256)
32
            {
33
                clearRegionFileReferences();
34
            }
35
36
            RegionFile regionfile1 = new RegionFile(file2);
37
            regionsByFilename.put(file2, regionfile1);
38
            return regionfile1;
39
        }
40
    }
41
42
    /**
43
     * clears region file references
44
     */
45
    public static synchronized void clearRegionFileReferences()
46
    {
47
        for (RegionFile regionfile : regionsByFilename.values())
48
        {
49
            try
50
            {
51
                if (regionfile != null)
52
                {
53
                    regionfile.close();
54
                }
55
            }
56
            catch (IOException ioexception)
57
            {
58
                ioexception.printStackTrace();
59
            }
60
        }
61
62
        regionsByFilename.clear();
63
    }
64
65
    /**
66
     * Returns an input stream for the specified chunk. Args: worldDir, chunkX, chunkZ
67
     */
68
    public static DataInputStream getChunkInputStream(File worldDir, int chunkX, int chunkZ)
69
    {
70
        RegionFile regionfile = createOrLoadRegionFile(worldDir, chunkX, chunkZ);
71
        return regionfile.getChunkDataInputStream(chunkX & 31, chunkZ & 31);
72
    }
73
74
    /**
75
     * Returns an output stream for the specified chunk. Args: worldDir, chunkX, chunkZ
76
     */
77
    public static DataOutputStream getChunkOutputStream(File worldDir, int chunkX, int chunkZ)
78
    {
79
        RegionFile regionfile = createOrLoadRegionFile(worldDir, chunkX, chunkZ);
80
        return regionfile.getChunkDataOutputStream(chunkX & 31, chunkZ & 31);
81
    }
82
}
83

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