ViewFrustum .java

net.minecraft.client.renderer.ViewFrustum (class): members: updateChunkPositions, markBlocksForUpdate, createRenderChunks, setCountChunksXYZ, countChunksX.

net.minecraft.client.rendererclass179 linesclient5.2 KB

API Surface (6)

void createRenderChunks(IRenderChunkFactory renderChunkFactory)
void deleteGlResources()
void setCountChunksXYZ(int renderDistanceChunks)
void updateChunkPositions(double viewEntityX, double viewEntityZ)
void markBlocksForUpdate(int fromX, int fromY, int fromZ, int toX, int toY, int toZ)
RenderChunk getRenderChunk(BlockPos pos)

Fields & Constants (6)

renderGlobal
world
countChunksY
countChunksX
countChunksZ
renderChunks

Code Graph: Dependencies (6)

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

Full Source

ViewFrustum.java179 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.renderer;
2
3
import net.minecraft.client.renderer.chunk.IRenderChunkFactory;
4
import net.minecraft.client.renderer.chunk.RenderChunk;
5
import net.minecraft.util.BlockPos;
6
import net.minecraft.util.MathHelper;
7
import net.minecraft.world.World;
8
9
public class ViewFrustum
10
{
11
    protected final RenderGlobal renderGlobal;
12
    protected final World world;
13
    protected int countChunksY;
14
    protected int countChunksX;
15
    protected int countChunksZ;
16
    public RenderChunk[] renderChunks;
17
18
    public ViewFrustum(World worldIn, int renderDistanceChunks, RenderGlobal p_i46246_3_, IRenderChunkFactory renderChunkFactory)
19
    {
20
        this.renderGlobal = p_i46246_3_;
21
        this.world = worldIn;
22
        this.setCountChunksXYZ(renderDistanceChunks);
23
        this.createRenderChunks(renderChunkFactory);
24
    }
25
26
    protected void createRenderChunks(IRenderChunkFactory renderChunkFactory)
27
    {
28
        int i = this.countChunksX * this.countChunksY * this.countChunksZ;
29
        this.renderChunks = new RenderChunk[i];
30
        int j = 0;
31
32
        for (int k = 0; k < this.countChunksX; ++k)
33
        {
34
            for (int l = 0; l < this.countChunksY; ++l)
35
            {
36
                for (int i1 = 0; i1 < this.countChunksZ; ++i1)
37
                {
38
                    int j1 = (i1 * this.countChunksY + l) * this.countChunksX + k;
39
                    BlockPos blockpos = new BlockPos(k * 16, l * 16, i1 * 16);
40
                    this.renderChunks[j1] = renderChunkFactory.makeRenderChunk(this.world, this.renderGlobal, blockpos, j++);
41
                }
42
            }
43
        }
44
    }
45
46
    public void deleteGlResources()
47
    {
48
        for (RenderChunk renderchunk : this.renderChunks)
49
        {
50
            renderchunk.deleteGlResources();
51
        }
52
    }
53
54
    protected void setCountChunksXYZ(int renderDistanceChunks)
55
    {
56
        int i = renderDistanceChunks * 2 + 1;
57
        this.countChunksX = i;
58
        this.countChunksY = 16;
59
        this.countChunksZ = i;
60
    }
61
62
    public void updateChunkPositions(double viewEntityX, double viewEntityZ)
63
    {
64
        int i = MathHelper.floor_double(viewEntityX) - 8;
65
        int j = MathHelper.floor_double(viewEntityZ) - 8;
66
        int k = this.countChunksX * 16;
67
68
        for (int l = 0; l < this.countChunksX; ++l)
69
        {
70
            int i1 = this.func_178157_a(i, k, l);
71
72
            for (int j1 = 0; j1 < this.countChunksZ; ++j1)
73
            {
74
                int k1 = this.func_178157_a(j, k, j1);
75
76
                for (int l1 = 0; l1 < this.countChunksY; ++l1)
77
                {
78
                    int i2 = l1 * 16;
79
                    RenderChunk renderchunk = this.renderChunks[(j1 * this.countChunksY + l1) * this.countChunksX + l];
80
                    BlockPos blockpos = new BlockPos(i1, i2, k1);
81
82
                    if (!blockpos.equals(renderchunk.getPosition()))
83
                    {
84
                        renderchunk.setPosition(blockpos);
85
                    }
86
                }
87
            }
88
        }
89
    }
90
91
    private int func_178157_a(int p_178157_1_, int p_178157_2_, int p_178157_3_)
92
    {
93
        int i = p_178157_3_ * 16;
94
        int j = i - p_178157_1_ + p_178157_2_ / 2;
95
96
        if (j < 0)
97
        {
98
            j -= p_178157_2_ - 1;
99
        }
100
101
        return i - j / p_178157_2_ * p_178157_2_;
102
    }
103
104
    public void markBlocksForUpdate(int fromX, int fromY, int fromZ, int toX, int toY, int toZ)
105
    {
106
        int i = MathHelper.bucketInt(fromX, 16);
107
        int j = MathHelper.bucketInt(fromY, 16);
108
        int k = MathHelper.bucketInt(fromZ, 16);
109
        int l = MathHelper.bucketInt(toX, 16);
110
        int i1 = MathHelper.bucketInt(toY, 16);
111
        int j1 = MathHelper.bucketInt(toZ, 16);
112
113
        for (int k1 = i; k1 <= l; ++k1)
114
        {
115
            int l1 = k1 % this.countChunksX;
116
117
            if (l1 < 0)
118
            {
119
                l1 += this.countChunksX;
120
            }
121
122
            for (int i2 = j; i2 <= i1; ++i2)
123
            {
124
                int j2 = i2 % this.countChunksY;
125
126
                if (j2 < 0)
127
                {
128
                    j2 += this.countChunksY;
129
                }
130
131
                for (int k2 = k; k2 <= j1; ++k2)
132
                {
133
                    int l2 = k2 % this.countChunksZ;
134
135
                    if (l2 < 0)
136
                    {
137
                        l2 += this.countChunksZ;
138
                    }
139
140
                    int i3 = (l2 * this.countChunksY + j2) * this.countChunksX + l1;
141
                    RenderChunk renderchunk = this.renderChunks[i3];
142
                    renderchunk.setNeedsUpdate(true);
143
                }
144
            }
145
        }
146
    }
147
148
    protected RenderChunk getRenderChunk(BlockPos pos)
149
    {
150
        int i = MathHelper.bucketInt(pos.getX(), 16);
151
        int j = MathHelper.bucketInt(pos.getY(), 16);
152
        int k = MathHelper.bucketInt(pos.getZ(), 16);
153
154
        if (j >= 0 && j < this.countChunksY)
155
        {
156
            i = i % this.countChunksX;
157
158
            if (i < 0)
159
            {
160
                i += this.countChunksX;
161
            }
162
163
            k = k % this.countChunksZ;
164
165
            if (k < 0)
166
            {
167
                k += this.countChunksZ;
168
            }
169
170
            int l = (k * this.countChunksY + j) * this.countChunksX + i;
171
            return this.renderChunks[l];
172
        }
173
        else
174
        {
175
            return null;
176
        }
177
    }
178
}
179

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