RenderChunk .java

net.minecraft.client.renderer.chunk.RenderChunk (class): members: makeCompileTaskTransparency, getVertexBufferByLayer, makeCompileTaskChunk, isNeedsUpdate.

net.minecraft.client.renderer.chunkclass390 linesclient13.0 KB

API Surface (18)

boolean setFrameIndex(int frameIndexIn)
VertexBuffer getVertexBufferByLayer(int layer)
void setPosition(BlockPos pos)
void resortTransparency(float x, float y, float z, ChunkCompileTaskGenerator generator)
void rebuildChunk(float x, float y, float z, ChunkCompileTaskGenerator generator)
void finishCompileTask()
ReentrantLock getLockCompileTask()
ChunkCompileTaskGenerator makeCompileTaskChunk()
ChunkCompileTaskGenerator makeCompileTaskTransparency()
void multModelviewMatrix()
CompiledChunk getCompiledChunk()
void setCompiledChunk(CompiledChunk compiledChunkIn)
void stopCompileTask()
void deleteGlResources()
BlockPos getPosition()
void setNeedsUpdate(boolean needsUpdateIn)
boolean isNeedsUpdate()
BlockPos getBlockPosOffset16(EnumFacing p_181701_1_)

Fields & Constants (16)

world
renderGlobal
renderChunksUpdated
position
compiledChunk
lockCompileTask
lockCompiledChunk
compileTask
setTileEntities
index
modelviewMatrix
vertexBuffers
boundingBox
frameIndex
needsUpdate
mapEnumFacing

Full Source

