BlockFluidRenderer .java

net.minecraft.client.renderer.BlockFluidRenderer (class): members: atlasSpritesWater, atlasSpritesLava, initAtlasSprites, renderFluid. imports: TextureMap.

net.minecraft.client.rendererclass298 linesclient13.6 KB

API Surface (2)

void initAtlasSprites()
boolean renderFluid(IBlockAccess blockAccess, IBlockState blockStateIn, BlockPos blockPosIn, WorldRenderer worldRendererIn)

Fields & Constants (2)

atlasSpritesLava
atlasSpritesWater

String literals (4)

"minecraft:blocks/lava_still"
"minecraft:blocks/lava_flow"
"minecraft:blocks/water_still"
"minecraft:blocks/water_flow"

Full Source

BlockFluidRenderer.java298 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.renderer;
2
3
import net.minecraft.block.BlockLiquid;
4
import net.minecraft.block.material.Material;
5
import net.minecraft.block.state.IBlockState;
6
import net.minecraft.client.Minecraft;
7
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
8
import net.minecraft.client.renderer.texture.TextureMap;
9
import net.minecraft.util.BlockPos;
10
import net.minecraft.util.EnumFacing;
11
import net.minecraft.util.MathHelper;
12
import net.minecraft.world.IBlockAccess;
13
14
public class BlockFluidRenderer
15
{
16
    private TextureAtlasSprite[] atlasSpritesLava = new TextureAtlasSprite[2];
17
    private TextureAtlasSprite[] atlasSpritesWater = new TextureAtlasSprite[2];
18
19
    public BlockFluidRenderer()
20
    {
21
        this.initAtlasSprites();
22
    }
23
24
    protected void initAtlasSprites()
25
    {
26
        TextureMap texturemap = Minecraft.getMinecraft().getTextureMapBlocks();
27
        this.atlasSpritesLava[0] = texturemap.getAtlasSprite("minecraft:blocks/lava_still");
28
        this.atlasSpritesLava[1] = texturemap.getAtlasSprite("minecraft:blocks/lava_flow");
29
        this.atlasSpritesWater[0] = texturemap.getAtlasSprite("minecraft:blocks/water_still");
30
        this.atlasSpritesWater[1] = texturemap.getAtlasSprite("minecraft:blocks/water_flow");
31
    }
32
33
    public boolean renderFluid(IBlockAccess blockAccess, IBlockState blockStateIn, BlockPos blockPosIn, WorldRenderer worldRendererIn)
34
    {
35
        BlockLiquid blockliquid = (BlockLiquid)blockStateIn.getBlock();
36
        blockliquid.setBlockBoundsBasedOnState(blockAccess, blockPosIn);
37
        TextureAtlasSprite[] atextureatlassprite = blockliquid.getMaterial() == Material.lava ? this.atlasSpritesLava : this.atlasSpritesWater;
38
        int i = blockliquid.colorMultiplier(blockAccess, blockPosIn);
39
        float f = (float)(i >> 16 & 255) / 255.0F;
40
        float f1 = (float)(i >> 8 & 255) / 255.0F;
41
        float f2 = (float)(i & 255) / 255.0F;
42
        boolean flag = blockliquid.shouldSideBeRendered(blockAccess, blockPosIn.up(), EnumFacing.UP);
43
        boolean flag1 = blockliquid.shouldSideBeRendered(blockAccess, blockPosIn.down(), EnumFacing.DOWN);
44
        boolean[] aboolean = new boolean[] {blockliquid.shouldSideBeRendered(blockAccess, blockPosIn.north(), EnumFacing.NORTH), blockliquid.shouldSideBeRendered(blockAccess, blockPosIn.south(), EnumFacing.SOUTH), blockliquid.shouldSideBeRendered(blockAccess, blockPosIn.west(), EnumFacing.WEST), blockliquid.shouldSideBeRendered(blockAccess, blockPosIn.east(), EnumFacing.EAST)};
45
46
        if (!flag && !flag1 && !aboolean[0] && !aboolean[1] && !aboolean[2] && !aboolean[3])
47
        {
48
            return false;
49
        }
50
        else
51
        {
52
            boolean flag2 = false;
53
            float f3 = 0.5F;
54
            float f4 = 1.0F;
55
            float f5 = 0.8F;
56
            float f6 = 0.6F;
57
            Material material = blockliquid.getMaterial();
58
            float f7 = this.getFluidHeight(blockAccess, blockPosIn, material);
59
            float f8 = this.getFluidHeight(blockAccess, blockPosIn.south(), material);
60
            float f9 = this.getFluidHeight(blockAccess, blockPosIn.east().south(), material);
61
            float f10 = this.getFluidHeight(blockAccess, blockPosIn.east(), material);
62
            double d0 = (double)blockPosIn.getX();
63
            double d1 = (double)blockPosIn.getY();
64
            double d2 = (double)blockPosIn.getZ();
65
            float f11 = 0.001F;
66
67
            if (flag)
68
            {
69
                flag2 = true;
70
                TextureAtlasSprite textureatlassprite = atextureatlassprite[0];
71
                float f12 = (float)BlockLiquid.getFlowDirection(blockAccess, blockPosIn, material);
72
73
                if (f12 > -999.0F)
74
                {
75
                    textureatlassprite = atextureatlassprite[1];
76
                }
77
78
                f7 -= f11;
79
                f8 -= f11;
80
                f9 -= f11;
81
                f10 -= f11;
82
                float f13;
83
                float f14;
84
                float f15;
85
                float f16;
86
                float f17;
87
                float f18;
88
                float f19;
89
                float f20;
90
91
                if (f12 < -999.0F)
92
                {
93
                    f13 = textureatlassprite.getInterpolatedU(0.0D);
94
                    f17 = textureatlassprite.getInterpolatedV(0.0D);
95
                    f14 = f13;
96
                    f18 = textureatlassprite.getInterpolatedV(16.0D);
97
                    f15 = textureatlassprite.getInterpolatedU(16.0D);
98
                    f19 = f18;
99
                    f16 = f15;
100
                    f20 = f17;
101
                }
102
                else
103
                {
104
                    float f21 = MathHelper.sin(f12) * 0.25F;
105
                    float f22 = MathHelper.cos(f12) * 0.25F;
106
                    float f23 = 8.0F;
107
                    f13 = textureatlassprite.getInterpolatedU((double)(8.0F + (-f22 - f21) * 16.0F));
108
                    f17 = textureatlassprite.getInterpolatedV((double)(8.0F + (-f22 + f21) * 16.0F));
109
                    f14 = textureatlassprite.getInterpolatedU((double)(8.0F + (-f22 + f21) * 16.0F));
110
                    f18 = textureatlassprite.getInterpolatedV((double)(8.0F + (f22 + f21) * 16.0F));
111
                    f15 = textureatlassprite.getInterpolatedU((double)(8.0F + (f22 + f21) * 16.0F));
112
                    f19 = textureatlassprite.getInterpolatedV((double)(8.0F + (f22 - f21) * 16.0F));
113
                    f16 = textureatlassprite.getInterpolatedU((double)(8.0F + (f22 - f21) * 16.0F));
114
                    f20 = textureatlassprite.getInterpolatedV((double)(8.0F + (-f22 - f21) * 16.0F));
115
                }
116
117
                int k2 = blockliquid.getMixedBrightnessForBlock(blockAccess, blockPosIn);
118
                int l2 = k2 >> 16 & 65535;
119
                int i3 = k2 & 65535;
120
                float f24 = f4 * f;
121
                float f25 = f4 * f1;
122
                float f26 = f4 * f2;
123
                worldRendererIn.pos(d0 + 0.0D, d1 + (double)f7, d2 + 0.0D).color(f24, f25, f26, 1.0F).tex((double)f13, (double)f17).lightmap(l2, i3).endVertex();
124
                worldRendererIn.pos(d0 + 0.0D, d1 + (double)f8, d2 + 1.0D).color(f24, f25, f26, 1.0F).tex((double)f14, (double)f18).lightmap(l2, i3).endVertex();
125
                worldRendererIn.pos(d0 + 1.0D, d1 + (double)f9, d2 + 1.0D).color(f24, f25, f26, 1.0F).tex((double)f15, (double)f19).lightmap(l2, i3).endVertex();
126
                worldRendererIn.pos(d0 + 1.0D, d1 + (double)f10, d2 + 0.0D).color(f24, f25, f26, 1.0F).tex((double)f16, (double)f20).lightmap(l2, i3).endVertex();
127
128
                if (blockliquid.shouldRenderSides(blockAccess, blockPosIn.up()))
129
                {
130
                    worldRendererIn.pos(d0 + 0.0D, d1 + (double)f7, d2 + 0.0D).color(f24, f25, f26, 1.0F).tex((double)f13, (double)f17).lightmap(l2, i3).endVertex();
131
                    worldRendererIn.pos(d0 + 1.0D, d1 + (double)f10, d2 + 0.0D).color(f24, f25, f26, 1.0F).tex((double)f16, (double)f20).lightmap(l2, i3).endVertex();
132
                    worldRendererIn.pos(d0 + 1.0D, d1 + (double)f9, d2 + 1.0D).color(f24, f25, f26, 1.0F).tex((double)f15, (double)f19).lightmap(l2, i3).endVertex();
133
                    worldRendererIn.pos(d0 + 0.0D, d1 + (double)f8, d2 + 1.0D).color(f24, f25, f26, 1.0F).tex((double)f14, (double)f18).lightmap(l2, i3).endVertex();
134
                }
135
            }
136
137
            if (flag1)
138
            {
139
                float f35 = atextureatlassprite[0].getMinU();
140
                float f36 = atextureatlassprite[0].getMaxU();
141
                float f37 = atextureatlassprite[0].getMinV();
142
                float f38 = atextureatlassprite[0].getMaxV();
143
                int l1 = blockliquid.getMixedBrightnessForBlock(blockAccess, blockPosIn.down());
144
                int i2 = l1 >> 16 & 65535;
145
                int j2 = l1 & 65535;
146
                worldRendererIn.pos(d0, d1, d2 + 1.0D).color(f3, f3, f3, 1.0F).tex((double)f35, (double)f38).lightmap(i2, j2).endVertex();
147
                worldRendererIn.pos(d0, d1, d2).color(f3, f3, f3, 1.0F).tex((double)f35, (double)f37).lightmap(i2, j2).endVertex();
148
                worldRendererIn.pos(d0 + 1.0D, d1, d2).color(f3, f3, f3, 1.0F).tex((double)f36, (double)f37).lightmap(i2, j2).endVertex();
149
                worldRendererIn.pos(d0 + 1.0D, d1, d2 + 1.0D).color(f3, f3, f3, 1.0F).tex((double)f36, (double)f38).lightmap(i2, j2).endVertex();
150
                flag2 = true;
151
            }
152
153
            for (int i1 = 0; i1 < 4; ++i1)
154
            {
155
                int j1 = 0;
156
                int k1 = 0;
157
158
                if (i1 == 0)
159
                {
160
                    --k1;
161
                }
162
163
                if (i1 == 1)
164
                {
165
                    ++k1;
166
                }
167
168
                if (i1 == 2)
169
                {
170
                    --j1;
171
                }
172
173
                if (i1 == 3)
174
                {
175
                    ++j1;
176
                }
177
178
                BlockPos blockpos = blockPosIn.add(j1, 0, k1);
179
                TextureAtlasSprite textureatlassprite1 = atextureatlassprite[1];
180
181
                if (aboolean[i1])
182
                {
183
                    float f39;
184
                    float f40;
185
                    double d3;
186
                    double d4;
187
                    double d5;
188
                    double d6;
189
190
                    if (i1 == 0)
191
                    {
192
                        f39 = f7;
193
                        f40 = f10;
194
                        d3 = d0;
195
                        d5 = d0 + 1.0D;
196
                        d4 = d2 + (double)f11;
197
                        d6 = d2 + (double)f11;
198
                    }
199
                    else if (i1 == 1)
200
                    {
201
                        f39 = f9;
202
                        f40 = f8;
203
                        d3 = d0 + 1.0D;
204
                        d5 = d0;
205
                        d4 = d2 + 1.0D - (double)f11;
206
                        d6 = d2 + 1.0D - (double)f11;
207
                    }
208
                    else if (i1 == 2)
209
                    {
210
                        f39 = f8;
211
                        f40 = f7;
212
                        d3 = d0 + (double)f11;
213
                        d5 = d0 + (double)f11;
214
                        d4 = d2 + 1.0D;
215
                        d6 = d2;
216
                    }
217
                    else
218
                    {
219
                        f39 = f10;
220
                        f40 = f9;
221
                        d3 = d0 + 1.0D - (double)f11;
222
                        d5 = d0 + 1.0D - (double)f11;
223
                        d4 = d2;
224
                        d6 = d2 + 1.0D;
225
                    }
226
227
                    flag2 = true;
228
                    float f41 = textureatlassprite1.getInterpolatedU(0.0D);
229
                    float f27 = textureatlassprite1.getInterpolatedU(8.0D);
230
                    float f28 = textureatlassprite1.getInterpolatedV((double)((1.0F - f39) * 16.0F * 0.5F));
231
                    float f29 = textureatlassprite1.getInterpolatedV((double)((1.0F - f40) * 16.0F * 0.5F));
232
                    float f30 = textureatlassprite1.getInterpolatedV(8.0D);
233
                    int j = blockliquid.getMixedBrightnessForBlock(blockAccess, blockpos);
234
                    int k = j >> 16 & 65535;
235
                    int l = j & 65535;
236
                    float f31 = i1 < 2 ? f5 : f6;
237
                    float f32 = f4 * f31 * f;
238
                    float f33 = f4 * f31 * f1;
239
                    float f34 = f4 * f31 * f2;
240
                    worldRendererIn.pos(d3, d1 + (double)f39, d4).color(f32, f33, f34, 1.0F).tex((double)f41, (double)f28).lightmap(k, l).endVertex();
241
                    worldRendererIn.pos(d5, d1 + (double)f40, d6).color(f32, f33, f34, 1.0F).tex((double)f27, (double)f29).lightmap(k, l).endVertex();
242
                    worldRendererIn.pos(d5, d1 + 0.0D, d6).color(f32, f33, f34, 1.0F).tex((double)f27, (double)f30).lightmap(k, l).endVertex();
243
                    worldRendererIn.pos(d3, d1 + 0.0D, d4).color(f32, f33, f34, 1.0F).tex((double)f41, (double)f30).lightmap(k, l).endVertex();
244
                    worldRendererIn.pos(d3, d1 + 0.0D, d4).color(f32, f33, f34, 1.0F).tex((double)f41, (double)f30).lightmap(k, l).endVertex();
245
                    worldRendererIn.pos(d5, d1 + 0.0D, d6).color(f32, f33, f34, 1.0F).tex((double)f27, (double)f30).lightmap(k, l).endVertex();
246
                    worldRendererIn.pos(d5, d1 + (double)f40, d6).color(f32, f33, f34, 1.0F).tex((double)f27, (double)f29).lightmap(k, l).endVertex();
247
                    worldRendererIn.pos(d3, d1 + (double)f39, d4).color(f32, f33, f34, 1.0F).tex((double)f41, (double)f28).lightmap(k, l).endVertex();
248
                }
249
            }
250
251
            return flag2;
252
        }
253
    }
254
255
    private float getFluidHeight(IBlockAccess blockAccess, BlockPos blockPosIn, Material blockMaterial)
256
    {
257
        int i = 0;
258
        float f = 0.0F;
259
260
        for (int j = 0; j < 4; ++j)
261
        {
262
            BlockPos blockpos = blockPosIn.add(-(j & 1), 0, -(j >> 1 & 1));
263
264
            if (blockAccess.getBlockState(blockpos.up()).getBlock().getMaterial() == blockMaterial)
265
            {
266
                return 1.0F;
267
            }
268
269
            IBlockState iblockstate = blockAccess.getBlockState(blockpos);
270
            Material material = iblockstate.getBlock().getMaterial();
271
272
            if (material != blockMaterial)
273
            {
274
                if (!material.isSolid())
275
                {
276
                    ++f;
277
                    ++i;
278
                }
279
            }
280
            else
281
            {
282
                int k = ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue();
283
284
                if (k >= 8 || k == 0)
285
                {
286
                    f += BlockLiquid.getLiquidHeightPercent(k) * 10.0F;
287
                    i += 10;
288
                }
289
290
                f += BlockLiquid.getLiquidHeightPercent(k);
291
                ++i;
292
            }
293
        }
294
295
        return 1.0F - f / (float)i;
296
    }
297
}
298

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