BlockLiquid .java

net.minecraft.block.BlockLiquid (class, 411 lines): members: getLiquidHeightPercent, getEffectiveFlowDecay, shouldRenderSides, triggerMixEffects, getLevel.

net.minecraft.blockclass411 linescommonextends Block13.5 KB

API Surface (31)

boolean isPassable(IBlockAccess worldIn, BlockPos pos)
int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
float getLiquidHeightPercent(int meta)
int getLevel(IBlockAccess worldIn, BlockPos pos)
int getEffectiveFlowDecay(IBlockAccess worldIn, BlockPos pos)
boolean isFullCube()
boolean isOpaqueCube()
boolean canCollideCheck(IBlockState state, boolean hitIfLiquid)
boolean isBlockSolid(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
boolean shouldRenderSides(IBlockAccess blockAccess, BlockPos pos)
AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
int getRenderType()
Item getItemDropped(IBlockState state, Random rand, int fortune)
int quantityDropped(Random random)
Vec3 getFlowVector(IBlockAccess worldIn, BlockPos pos)
Vec3 modifyAcceleration(World worldIn, BlockPos pos, Entity entityIn, Vec3 motion)
int tickRate(World worldIn)
int getMixedBrightnessForBlock(IBlockAccess worldIn, BlockPos pos)
EnumWorldBlockLayer getBlockLayer()
void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
double getFlowDirection(IBlockAccess worldIn, BlockPos pos, Material materialIn)
void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
boolean checkForMixing(World worldIn, BlockPos pos, IBlockState state)
void triggerMixEffects(World worldIn, BlockPos pos)
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()
BlockDynamicLiquid getFlowingBlock(Material materialIn)
BlockStaticLiquid getStaticBlock(Material materialIn)

Fields & Constants (1)

LEVEL

String literals (6)

"level"
"liquid.water"
"liquid.lavapop"
"liquid.lava"
"random.fizz"
"Invalid material"

Full Source

BlockLiquid.java411 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import java.util.Random;
4
import net.minecraft.block.material.Material;
5
import net.minecraft.block.properties.IProperty;
6
import net.minecraft.block.properties.PropertyInteger;
7
import net.minecraft.block.state.BlockState;
8
import net.minecraft.block.state.IBlockState;
9
import net.minecraft.entity.Entity;
10
import net.minecraft.init.Blocks;
11
import net.minecraft.item.Item;
12
import net.minecraft.util.AxisAlignedBB;
13
import net.minecraft.util.BlockPos;
14
import net.minecraft.util.EnumFacing;
15
import net.minecraft.util.EnumParticleTypes;
16
import net.minecraft.util.EnumWorldBlockLayer;
17
import net.minecraft.util.MathHelper;
18
import net.minecraft.util.Vec3;
19
import net.minecraft.world.IBlockAccess;
20
import net.minecraft.world.World;
21
import net.minecraft.world.biome.BiomeColorHelper;
22
23
public abstract class BlockLiquid extends Block
24
{
25
    public static final PropertyInteger LEVEL = PropertyInteger.create("level", 0, 15);
26
27
    protected BlockLiquid(Material materialIn)
28
    {
29
        super(materialIn);
30
        this.setDefaultState(this.blockState.getBaseState().withProperty(LEVEL, Integer.valueOf(0)));
31
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
32
        this.setTickRandomly(true);
33
    }
34
35
    public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
36
    {
37
        return this.blockMaterial != Material.lava;
38
    }
39
40
    public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
41
    {
42
        return this.blockMaterial == Material.water ? BiomeColorHelper.getWaterColorAtPos(worldIn, pos) : 16777215;
43
    }
44
45
    /**
46
     * Returns the percentage of the liquid block that is air, based on the given flow decay of the liquid
47
     */
48
    public static float getLiquidHeightPercent(int meta)
49
    {
50
        if (meta >= 8)
51
        {
52
            meta = 0;
53
        }
54
55
        return (float)(meta + 1) / 9.0F;
56
    }
57
58
    protected int getLevel(IBlockAccess worldIn, BlockPos pos)
59
    {
60
        return worldIn.getBlockState(pos).getBlock().getMaterial() == this.blockMaterial ? ((Integer)worldIn.getBlockState(pos).getValue(LEVEL)).intValue() : -1;
61
    }
62
63
    protected int getEffectiveFlowDecay(IBlockAccess worldIn, BlockPos pos)
64
    {
65
        int i = this.getLevel(worldIn, pos);
66
        return i >= 8 ? 0 : i;
67
    }
68
69
    public boolean isFullCube()
70
    {
71
        return false;
72
    }
73
74
    /**
75
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
76
     */
77
    public boolean isOpaqueCube()
78
    {
79
        return false;
80
    }
81
82
    public boolean canCollideCheck(IBlockState state, boolean hitIfLiquid)
83
    {
84
        return hitIfLiquid && ((Integer)state.getValue(LEVEL)).intValue() == 0;
85
    }
86
87
    /**
88
     * Whether this Block is solid on the given Side
89
     */
90
    public boolean isBlockSolid(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
91
    {
92
        Material material = worldIn.getBlockState(pos).getBlock().getMaterial();
93
        return material == this.blockMaterial ? false : (side == EnumFacing.UP ? true : (material == Material.ice ? false : super.isBlockSolid(worldIn, pos, side)));
94
    }
95
96
    public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
97
    {
98
        return worldIn.getBlockState(pos).getBlock().getMaterial() == this.blockMaterial ? false : (side == EnumFacing.UP ? true : super.shouldSideBeRendered(worldIn, pos, side));
99
    }
100
101
    public boolean shouldRenderSides(IBlockAccess blockAccess, BlockPos pos)
102
    {
103
        for (int i = -1; i <= 1; ++i)
104
        {
105
            for (int j = -1; j <= 1; ++j)
106
            {
107
                IBlockState iblockstate = blockAccess.getBlockState(pos.add(i, 0, j));
108
                Block block = iblockstate.getBlock();
109
                Material material = block.getMaterial();
110
111
                if (material != this.blockMaterial && !block.isFullBlock())
112
                {
113
                    return true;
114
                }
115
            }
116
        }
117
118
        return false;
119
    }
120
121
    public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
122
    {
123
        return null;
124
    }
125
126
    /**
127
     * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids, -1 is no render
128
     */
129
    public int getRenderType()
130
    {
131
        return 1;
132
    }
133
134
    /**
135
     * Get the Item that this Block should drop when harvested.
136
     */
137
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
138
    {
139
        return null;
140
    }
141
142
    /**
143
     * Returns the quantity of items to drop on block destruction.
144
     */
145
    public int quantityDropped(Random random)
146
    {
147
        return 0;
148
    }
149
150
    protected Vec3 getFlowVector(IBlockAccess worldIn, BlockPos pos)
151
    {
152
        Vec3 vec3 = new Vec3(0.0D, 0.0D, 0.0D);
153
        int i = this.getEffectiveFlowDecay(worldIn, pos);
154
155
        for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
156
        {
157
            BlockPos blockpos = pos.offset(enumfacing);
158
            int j = this.getEffectiveFlowDecay(worldIn, blockpos);
159
160
            if (j < 0)
161
            {
162
                if (!worldIn.getBlockState(blockpos).getBlock().getMaterial().blocksMovement())
163
                {
164
                    j = this.getEffectiveFlowDecay(worldIn, blockpos.down());
165
166
                    if (j >= 0)
167
                    {
168
                        int k = j - (i - 8);
169
                        vec3 = vec3.addVector((double)((blockpos.getX() - pos.getX()) * k), (double)((blockpos.getY() - pos.getY()) * k), (double)((blockpos.getZ() - pos.getZ()) * k));
170
                    }
171
                }
172
            }
173
            else if (j >= 0)
174
            {
175
                int l = j - i;
176
                vec3 = vec3.addVector((double)((blockpos.getX() - pos.getX()) * l), (double)((blockpos.getY() - pos.getY()) * l), (double)((blockpos.getZ() - pos.getZ()) * l));
177
            }
178
        }
179
180
        if (((Integer)worldIn.getBlockState(pos).getValue(LEVEL)).intValue() >= 8)
181
        {
182
            for (EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL)
183
            {
184
                BlockPos blockpos1 = pos.offset(enumfacing1);
185
186
                if (this.isBlockSolid(worldIn, blockpos1, enumfacing1) || this.isBlockSolid(worldIn, blockpos1.up(), enumfacing1))
187
                {
188
                    vec3 = vec3.normalize().addVector(0.0D, -6.0D, 0.0D);
189
                    break;
190
                }
191
            }
192
        }
193
194
        return vec3.normalize();
195
    }
196
197
    public Vec3 modifyAcceleration(World worldIn, BlockPos pos, Entity entityIn, Vec3 motion)
198
    {
199
        return motion.add(this.getFlowVector(worldIn, pos));
200
    }
201
202
    /**
203
     * How many world ticks before ticking
204
     */
205
    public int tickRate(World worldIn)
206
    {
207
        return this.blockMaterial == Material.water ? 5 : (this.blockMaterial == Material.lava ? (worldIn.provider.getHasNoSky() ? 10 : 30) : 0);
208
    }
209
210
    public int getMixedBrightnessForBlock(IBlockAccess worldIn, BlockPos pos)
211
    {
212
        int i = worldIn.getCombinedLight(pos, 0);
213
        int j = worldIn.getCombinedLight(pos.up(), 0);
214
        int k = i & 255;
215
        int l = j & 255;
216
        int i1 = i >> 16 & 255;
217
        int j1 = j >> 16 & 255;
218
        return (k > l ? k : l) | (i1 > j1 ? i1 : j1) << 16;
219
    }
220
221
    public EnumWorldBlockLayer getBlockLayer()
222
    {
223
        return this.blockMaterial == Material.water ? EnumWorldBlockLayer.TRANSLUCENT : EnumWorldBlockLayer.SOLID;
224
    }
225
226
    public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
227
    {
228
        double d0 = (double)pos.getX();
229
        double d1 = (double)pos.getY();
230
        double d2 = (double)pos.getZ();
231
232
        if (this.blockMaterial == Material.water)
233
        {
234
            int i = ((Integer)state.getValue(LEVEL)).intValue();
235
236
            if (i > 0 && i < 8)
237
            {
238
                if (rand.nextInt(64) == 0)
239
                {
240
                    worldIn.playSound(d0 + 0.5D, d1 + 0.5D, d2 + 0.5D, "liquid.water", rand.nextFloat() * 0.25F + 0.75F, rand.nextFloat() * 1.0F + 0.5F, false);
241
                }
242
            }
243
            else if (rand.nextInt(10) == 0)
244
            {
245
                worldIn.spawnParticle(EnumParticleTypes.SUSPENDED, d0 + (double)rand.nextFloat(), d1 + (double)rand.nextFloat(), d2 + (double)rand.nextFloat(), 0.0D, 0.0D, 0.0D, new int[0]);
246
            }
247
        }
248
249
        if (this.blockMaterial == Material.lava && worldIn.getBlockState(pos.up()).getBlock().getMaterial() == Material.air && !worldIn.getBlockState(pos.up()).getBlock().isOpaqueCube())
250
        {
251
            if (rand.nextInt(100) == 0)
252
            {
253
                double d8 = d0 + (double)rand.nextFloat();
254
                double d4 = d1 + this.maxY;
255
                double d6 = d2 + (double)rand.nextFloat();
256
                worldIn.spawnParticle(EnumParticleTypes.LAVA, d8, d4, d6, 0.0D, 0.0D, 0.0D, new int[0]);
257
                worldIn.playSound(d8, d4, d6, "liquid.lavapop", 0.2F + rand.nextFloat() * 0.2F, 0.9F + rand.nextFloat() * 0.15F, false);
258
            }
259
260
            if (rand.nextInt(200) == 0)
261
            {
262
                worldIn.playSound(d0, d1, d2, "liquid.lava", 0.2F + rand.nextFloat() * 0.2F, 0.9F + rand.nextFloat() * 0.15F, false);
263
            }
264
        }
265
266
        if (rand.nextInt(10) == 0 && World.doesBlockHaveSolidTopSurface(worldIn, pos.down()))
267
        {
268
            Material material = worldIn.getBlockState(pos.down(2)).getBlock().getMaterial();
269
270
            if (!material.blocksMovement() && !material.isLiquid())
271
            {
272
                double d3 = d0 + (double)rand.nextFloat();
273
                double d5 = d1 - 1.05D;
274
                double d7 = d2 + (double)rand.nextFloat();
275
276
                if (this.blockMaterial == Material.water)
277
                {
278
                    worldIn.spawnParticle(EnumParticleTypes.DRIP_WATER, d3, d5, d7, 0.0D, 0.0D, 0.0D, new int[0]);
279
                }
280
                else
281
                {
282
                    worldIn.spawnParticle(EnumParticleTypes.DRIP_LAVA, d3, d5, d7, 0.0D, 0.0D, 0.0D, new int[0]);
283
                }
284
            }
285
        }
286
    }
287
288
    public static double getFlowDirection(IBlockAccess worldIn, BlockPos pos, Material materialIn)
289
    {
290
        Vec3 vec3 = getFlowingBlock(materialIn).getFlowVector(worldIn, pos);
291
        return vec3.xCoord == 0.0D && vec3.zCoord == 0.0D ? -1000.0D : MathHelper.atan2(vec3.zCoord, vec3.xCoord) - (Math.PI / 2D);
292
    }
293
294
    public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
295
    {
296
        this.checkForMixing(worldIn, pos, state);
297
    }
298
299
    /**
300
     * Called when a neighboring block changes.
301
     */
302
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
303
    {
304
        this.checkForMixing(worldIn, pos, state);
305
    }
306
307
    public boolean checkForMixing(World worldIn, BlockPos pos, IBlockState state)
308
    {
309
        if (this.blockMaterial == Material.lava)
310
        {
311
            boolean flag = false;
312
313
            for (EnumFacing enumfacing : EnumFacing.values())
314
            {
315
                if (enumfacing != EnumFacing.DOWN && worldIn.getBlockState(pos.offset(enumfacing)).getBlock().getMaterial() == Material.water)
316
                {
317
                    flag = true;
318
                    break;
319
                }
320
            }
321
322
            if (flag)
323
            {
324
                Integer integer = (Integer)state.getValue(LEVEL);
325
326
                if (integer.intValue() == 0)
327
                {
328
                    worldIn.setBlockState(pos, Blocks.obsidian.getDefaultState());
329
                    this.triggerMixEffects(worldIn, pos);
330
                    return true;
331
                }
332
333
                if (integer.intValue() <= 4)
334
                {
335
                    worldIn.setBlockState(pos, Blocks.cobblestone.getDefaultState());
336
                    this.triggerMixEffects(worldIn, pos);
337
                    return true;
338
                }
339
            }
340
        }
341
342
        return false;
343
    }
344
345
    protected void triggerMixEffects(World worldIn, BlockPos pos)
346
    {
347
        double d0 = (double)pos.getX();
348
        double d1 = (double)pos.getY();
349
        double d2 = (double)pos.getZ();
350
        worldIn.playSoundEffect(d0 + 0.5D, d1 + 0.5D, d2 + 0.5D, "random.fizz", 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F);
351
352
        for (int i = 0; i < 8; ++i)
353
        {
354
            worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d0 + Math.random(), d1 + 1.2D, d2 + Math.random(), 0.0D, 0.0D, 0.0D, new int[0]);
355
        }
356
    }
357
358
    /**
359
     * Convert the given metadata into a BlockState for this Block
360
     */
361
    public IBlockState getStateFromMeta(int meta)
362
    {
363
        return this.getDefaultState().withProperty(LEVEL, Integer.valueOf(meta));
364
    }
365
366
    /**
367
     * Convert the BlockState into the correct metadata value
368
     */
369
    public int getMetaFromState(IBlockState state)
370
    {
371
        return ((Integer)state.getValue(LEVEL)).intValue();
372
    }
373
374
    protected BlockState createBlockState()
375
    {
376
        return new BlockState(this, new IProperty[] {LEVEL});
377
    }
378
379
    public static BlockDynamicLiquid getFlowingBlock(Material materialIn)
380
    {
381
        if (materialIn == Material.water)
382
        {
383
            return Blocks.flowing_water;
384
        }
385
        else if (materialIn == Material.lava)
386
        {
387
            return Blocks.flowing_lava;
388
        }
389
        else
390
        {
391
            throw new IllegalArgumentException("Invalid material");
392
        }
393
    }
394
395
    public static BlockStaticLiquid getStaticBlock(Material materialIn)
396
    {
397
        if (materialIn == Material.water)
398
        {
399
            return Blocks.water;
400
        }
401
        else if (materialIn == Material.lava)
402
        {
403
            return Blocks.lava;
404
        }
405
        else
406
        {
407
            throw new IllegalArgumentException("Invalid material");
408
        }
409
    }
410
}
411

Deobfuscated MCP 1.8.9 source of BlockLiquid from Marcelektro/MavenMCP-1.8.9 (net/minecraft/block/BlockLiquid.java), stored verbatim.