BlockFire .java

net.minecraft.block.BlockFire (class, 507 lines): members: encouragements, flammabilities, canCatchFire, setFireInfo, canDie, UPPER, FLIP, ALT, AGE, NORTH.

net.minecraft.blockclass507 linescommonextends Block18.7 KB

API Surface (22)

IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
void init()
void setFireInfo(Block blockIn, int encouragement, int flammability)
AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
boolean isOpaqueCube()
boolean isFullCube()
int quantityDropped(Random random)
int tickRate(World worldIn)
void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
boolean canDie(World worldIn, BlockPos pos)
boolean requiresUpdates()
boolean isCollidable()
boolean canCatchFire(IBlockAccess worldIn, BlockPos pos)
boolean canPlaceBlockAt(World worldIn, BlockPos pos)
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
MapColor getMapColor(IBlockState state)
EnumWorldBlockLayer getBlockLayer()
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()

Fields & Constants (10)

AGE
FLIP
ALT
NORTH
EAST
SOUTH
WEST
UPPER
encouragements
flammabilities

String literals (8)

"flip"
"north"
"east"
"south"
"west"
"upper"
"doFireTick"
"fire.fire"

Full Source

BlockFire.java507 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import com.google.common.collect.Maps;
4
import java.util.Map;
5
import java.util.Random;
6
import net.minecraft.block.material.MapColor;
7
import net.minecraft.block.material.Material;
8
import net.minecraft.block.properties.IProperty;
9
import net.minecraft.block.properties.PropertyBool;
10
import net.minecraft.block.properties.PropertyInteger;
11
import net.minecraft.block.state.BlockState;
12
import net.minecraft.block.state.IBlockState;
13
import net.minecraft.init.Blocks;
14
import net.minecraft.util.AxisAlignedBB;
15
import net.minecraft.util.BlockPos;
16
import net.minecraft.util.EnumFacing;
17
import net.minecraft.util.EnumParticleTypes;
18
import net.minecraft.util.EnumWorldBlockLayer;
19
import net.minecraft.world.IBlockAccess;
20
import net.minecraft.world.World;
21
import net.minecraft.world.WorldProviderEnd;
22
23
public class BlockFire extends Block
24
{
25
    public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 15);
26
    public static final PropertyBool FLIP = PropertyBool.create("flip");
27
    public static final PropertyBool ALT = PropertyBool.create("alt");
28
    public static final PropertyBool NORTH = PropertyBool.create("north");
29
    public static final PropertyBool EAST = PropertyBool.create("east");
30
    public static final PropertyBool SOUTH = PropertyBool.create("south");
31
    public static final PropertyBool WEST = PropertyBool.create("west");
32
    public static final PropertyInteger UPPER = PropertyInteger.create("upper", 0, 2);
33
    private final Map<Block, Integer> encouragements = Maps.<Block, Integer>newIdentityHashMap();
34
    private final Map<Block, Integer> flammabilities = Maps.<Block, Integer>newIdentityHashMap();
35
36
    /**
37
     * Get the actual Block state of this Block at the given position. This applies properties not visible in the
38
     * metadata, such as fence connections.
39
     */
40
    public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
41
    {
42
        int i = pos.getX();
43
        int j = pos.getY();
44
        int k = pos.getZ();
45
46
        if (!World.doesBlockHaveSolidTopSurface(worldIn, pos.down()) && !Blocks.fire.canCatchFire(worldIn, pos.down()))
47
        {
48
            boolean flag = (i + j + k & 1) == 1;
49
            boolean flag1 = (i / 2 + j / 2 + k / 2 & 1) == 1;
50
            int l = 0;
51
52
            if (this.canCatchFire(worldIn, pos.up()))
53
            {
54
                l = flag ? 1 : 2;
55
            }
56
57
            return state.withProperty(NORTH, Boolean.valueOf(this.canCatchFire(worldIn, pos.north()))).withProperty(EAST, Boolean.valueOf(this.canCatchFire(worldIn, pos.east()))).withProperty(SOUTH, Boolean.valueOf(this.canCatchFire(worldIn, pos.south()))).withProperty(WEST, Boolean.valueOf(this.canCatchFire(worldIn, pos.west()))).withProperty(UPPER, Integer.valueOf(l)).withProperty(FLIP, Boolean.valueOf(flag1)).withProperty(ALT, Boolean.valueOf(flag));
58
        }
59
        else
60
        {
61
            return this.getDefaultState();
62
        }
63
    }