RenderChunk.java390 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.renderer.chunk;
2
3
import com.google.common.collect.Maps;
4
import com.google.common.collect.Sets;
5
import java.nio.FloatBuffer;
6
import java.util.EnumMap;
7
import java.util.HashSet;
8
import java.util.Set;
9
import java.util.concurrent.locks.ReentrantLock;
10
import net.minecraft.block.Block;
11
import net.minecraft.block.state.IBlockState;
12
import net.minecraft.client.Minecraft;
13
import net.minecraft.client.renderer.BlockRendererDispatcher;
14
import net.minecraft.client.renderer.GLAllocation;
15
import net.minecraft.client.renderer.GlStateManager;
16
import net.minecraft.client.renderer.OpenGlHelper;
17
import net.minecraft.client.renderer.RegionRenderCache;
18
import net.minecraft.client.renderer.RenderGlobal;
19
import net.minecraft.client.renderer.WorldRenderer;
20
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
21
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
22
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
23
import net.minecraft.client.renderer.vertex.VertexBuffer;
24
import net.minecraft.tileentity.TileEntity;
25
import net.minecraft.util.AxisAlignedBB;
26
import net.minecraft.util.BlockPos;
27
import net.minecraft.util.EnumFacing;
28
import net.minecraft.util.EnumWorldBlockLayer;
29
import net.minecraft.world.IBlockAccess;
30
import net.minecraft.world.World;
31
32
public class RenderChunk
33
{
34
    private World world;
35
    private final RenderGlobal renderGlobal;
36
    public static int renderChunksUpdated;
37
    private BlockPos position;
38
    public CompiledChunk compiledChunk = CompiledChunk.DUMMY;
39
    private final ReentrantLock lockCompileTask = new ReentrantLock();
40
    private final ReentrantLock lockCompiledChunk = new ReentrantLock();
41
    private ChunkCompileTaskGenerator compileTask = null;
42
    private final Set<TileEntity> setTileEntities = Sets.<TileEntity>newHashSet();
43
    private final int index;
44
    private final FloatBuffer modelviewMatrix = GLAllocation.createDirectFloatBuffer(16);
45
    private final VertexBuffer[] vertexBuffers = new VertexBuffer[EnumWorldBlockLayer.values().length];
46
    public AxisAlignedBB boundingBox;
47
    private int frameIndex = -1;
48
    private boolean needsUpdate = true;
49
    private EnumMap<EnumFacing, BlockPos> mapEnumFacing = Maps.newEnumMap(EnumFacing.class);
50
51
    public RenderChunk(World worldIn, RenderGlobal renderGlobalIn, BlockPos blockPosIn, int indexIn)
52
    {
53
        this.world = worldIn;
54
        this.renderGlobal = renderGlobalIn;
55
        this.index = indexIn;
56
57
        if (!blockPosIn.equals(this.getPosition()))
58
        {
59
            this.setPosition(blockPosIn);
60
        }
61
62
        if (OpenGlHelper.useVbo())
63
        {
64
            for (int i = 0; i < EnumWorldBlockLayer.values().length; ++i)
65
            {
66
                this.vertexBuffers[i] = new VertexBuffer(DefaultVertexFormats.BLOCK);
67
            }
68
        }
69
    }
70
71
    public boolean setFrameIndex(int frameIndexIn)
72
    {
73
        if (this.frameIndex == frameIndexIn)
74
        {
75
            return false;
76
        }
77
        else
78
        {
79
            this.frameIndex = frameIndexIn;
80
            return true;
81
        }
82
    }
83
84
    public VertexBuffer getVertexBufferByLayer(int layer)
85
    {
86
        return this.vertexBuffers[layer];
87
    }
88
89
    public void setPosition(BlockPos pos)
90
    {
91
        this.stopCompileTask();
92
        this.position = pos;
93
        this.boundingBox = new AxisAlignedBB(pos, pos.add(16, 16, 16));
94
95
        for (EnumFacing enumfacing : EnumFacing.values())
96
        {
97
            this.mapEnumFacing.put(enumfacing, pos.offset(enumfacing, 16));
98
        }
99
100
        this.initModelviewMatrix();
101
    }
102
103
    public void resortTransparency(float x, float y, float z, ChunkCompileTaskGenerator generator)
104
    {
105
        CompiledChunk compiledchunk = generator.getCompiledChunk();
106
107
        if (compiledchunk.getState() != null && !compiledchunk.isLayerEmpty(EnumWorldBlockLayer.TRANSLUCENT))
108
        {
109
            this.preRenderBlocks(generator.getRegionRenderCacheBuilder().getWorldRendererByLayer(EnumWorldBlockLayer.TRANSLUCENT), this.position);
110
            generator.getRegionRenderCacheBuilder().getWorldRendererByLayer(EnumWorldBlockLayer.TRANSLUCENT).setVertexState(compiledchunk.getState());
111
            this.postRenderBlocks(EnumWorldBlockLayer.TRANSLUCENT, x, y, z, generator.getRegionRenderCacheBuilder().getWorldRendererByLayer(EnumWorldBlockLayer.TRANSLUCENT), compiledchunk);
112
        }
113
    }
114
115
    public void rebuildChunk(float x, float y, float z, ChunkCompileTaskGenerator generator)
116
    {
117
        CompiledChunk compiledchunk = new CompiledChunk();
118
        int i = 1;
119
        BlockPos blockpos = this.position;
120
        BlockPos blockpos1 = blockpos.add(15, 15, 15);
121
        generator.getLock().lock();
122
        IBlockAccess iblockaccess;
123
124
        try
125
        {
126
            if (generator.getStatus() != ChunkCompileTaskGenerator.Status.COMPILING)
127
            {
128
                return;
129
            }
130
131
            iblockaccess = new RegionRenderCache(this.world, blockpos.add(-1, -1, -1), blockpos1.add(1, 1, 1), 1);
132
            generator.setCompiledChunk(compiledchunk);
133
        }
134
        finally
135
        {
136
            generator.getLock().unlock();
137
        }
138
139
        VisGraph lvt_10_1_ = new VisGraph();
140
        HashSet lvt_11_1_ = Sets.newHashSet();
141
142
        if (!iblockaccess.extendedLevelsInChunkCache())
143
        {
144
            ++renderChunksUpdated;
145
            boolean[] aboolean = new boolean[EnumWorldBlockLayer.values().length];
146
            BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
147
148
            for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(blockpos, blockpos1))
149
            {
150
                IBlockState iblockstate = iblockaccess.getBlockState(blockpos$mutableblockpos);
151
                Block block = iblockstate.getBlock();
152
153
                if (block.isOpaqueCube())
154
                {
155
                    lvt_10_1_.func_178606_a(blockpos$mutableblockpos);
156
                }
157
158
                if (block.hasTileEntity())
159
                {
160
                    TileEntity tileentity = iblockaccess.getTileEntity(new BlockPos(blockpos$mutableblockpos));
161
                    TileEntitySpecialRenderer<TileEntity> tileentityspecialrenderer = TileEntityRendererDispatcher.instance.<TileEntity>getSpecialRenderer(tileentity);
162
163
                    if (tileentity != null && tileentityspecialrenderer != null)
164
                    {
165
                        compiledchunk.addTileEntity(tileentity);
166
167
                        if (tileentityspecialrenderer.forceTileEntityRender())
168
                        {
169
                            lvt_11_1_.add(tileentity);
170
                        }
171
                    }
172
                }
173
174
                EnumWorldBlockLayer enumworldblocklayer1 = block.getBlockLayer();
175
                int j = enumworldblocklayer1.ordinal();
176
177
                if (block.getRenderType() != -1)
178
                {
179
                    WorldRenderer worldrenderer = generator.getRegionRenderCacheBuilder().getWorldRendererByLayerId(j);
180
181
                    if (!compiledchunk.isLayerStarted(enumworldblocklayer1))
182
                    {
183
                        compiledchunk.setLayerStarted(enumworldblocklayer1);
184
                        this.preRenderBlocks(worldrenderer, blockpos);
185
                    }
186
187
                    aboolean[j] |= blockrendererdispatcher.renderBlock(iblockstate, blockpos$mutableblockpos, iblockaccess, worldrenderer);
188
                }
189
            }
190
191
            for (EnumWorldBlockLayer enumworldblocklayer : EnumWorldBlockLayer.values())
192
            {
193
                if (aboolean[enumworldblocklayer.ordinal()])
194
                {
195
                    compiledchunk.setLayerUsed(enumworldblocklayer);
196
                }
197
198
                if (compiledchunk.isLayerStarted(enumworldblocklayer))
199
                {
200
                    this.postRenderBlocks(enumworldblocklayer, x, y, z, generator.getRegionRenderCacheBuilder().getWorldRendererByLayer(enumworldblocklayer), compiledchunk);
201
                }
202
            }
203
        }
204
205
        compiledchunk.setVisibility(lvt_10_1_.computeVisibility());
206
        this.lockCompileTask.lock();
207
208
        try
209
        {
210
            Set<TileEntity> set = Sets.newHashSet(lvt_11_1_);
211
            Set<TileEntity> set1 = Sets.newHashSet(this.setTileEntities);
212
            set.removeAll(this.setTileEntities);
213
            set1.removeAll(lvt_11_1_);
214
            this.setTileEntities.clear();
215
            this.setTileEntities.addAll(lvt_11_1_);
216
            this.renderGlobal.updateTileEntities(set1, set);
217
        }
218
        finally
219
        {
220
            this.lockCompileTask.unlock();
221
        }
222
    }
