ChunkProviderClient .java

net.minecraft.client.multiplayer.ChunkProviderClient (class, 178 lines): members: chunkListing, chunkMapping, unloadChunk, blankChunk, loadChunk, canSave.

net.minecraft.client.multiplayerclass178 linesclient5.0 KB

Implements

API Surface (16)

boolean chunkExists(int x, int z)
void unloadChunk(int x, int z)
Chunk loadChunk(int chunkX, int chunkZ)
Chunk provideChunk(int x, int z)
boolean saveChunks(boolean saveAllChunks, IProgressUpdate progressCallback)
void saveExtraData()
boolean unloadQueuedChunks()
boolean canSave()
void populate(IChunkProvider chunkProvider, int x, int z)
boolean populateChunk(IChunkProvider chunkProvider, Chunk chunkIn, int x, int z)
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 (5)

logger
blankChunk
chunkMapping
chunkListing
worldObj

String literals (1)

"MultiplayerChunkCache: "

Full Source

ChunkProviderClient.java178 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.multiplayer;
2
3
import com.google.common.collect.Lists;
4
import java.util.List;
5
import net.minecraft.entity.EnumCreatureType;
6
import net.minecraft.util.BlockPos;
7
import net.minecraft.util.IProgressUpdate;
8
import net.minecraft.util.LongHashMap;
9
import net.minecraft.world.ChunkCoordIntPair;
10
import net.minecraft.world.World;
11
import net.minecraft.world.biome.BiomeGenBase;
12
import net.minecraft.world.chunk.Chunk;
13
import net.minecraft.world.chunk.EmptyChunk;
14
import net.minecraft.world.chunk.IChunkProvider;
15
import org.apache.logging.log4j.LogManager;
16
import org.apache.logging.log4j.Logger;
17
18
public class ChunkProviderClient implements IChunkProvider
19
{
20
    private static final Logger logger = LogManager.getLogger();
21
22
    /**
23
     * The completely empty chunk used by ChunkProviderClient when chunkMapping doesn't contain the requested
24
     * coordinates.
25
     */
26
    private Chunk blankChunk;
27
    private LongHashMap<Chunk> chunkMapping = new LongHashMap();
28
    private List<Chunk> chunkListing = Lists.<Chunk>newArrayList();
29
30
    /** Reference to the World object. */
31
    private World worldObj;
32
33
    public ChunkProviderClient(World worldIn)
34
    {
35
        this.blankChunk = new EmptyChunk(worldIn, 0, 0);
36
        this.worldObj = worldIn;
37
    }
38
39
    /**
40
     * Checks to see if a chunk exists at x, z
41
     */
42
    public boolean chunkExists(int x, int z)
43
    {
44
        return true;
45
    }
46
47
    /**
48
     * Unload chunk from ChunkProviderClient's hashmap. Called in response to a Packet50PreChunk with its mode field set
49
     * to false
50
     */
51
    public void unloadChunk(int x, int z)
52
    {
53
        Chunk chunk = this.provideChunk(x, z);
54
55
        if (!chunk.isEmpty())
56
        {
57
            chunk.onChunkUnload();
58
        }
59
60
        this.chunkMapping.remove(ChunkCoordIntPair.chunkXZ2Int(x, z));
61
        this.chunkListing.remove(chunk);
62
    }
63
64
    /**
65
     * loads or generates the chunk at the chunk location specified
66
     *  
67
     * @param chunkX x coord of the chunk to load (block coord >> 4)
68
     * @param chunkZ z coord of the chunk to load (block coord >> 4)
69
     */
70
    public Chunk loadChunk(int chunkX, int chunkZ)
71
    {
72
        Chunk chunk = new Chunk(this.worldObj, chunkX, chunkZ);
73
        this.chunkMapping.add(ChunkCoordIntPair.chunkXZ2Int(chunkX, chunkZ), chunk);
74
        this.chunkListing.add(chunk);
75
        chunk.setChunkLoaded(true);
76
        return chunk;
77
    }
78
79
    /**
80
     * Will return back a chunk, if it doesn't exist and its not a MP client it will generates all the blocks for the
81
     * specified chunk from the map seed and chunk seed
82
     */
83
    public Chunk provideChunk(int x, int z)
84
    {
85
        Chunk chunk = (Chunk)this.chunkMapping.getValueByKey(ChunkCoordIntPair.chunkXZ2Int(x, z));
86
        return chunk == null ? this.blankChunk : chunk;
87
    }
88
89
    /**
90
     * Two modes of operation: if passed true, save all Chunks in one go.  If passed false, save up to two chunks.
91
     * Return true if all chunks have been saved.
92
     */
93
    public boolean saveChunks(boolean saveAllChunks, IProgressUpdate progressCallback)
94
    {
95
        return true;
96
    }
97
98
    /**
99
     * Save extra data not associated with any Chunk.  Not saved during autosave, only during world unload.  Currently
100
     * unimplemented.
101
     */
102
    public void saveExtraData()
103
    {
104
    }
105
106
    /**
107
     * Unloads chunks that are marked to be unloaded. This is not guaranteed to unload every such chunk.
108
     */
109
    public boolean unloadQueuedChunks()
110
    {
111
        long i = System.currentTimeMillis();
112
113
        for (Chunk chunk : this.chunkListing)
114
        {
115
            chunk.func_150804_b(System.currentTimeMillis() - i > 5L);
116
        }
117
118
        if (System.currentTimeMillis() - i > 100L)
119
        {
120
            logger.info("Warning: Clientside chunk ticking took {} ms", new Object[] {Long.valueOf(System.currentTimeMillis() - i)});
121
        }
122
123
        return false;
124
    }
125
126
    /**
127
     * Returns if the IChunkProvider supports saving.
128
     */
129
    public boolean canSave()
130
    {
131
        return false;
132
    }
133
134
    /**
135
     * Populates chunk with ores etc etc
136
     */
137
    public void populate(IChunkProvider chunkProvider, int x, int z)
138
    {
139
    }
140
141
    public boolean populateChunk(IChunkProvider chunkProvider, Chunk chunkIn, int x, int z)
142
    {
143
        return false;
144
    }
145
146
    /**
147
     * Converts the instance data to a readable string.
148
     */
149
    public String makeString()
150
    {
151
        return "MultiplayerChunkCache: " + this.chunkMapping.getNumHashElements() + ", " + this.chunkListing.size();
152
    }
153
154
    public List<BiomeGenBase.SpawnListEntry> getPossibleCreatures(EnumCreatureType creatureType, BlockPos pos)
155
    {
156
        return null;
157
    }
158
159
    public BlockPos getStrongholdGen(World worldIn, String structureName, BlockPos position)
160
    {
161
        return null;
162
    }
163
164
    public int getLoadedChunkCount()
165
    {
166
        return this.chunkListing.size();
167
    }
168
169
    public void recreateStructures(Chunk chunkIn, int x, int z)
170
    {
171
    }
172
173
    public Chunk provideChunk(BlockPos blockPosIn)
174
    {
175
        return this.provideChunk(blockPosIn.getX() >> 4, blockPosIn.getZ() >> 4);
176
    }
177
}
178

Deobfuscated MCP 1.8.9 source of ChunkProviderClient from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/multiplayer/ChunkProviderClient.java), stored verbatim.