64
65
    protected BlockFire()
66
    {
67
        super(Material.fire);
68
        this.setDefaultState(this.blockState.getBaseState().withProperty(AGE, Integer.valueOf(0)).withProperty(FLIP, Boolean.valueOf(false)).withProperty(ALT, Boolean.valueOf(false)).withProperty(NORTH, Boolean.valueOf(false)).withProperty(EAST, Boolean.valueOf(false)).withProperty(SOUTH, Boolean.valueOf(false)).withProperty(WEST, Boolean.valueOf(false)).withProperty(UPPER, Integer.valueOf(0)));
69
        this.setTickRandomly(true);
70
    }
71
72
    public static void init()
73
    {
74
        Blocks.fire.setFireInfo(Blocks.planks, 5, 20);
75
        Blocks.fire.setFireInfo(Blocks.double_wooden_slab, 5, 20);
76
        Blocks.fire.setFireInfo(Blocks.wooden_slab, 5, 20);
77
        Blocks.fire.setFireInfo(Blocks.oak_fence_gate, 5, 20);
78
        Blocks.fire.setFireInfo(Blocks.spruce_fence_gate, 5, 20);
79
        Blocks.fire.setFireInfo(Blocks.birch_fence_gate, 5, 20);
80
        Blocks.fire.setFireInfo(Blocks.jungle_fence_gate, 5, 20);
81
        Blocks.fire.setFireInfo(Blocks.dark_oak_fence_gate, 5, 20);
82
        Blocks.fire.setFireInfo(Blocks.acacia_fence_gate, 5, 20);
83
        Blocks.fire.setFireInfo(Blocks.oak_fence, 5, 20);
84
        Blocks.fire.setFireInfo(Blocks.spruce_fence, 5, 20);
85
        Blocks.fire.setFireInfo(Blocks.birch_fence, 5, 20);
86
        Blocks.fire.setFireInfo(Blocks.jungle_fence, 5, 20);
87
        Blocks.fire.setFireInfo(Blocks.dark_oak_fence, 5, 20);
88
        Blocks.fire.setFireInfo(Blocks.acacia_fence, 5, 20);
89
        Blocks.fire.setFireInfo(Blocks.oak_stairs, 5, 20);
90
        Blocks.fire.setFireInfo(Blocks.birch_stairs, 5, 20);
91
        Blocks.fire.setFireInfo(Blocks.spruce_stairs, 5, 20);
92
        Blocks.fire.setFireInfo(Blocks.jungle_stairs, 5, 20);
93
        Blocks.fire.setFireInfo(Blocks.log, 5, 5);
94
        Blocks.fire.setFireInfo(Blocks.log2, 5, 5);
95
        Blocks.fire.setFireInfo(Blocks.leaves, 30, 60);
96
        Blocks.fire.setFireInfo(Blocks.leaves2, 30, 60);
97
        Blocks.fire.setFireInfo(Blocks.bookshelf, 30, 20);
98
        Blocks.fire.setFireInfo(Blocks.tnt, 15, 100);
99
        Blocks.fire.setFireInfo(Blocks.tallgrass, 60, 100);
100
        Blocks.fire.setFireInfo(Blocks.double_plant, 60, 100);
101
        Blocks.fire.setFireInfo(Blocks.yellow_flower, 60, 100);
102
        Blocks.fire.setFireInfo(Blocks.red_flower, 60, 100);
103
        Blocks.fire.setFireInfo(Blocks.deadbush, 60, 100);
104
        Blocks.fire.setFireInfo(Blocks.wool, 30, 60);
105
        Blocks.fire.setFireInfo(Blocks.vine, 15, 100);
106
        Blocks.fire.setFireInfo(Blocks.coal_block, 5, 5);
107
        Blocks.fire.setFireInfo(Blocks.hay_block, 60, 20);
108
        Blocks.fire.setFireInfo(Blocks.carpet, 60, 20);
109
    }
110
111
    public void setFireInfo(Block blockIn, int encouragement, int flammability)
112
    {
113
        this.encouragements.put(blockIn, Integer.valueOf(encouragement));
114
        this.flammabilities.put(blockIn, Integer.valueOf(flammability));
115
    }
116
117
    public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
118
    {
119
        return null;
120
    }
121
122
    /**
123
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
124
     */
125
    public boolean isOpaqueCube()
126
    {
127
        return false;
128
    }
129
130
    public boolean isFullCube()
131
    {
132
        return false;
133
    }