223
224
    protected void finishCompileTask()
225
    {
226
        this.lockCompileTask.lock();
227
228
        try
229
        {
230
            if (this.compileTask != null && this.compileTask.getStatus() != ChunkCompileTaskGenerator.Status.DONE)
231
            {
232
                this.compileTask.finish();
233
                this.compileTask = null;
234
            }
235
        }
236
        finally
237
        {
238
            this.lockCompileTask.unlock();
239
        }
240
    }
241
242
    public ReentrantLock getLockCompileTask()
243
    {
244
        return this.lockCompileTask;
245
    }
246
247
    public ChunkCompileTaskGenerator makeCompileTaskChunk()
248
    {
249
        this.lockCompileTask.lock();
250
        ChunkCompileTaskGenerator chunkcompiletaskgenerator;
251
252
        try
253
        {
254
            this.finishCompileTask();
255
            this.compileTask = new ChunkCompileTaskGenerator(this, ChunkCompileTaskGenerator.Type.REBUILD_CHUNK);
256
            chunkcompiletaskgenerator = this.compileTask;
257
        }
258
        finally
259
        {
260
            this.lockCompileTask.unlock();
261
        }
262
263
        return chunkcompiletaskgenerator;
264
    }
265
266
    public ChunkCompileTaskGenerator makeCompileTaskTransparency()
