-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChunkProviderLoadOrGenerate.java
More file actions
265 lines (247 loc) · 7.4 KB
/
ChunkProviderLoadOrGenerate.java
File metadata and controls
265 lines (247 loc) · 7.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
package net.minecraft.src;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode
import java.io.IOException;
public class ChunkProviderLoadOrGenerate
implements IChunkProvider
{
public ChunkProviderLoadOrGenerate(World world, IChunkLoader ichunkloader, IChunkProvider ichunkprovider)
{
chunks = new Chunk[1024];
lastQueriedChunkXPos = 0xc4653601;
lastQueriedChunkZPos = 0xc4653601;
blankChunk = new EmptyChunk(world, new byte[32768], 0, 0);
worldObj = world;
chunkLoader = ichunkloader;
chunkProvider = ichunkprovider;
}
public void func_21110_c(int i, int j)
{
field_21113_i = i;
field_21112_j = j;
}
public boolean func_21111_d(int i, int j)
{
byte byte0 = 15;
return i >= field_21113_i - byte0 && j >= field_21112_j - byte0 && i <= field_21113_i + byte0 && j <= field_21112_j + byte0;
}
public boolean chunkExists(int i, int j)
{
if(!func_21111_d(i, j))
{
return false;
}
if(i == lastQueriedChunkXPos && j == lastQueriedChunkZPos && lastQueriedChunk != null)
{
return true;
} else
{
int k = i & 0x1f;
int l = j & 0x1f;
int i1 = k + l * 32;
return chunks[i1] != null && (chunks[i1] == blankChunk || chunks[i1].isAtLocation(i, j));
}
}
public Chunk provideChunk(int i, int j)
{
if(i == lastQueriedChunkXPos && j == lastQueriedChunkZPos && lastQueriedChunk != null)
{
return lastQueriedChunk;
}
if(!worldObj.field_9430_x && !func_21111_d(i, j))
{
return blankChunk;
}
int k = i & 0x1f;
int l = j & 0x1f;
int i1 = k + l * 32;
if(!chunkExists(i, j))
{
if(chunks[i1] != null)
{
chunks[i1].onChunkUnload();
saveChunk(chunks[i1]);
saveExtraChunkData(chunks[i1]);
}
Chunk chunk = func_542_c(i, j);
if(chunk == null)
{
if(chunkProvider == null)
{
chunk = blankChunk;
} else
{
chunk = chunkProvider.provideChunk(i, j);
}
}
chunks[i1] = chunk;
chunk.func_4143_d();
if(chunks[i1] != null)
{
chunks[i1].onChunkLoad();
}
if(!chunks[i1].isTerrainPopulated && chunkExists(i + 1, j + 1) && chunkExists(i, j + 1) && chunkExists(i + 1, j))
{
populate(this, i, j);
}
if(chunkExists(i - 1, j) && !provideChunk(i - 1, j).isTerrainPopulated && chunkExists(i - 1, j + 1) && chunkExists(i, j + 1) && chunkExists(i - 1, j))
{
populate(this, i - 1, j);
}
if(chunkExists(i, j - 1) && !provideChunk(i, j - 1).isTerrainPopulated && chunkExists(i + 1, j - 1) && chunkExists(i, j - 1) && chunkExists(i + 1, j))
{
populate(this, i, j - 1);
}
if(chunkExists(i - 1, j - 1) && !provideChunk(i - 1, j - 1).isTerrainPopulated && chunkExists(i - 1, j - 1) && chunkExists(i, j - 1) && chunkExists(i - 1, j))
{
populate(this, i - 1, j - 1);
}
}
lastQueriedChunkXPos = i;
lastQueriedChunkZPos = j;
lastQueriedChunk = chunks[i1];
return chunks[i1];
}
private Chunk func_542_c(int i, int j)
{
if(chunkLoader == null)
{
return blankChunk;
}
try
{
Chunk chunk = chunkLoader.loadChunk(worldObj, i, j);
if(chunk != null)
{
chunk.lastSaveTime = worldObj.func_22139_r();
}
return chunk;
}
catch(Exception exception)
{
exception.printStackTrace();
}
return blankChunk;
}
private void saveExtraChunkData(Chunk chunk)
{
if(chunkLoader == null)
{
return;
}
try
{
chunkLoader.saveExtraChunkData(worldObj, chunk);
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
private void saveChunk(Chunk chunk)
{
if(chunkLoader == null)
{
return;
}
try
{
chunk.lastSaveTime = worldObj.func_22139_r();
chunkLoader.saveChunk(worldObj, chunk);
}
catch(IOException ioexception)
{
ioexception.printStackTrace();
}
}
public void populate(IChunkProvider ichunkprovider, int i, int j)
{
Chunk chunk = provideChunk(i, j);
if(!chunk.isTerrainPopulated)
{
chunk.isTerrainPopulated = true;
if(chunkProvider != null)
{
chunkProvider.populate(ichunkprovider, i, j);
chunk.setChunkModified();
}
}
}
public boolean saveChunks(boolean flag, IProgressUpdate iprogressupdate)
{
int i = 0;
int j = 0;
if(iprogressupdate != null)
{
for(int k = 0; k < chunks.length; k++)
{
if(chunks[k] != null && chunks[k].needsSaving(flag))
{
j++;
}
}
}
int l = 0;
for(int i1 = 0; i1 < chunks.length; i1++)
{
if(chunks[i1] == null)
{
continue;
}
if(flag && !chunks[i1].neverSave)
{
saveExtraChunkData(chunks[i1]);
}
if(!chunks[i1].needsSaving(flag))
{
continue;
}
saveChunk(chunks[i1]);
chunks[i1].isModified = false;
if(++i == 2 && !flag)
{
return false;
}
if(iprogressupdate != null && ++l % 10 == 0)
{
iprogressupdate.setLoadingProgress((l * 100) / j);
}
}
if(flag)
{
if(chunkLoader == null)
{
return true;
}
chunkLoader.saveExtraData();
}
return true;
}
public boolean func_532_a()
{
if(chunkLoader != null)
{
chunkLoader.func_814_a();
}
return chunkProvider.func_532_a();
}
public boolean func_536_b()
{
return true;
}
public String toString()
{
return (new StringBuilder()).append("ChunkCache: ").append(chunks.length).toString();
}
private Chunk blankChunk;
private IChunkProvider chunkProvider;
private IChunkLoader chunkLoader;
private Chunk chunks[];
private World worldObj;
int lastQueriedChunkXPos;
int lastQueriedChunkZPos;
private Chunk lastQueriedChunk;
private int field_21113_i;
private int field_21112_j;
}