134
135
    /**
136
     * Returns the quantity of items to drop on block destruction.
137
     */
138
    public int quantityDropped(Random random)
139
    {
140
        return 0;
141
    }
142
143
    /**
144
     * How many world ticks before ticking
145
     */
146
    public int tickRate(World worldIn)
147
    {
148
        return 30;
149
    }
150
151
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
152
    {
153
        if (worldIn.getGameRules().getBoolean("doFireTick"))
154
        {
155
            if (!this.canPlaceBlockAt(worldIn, pos))
156
            {
157
                worldIn.setBlockToAir(pos);
158
            }
159
160
            Block block = worldIn.getBlockState(pos.down()).getBlock();
161
            boolean flag = block == Blocks.netherrack;
162
163
            if (worldIn.provider instanceof WorldProviderEnd && block == Blocks.bedrock)
164
            {
165
                flag = true;
166
            }
167
168
            if (!flag && worldIn.isRaining() && this.canDie(worldIn, pos))
169
            {
170
                worldIn.setBlockToAir(pos);
171
            }
172
            else
173
            {
174
                int i = ((Integer)state.getValue(AGE)).intValue();
175
176
                if (i < 15)
177
                {
178
                    state = state.withProperty(AGE, Integer.valueOf(i + rand.nextInt(3) / 2));
179
                    worldIn.setBlockState(pos, state, 4);
180
                }
181
182
                worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn) + rand.nextInt(10));
183
184
                if (!flag)
185
                {
186
                    if (!this.canNeighborCatchFire(worldIn, pos))
187
                    {
188
                        if (!World.doesBlockHaveSolidTopSurface(worldIn, pos.down()) || i > 3)
189
                        {
190
                            worldIn.setBlockToAir(pos);
191
                        }
192
193
                        return;
194
                    }
195
196
                    if (!this.canCatchFire(worldIn, pos.down()) && i == 15 && rand.nextInt(4) == 0)
197
                    {
198
                        worldIn.setBlockToAir(pos);
199
                        return;
200
                    }
201
                }
202
203
                boolean flag1 = worldIn.isBlockinHighHumidity(pos);
204
                int j = 0;
205
206
                if (flag1)
207
                {
208
                    j = -50;
209
                }
210
211
                this.catchOnFire(worldIn, pos.east(), 300 + j, rand, i);
212
                this.catchOnFire(worldIn, pos.west(), 300 + j, rand, i);
213
                this.catchOnFire(worldIn, pos.down(), 250 + j, rand, i);
214
                this.catchOnFire(worldIn, pos.up(), 250 + j, rand, i);
215
                this.catchOnFire(worldIn, pos.north(), 300 + j, rand, i);
216
                this.catchOnFire(worldIn, pos.south(), 300 + j, rand, i);
217
218
                for (int k = -1; k <= 1; ++k)
219
                {
220
                    for (int l = -1; l <= 1; ++l)
221
                    {
222
                        for (int i1 = -1; i1 <= 4; ++i1)
223
                        {
224
                            if (k != 0 || i1 != 0 || l != 0)
225
                            {
226
                                int j1 = 100;
227
228
                                if (i1 > 1)
229
                                {
230
                                    j1 += (i1 - 1) * 100;
231
                                }
232
233
                                BlockPos blockpos = pos.add(k, i1, l);
234
                                int k1 = this.getNeighborEncouragement(worldIn, blockpos);
235
236
                                if (k1 > 0)
237
                                {
238
                                    int l1 = (k1 + 40 + worldIn.getDifficulty().getDifficultyId() * 7) / (i + 30);
239
240
                                    if (flag1)
241
                                    {
242
                                        l1 /= 2;
243
                                    }
244
245
                                    if (l1 > 0 && rand.nextInt(j1) <= l1 && (!worldIn.isRaining() || !this.canDie(worldIn, blockpos)))
246
                                    {
247
                                        int i2 = i + rand.nextInt(5) / 4;
248
249
                                        if (i2 > 15)
250
                                        {
251
                                            i2 = 15;
252
                                        }
253
254
                                        worldIn.setBlockState(blockpos, state.withProperty(AGE, Integer.valueOf(i2)), 3);
255
                                    }
256
                                }
257
                            }
258
                        }
259
                    }
260
                }
261
            }
262
        }
263
    }
264
265
    protected boolean canDie(World worldIn, BlockPos pos)
266
    {
267
        return worldIn.isRainingAt(pos) || worldIn.isRainingAt(pos.west()) || worldIn.isRainingAt(pos.east()) || worldIn.isRainingAt(pos.north()) || worldIn.isRainingAt(pos.south());
268
    }