267
    {
268
        this.lockCompileTask.lock();
269
        ChunkCompileTaskGenerator chunkcompiletaskgenerator;
270
271
        try
272
        {
273
            if (this.compileTask == null || this.compileTask.getStatus() != ChunkCompileTaskGenerator.Status.PENDING)
274
            {
275
                if (this.compileTask != null && this.compileTask.getStatus() != ChunkCompileTaskGenerator.Status.DONE)
276
                {
277
                    this.compileTask.finish();
278
                    this.compileTask = null;
279
                }
280
281
                this.compileTask = new ChunkCompileTaskGenerator(this, ChunkCompileTaskGenerator.Type.RESORT_TRANSPARENCY);
282
                this.compileTask.setCompiledChunk(this.compiledChunk);
283
                chunkcompiletaskgenerator = this.compileTask;
284
                return chunkcompiletaskgenerator;
285
            }
286
287
            chunkcompiletaskgenerator = null;
288
        }
289
        finally
290
        {
291
            this.lockCompileTask.unlock();
292
        }
293
294
        return chunkcompiletaskgenerator;
295
    }
296
297
    private void preRenderBlocks(WorldRenderer worldRendererIn, BlockPos pos)
298
    {
299
        worldRendererIn.begin(7, DefaultVertexFormats.BLOCK);
300
        worldRendererIn.setTranslation((double)(-pos.getX()), (double)(-pos.getY()), (double)(-pos.getZ()));
301
    }
302
303
    private void postRenderBlocks(EnumWorldBlockLayer layer, float x, float y, float z, WorldRenderer worldRendererIn, CompiledChunk compiledChunkIn)
304
    {
305
        if (layer == EnumWorldBlockLayer.TRANSLUCENT && !compiledChunkIn.isLayerEmpty(layer))
306
        {
307
            worldRendererIn.sortVertexData(x, y, z);
308
            compiledChunkIn.setState(worldRendererIn.getVertexState());
309
        }
310
311
        worldRendererIn.finishDrawing();
312
    }
313
314
    private void initModelviewMatrix()
315
    {
316
        GlStateManager.pushMatrix();
317
        GlStateManager.loadIdentity();
318
        float f = 1.000001F;
319
        GlStateManager.translate(-8.0F, -8.0F, -8.0F);
320
        GlStateManager.scale(f, f, f);
321
        GlStateManager.translate(8.0F, 8.0F, 8.0F);
322
        GlStateManager.getFloat(2982, this.modelviewMatrix);
323
        GlStateManager.popMatrix();
324
    }
325
326
    public void multModelviewMatrix()
327
    {
328
        GlStateManager.multMatrix(this.modelviewMatrix);
329
    }
330
331
    public CompiledChunk getCompiledChunk()
332
    {
333
        return this.compiledChunk;
334
    }
335
336
    public void setCompiledChunk(CompiledChunk compiledChunkIn)
337
    {
338
        this.lockCompiledChunk.lock();
339
340
        try
341
        {
342
            this.compiledChunk = compiledChunkIn;
343
        }
344
        finally
345
        {
346
            this.lockCompiledChunk.unlock();
347
        }
348
    }
349
350
    public void stopCompileTask()
351
    {
352
        this.finishCompileTask();
353
        this.compiledChunk = CompiledChunk.DUMMY;
354
    }
355
356
    public void deleteGlResources()
357
    {
358
        this.stopCompileTask();
359
        this.world = null;
360
361
        for (int i = 0; i < EnumWorldBlockLayer.values().length; ++i)
362
        {
363
            if (this.vertexBuffers[i] != null)
364
            {
365
                this.vertexBuffers[i].deleteGlBuffers();
366
            }
367
        }
368
    }
369
370
    public BlockPos getPosition()
371
    {
372
        return this.position;
373
    }
374
375
    public void setNeedsUpdate(boolean needsUpdateIn)
376
    {
377
        this.needsUpdate = needsUpdateIn;
378
    }
379
380
    public boolean isNeedsUpdate()
381
    {
382
        return this.needsUpdate;
383
    }
384
385
    public BlockPos getBlockPosOffset16(EnumFacing p_181701_1_)
386
    {
387
        return (BlockPos)this.mapEnumFacing.get(p_181701_1_);
388
    }
389
}
390

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