269
270
    public boolean requiresUpdates()
271
    {
272
        return false;
273
    }
274
275
    private int getFlammability(Block blockIn)
276
    {
277
        Integer integer = (Integer)this.flammabilities.get(blockIn);
278
        return integer == null ? 0 : integer.intValue();
279
    }
280
281
    private int getEncouragement(Block blockIn)
282
    {
283
        Integer integer = (Integer)this.encouragements.get(blockIn);
284
        return integer == null ? 0 : integer.intValue();
285
    }
286
287
    private void catchOnFire(World worldIn, BlockPos pos, int chance, Random random, int age)
288
    {
289
        int i = this.getFlammability(worldIn.getBlockState(pos).getBlock());
290
291
        if (random.nextInt(chance) < i)
292
        {
293
            IBlockState iblockstate = worldIn.getBlockState(pos);
294
295
            if (random.nextInt(age + 10) < 5 && !worldIn.isRainingAt(pos))
296
            {
297
                int j = age + random.nextInt(5) / 4;
298
299
                if (j > 15)
300
                {
301
                    j = 15;
302
                }
303
304
                worldIn.setBlockState(pos, this.getDefaultState().withProperty(AGE, Integer.valueOf(j)), 3);
305
            }
306
            else
307
            {
308
                worldIn.setBlockToAir(pos);
309
            }
310
311
            if (iblockstate.getBlock() == Blocks.tnt)
312
            {
313
                Blocks.tnt.onBlockDestroyedByPlayer(worldIn, pos, iblockstate.withProperty(BlockTNT.EXPLODE, Boolean.valueOf(true)));
314
            }
315
        }
316
    }
317
318
    private boolean canNeighborCatchFire(World worldIn, BlockPos pos)
319
    {
320
        for (EnumFacing enumfacing : EnumFacing.values())
321
        {
322
            if (this.canCatchFire(worldIn, pos.offset(enumfacing)))
323
            {
324
                return true;
325
            }
326
        }
327
328
        return false;
329
    }
330
331
    private int getNeighborEncouragement(World worldIn, BlockPos pos)
332
    {
333
        if (!worldIn.isAirBlock(pos))
334
        {
335
            return 0;
336
        }
337
        else
338
        {
339
            int i = 0;
340
341
            for (EnumFacing enumfacing : EnumFacing.values())
342
            {
343
                i = Math.max(this.getEncouragement(worldIn.getBlockState(pos.offset(enumfacing)).getBlock()), i);
344
            }
345
346
            return i;
347
        }
348
    }
349
350
    /**
351
     * Returns if this block is collidable (only used by Fire). Args: x, y, z
352
     */
353
    public boolean isCollidable()
354
    {
355
        return false;
356
    }
357
358
    /**
359
     * Checks if the block can be caught on fire
360
     */
361
    public boolean canCatchFire(IBlockAccess worldIn, BlockPos pos)
362
    {
363
        return this.getEncouragement(worldIn.getBlockState(pos).getBlock()) > 0;
364
    }
365
366
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
367
    {
368
        return World.doesBlockHaveSolidTopSurface(worldIn, pos.down()) || this.canNeighborCatchFire(worldIn, pos);
369
    }
370
371
    /**
372
     * Called when a neighboring block changes.
373
     */
374
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
375
    {
376
        if (!World.doesBlockHaveSolidTopSurface(worldIn, pos.down()) && !this.canNeighborCatchFire(worldIn, pos))
377
        {
378
            worldIn.setBlockToAir(pos);
379
        }
380
    }
381
382
    public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
383
    {
384
        if (worldIn.provider.getDimensionId() > 0 || !Blocks.portal.func_176548_d(worldIn, pos))
385
        {
386
            if (!World.doesBlockHaveSolidTopSurface(worldIn, pos.down()) && !this.canNeighborCatchFire(worldIn, pos))
387
            {
388
                worldIn.setBlockToAir(pos);
389
            }
390
            else
391
            {
392
                worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn) + worldIn.rand.nextInt(10));
393
            }
394
        }
395
    }
396
397
    public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
398
    {
399
        if (rand.nextInt(24) == 0)
400
        {
401
            worldIn.playSound((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), "fire.fire", 1.0F + rand.nextFloat(), rand.nextFloat() * 0.7F + 0.3F, false);
402
        }
403
404
        if (!World.doesBlockHaveSolidTopSurface(worldIn, pos.down()) && !Blocks.fire.canCatchFire(worldIn, pos.down()))
405
        {
406
            if (Blocks.fire.canCatchFire(worldIn, pos.west()))
407
            {
408
                for (int j = 0; j < 2; ++j)
409
                {
410
                    double d3 = (double)pos.getX() + rand.nextDouble() * 0.10000000149011612D;
411
                    double d8 = (double)pos.getY() + rand.nextDouble();
412
                    double d13 = (double)pos.getZ() + rand.nextDouble();
413
                    worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d3, d8, d13, 0.0D, 0.0D, 0.0D, new int[0]);
414
                }
415
            }
416
417
            if (Blocks.fire.canCatchFire(worldIn, pos.east()))
418
            {
419
                for (int k = 0; k < 2; ++k)
420
                {
421
                    double d4 = (double)(pos.getX() + 1) - rand.nextDouble() * 0.10000000149011612D;
422
                    double d9 = (double)pos.getY() + rand.nextDouble();
423
                    double d14 = (double)pos.getZ() + rand.nextDouble();
424
                    worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d4, d9, d14, 0.0D, 0.0D, 0.0D, new int[0]);
425
                }
426
            }
427
428
            if (Blocks.fire.canCatchFire(worldIn, pos.north()))
429
            {
430
                for (int l = 0; l < 2; ++l)
431
                {
432
                    double d5 = (double)pos.getX() + rand.nextDouble();
433
                    double d10 = (double)pos.getY() + rand.nextDouble();
434
                    double d15 = (double)pos.getZ() + rand.nextDouble() * 0.10000000149011612D;
435
                    worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d5, d10, d15, 0.0D, 0.0D, 0.0D, new int[0]);
436
                }
437
            }
438
439
            if (Blocks.fire.canCatchFire(worldIn, pos.south()))
440
            {
441
                for (int i1 = 0; i1 < 2; ++i1)
442
                {
443
                    double d6 = (double)pos.getX() + rand.nextDouble();
444
                    double d11 = (double)pos.getY() + rand.nextDouble();
445
                    double d16 = (double)(pos.getZ() + 1) - rand.nextDouble() * 0.10000000149011612D;
446
                    worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d6, d11, d16, 0.0D, 0.0D, 0.0D, new int[0]);
447
                }
448
            }
449
450
            if (Blocks.fire.canCatchFire(worldIn, pos.up()))
451
            {
452
                for (int j1 = 0; j1 < 2; ++j1)
453
                {
454
                    double d7 = (double)pos.getX() + rand.nextDouble();
455
                    double d12 = (double)(pos.getY() + 1) - rand.nextDouble() * 0.10000000149011612D;
456
                    double d17 = (double)pos.getZ() + rand.nextDouble();
457
                    worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d7, d12, d17, 0.0D, 0.0D, 0.0D, new int[0]);
458
                }
459
            }
460
        }
461
        else
462
        {
463
            for (int i = 0; i < 3; ++i)
464
            {
465
                double d0 = (double)pos.getX() + rand.nextDouble();
466
                double d1 = (double)pos.getY() + rand.nextDouble() * 0.5D + 0.5D;
467
                double d2 = (double)pos.getZ() + rand.nextDouble();
468
                worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d0, d1, d2, 0.0D, 0.0D, 0.0D, new int[0]);
469
            }
470
        }
471
    }
472
473
    /**
474
     * Get the MapColor for this Block and the given BlockState
475
     */
476
    public MapColor getMapColor(IBlockState state)
477
    {
478
        return MapColor.tntColor;
479
    }
480
481
    public EnumWorldBlockLayer getBlockLayer()
482
    {
483
        return EnumWorldBlockLayer.CUTOUT;
484
    }
485
486
    /**
487
     * Convert the given metadata into a BlockState for this Block
488
     */
489
    public IBlockState getStateFromMeta(int meta)
490
    {
491
        return this.getDefaultState().withProperty(AGE, Integer.valueOf(meta));
492
    }
493
494
    /**
495
     * Convert the BlockState into the correct metadata value
496
     */
497
    public int getMetaFromState(IBlockState state)
498
    {
499
        return ((Integer)state.getValue(AGE)).intValue();
500
    }
501
502
    protected BlockState createBlockState()
503
    {
504
        return new BlockState(this, new IProperty[] {AGE, NORTH, EAST, SOUTH, WEST, UPPER, FLIP, ALT});
505
    }
506
}
507

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