BlockVine .java

net.minecraft.block.BlockVine (class): members: getNumGrownFaces, getPropertyFor, ALL_FACES, UP, getBlockColor, getRenderColor, isReplaceable, NORTH, EAST.

net.minecraft.blockclass514 linescommonextends Block18.3 KB

API Surface (23)

IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
void setBlockBoundsForItemRender()
boolean isOpaqueCube()
boolean isFullCube()
boolean isReplaceable(World worldIn, BlockPos pos)
void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side)
int getBlockColor()
int getRenderColor(IBlockState state)
int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
Item getItemDropped(IBlockState state, Random rand, int fortune)
int quantityDropped(Random random)
void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
EnumWorldBlockLayer getBlockLayer()
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()
PropertyBool getPropertyFor(EnumFacing side)
int getNumGrownFaces(IBlockState state)

Fields & Constants (6)

UP
NORTH
EAST
SOUTH
WEST
ALL_FACES

String literals (5)

"north"
"east"
"south"
"west"
" is an invalid choice"

Full Source

BlockVine.java514 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.PropertyBool;
7
import net.minecraft.block.state.BlockState;
8
import net.minecraft.block.state.IBlockState;
9
import net.minecraft.creativetab.CreativeTabs;
10
import net.minecraft.entity.EntityLivingBase;
11
import net.minecraft.entity.player.EntityPlayer;
12
import net.minecraft.init.Blocks;
13
import net.minecraft.init.Items;
14
import net.minecraft.item.Item;
15
import net.minecraft.item.ItemStack;
16
import net.minecraft.stats.StatList;
17
import net.minecraft.tileentity.TileEntity;
18
import net.minecraft.util.AxisAlignedBB;
19
import net.minecraft.util.BlockPos;
20
import net.minecraft.util.EnumFacing;
21
import net.minecraft.util.EnumWorldBlockLayer;
22
import net.minecraft.world.ColorizerFoliage;
23
import net.minecraft.world.IBlockAccess;
24
import net.minecraft.world.World;
25
26
public class BlockVine extends Block
27
{
28
    public static final PropertyBool UP = PropertyBool.create("up");
29
    public static final PropertyBool NORTH = PropertyBool.create("north");
30
    public static final PropertyBool EAST = PropertyBool.create("east");
31
    public static final PropertyBool SOUTH = PropertyBool.create("south");
32
    public static final PropertyBool WEST = PropertyBool.create("west");
33
    public static final PropertyBool[] ALL_FACES = new PropertyBool[] {UP, NORTH, SOUTH, WEST, EAST};
34
35
    public BlockVine()
36
    {
37
        super(Material.vine);
38
        this.setDefaultState(this.blockState.getBaseState().withProperty(UP, Boolean.valueOf(false)).withProperty(NORTH, Boolean.valueOf(false)).withProperty(EAST, Boolean.valueOf(false)).withProperty(SOUTH, Boolean.valueOf(false)).withProperty(WEST, Boolean.valueOf(false)));
39
        this.setTickRandomly(true);
40
        this.setCreativeTab(CreativeTabs.tabDecorations);
41
    }
42
43
    /**
44
     * Get the actual Block state of this Block at the given position. This applies properties not visible in the
45
     * metadata, such as fence connections.
46
     */
47
    public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
48
    {
49
        return state.withProperty(UP, Boolean.valueOf(worldIn.getBlockState(pos.up()).getBlock().isBlockNormalCube()));
50
    }
51
52
    /**
53
     * Sets the block's bounds for rendering it as an item
54
     */
55
    public void setBlockBoundsForItemRender()
56
    {
57
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
58
    }
59
60
    /**
61
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
62
     */
63
    public boolean isOpaqueCube()
64
    {
65
        return false;
66
    }
67
68
    public boolean isFullCube()
69
    {
70
        return false;
71
    }
72
73
    /**
74
     * Whether this Block can be replaced directly by other blocks (true for e.g. tall grass)
75
     */
76
    public boolean isReplaceable(World worldIn, BlockPos pos)
77
    {
78
        return true;
79
    }
80
81
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
82
    {
83
        float f = 0.0625F;
84
        float f1 = 1.0F;
85
        float f2 = 1.0F;
86
        float f3 = 1.0F;
87
        float f4 = 0.0F;
88
        float f5 = 0.0F;
89
        float f6 = 0.0F;
90
        boolean flag = false;
91
92
        if (((Boolean)worldIn.getBlockState(pos).getValue(WEST)).booleanValue())
93
        {
94
            f4 = Math.max(f4, 0.0625F);
95
            f1 = 0.0F;
96
            f2 = 0.0F;
97
            f5 = 1.0F;
98
            f3 = 0.0F;
99
            f6 = 1.0F;
100
            flag = true;
101
        }
102
103
        if (((Boolean)worldIn.getBlockState(pos).getValue(EAST)).booleanValue())
104
        {
105
            f1 = Math.min(f1, 0.9375F);
106
            f4 = 1.0F;
107
            f2 = 0.0F;
108
            f5 = 1.0F;
109
            f3 = 0.0F;
110
            f6 = 1.0F;
111
            flag = true;
112
        }
113
114
        if (((Boolean)worldIn.getBlockState(pos).getValue(NORTH)).booleanValue())
115
        {
116
            f6 = Math.max(f6, 0.0625F);
117
            f3 = 0.0F;
118
            f1 = 0.0F;
119
            f4 = 1.0F;
120
            f2 = 0.0F;
121
            f5 = 1.0F;
122
            flag = true;
123
        }
124
125
        if (((Boolean)worldIn.getBlockState(pos).getValue(SOUTH)).booleanValue())
126
        {
127
            f3 = Math.min(f3, 0.9375F);
128
            f6 = 1.0F;
129
            f1 = 0.0F;
130
            f4 = 1.0F;
131
            f2 = 0.0F;
132
            f5 = 1.0F;
133
            flag = true;
134
        }
135
136
        if (!flag && this.canPlaceOn(worldIn.getBlockState(pos.up()).getBlock()))
137
        {
138
            f2 = Math.min(f2, 0.9375F);
139
            f5 = 1.0F;
140
            f1 = 0.0F;
141
            f4 = 1.0F;
142
            f3 = 0.0F;
143
            f6 = 1.0F;
144
        }
145
146
        this.setBlockBounds(f1, f2, f3, f4, f5, f6);
147
    }
148
149
    public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
150
    {
151
        return null;
152
    }
153
154
    /**
155
     * Check whether this Block can be placed on the given side
156
     */
157
    public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side)
158
    {
159
        switch (side)
160
        {
161
            case UP:
162
                return this.canPlaceOn(worldIn.getBlockState(pos.up()).getBlock());
163
164
            case NORTH:
165
            case SOUTH:
166
            case EAST:
167
            case WEST:
168
                return this.canPlaceOn(worldIn.getBlockState(pos.offset(side.getOpposite())).getBlock());
169
170
            default:
171
                return false;
172
        }
173
    }
174
175
    private boolean canPlaceOn(Block blockIn)
176
    {
177
        return blockIn.isFullCube() && blockIn.blockMaterial.blocksMovement();
178
    }
179
180
    private boolean recheckGrownSides(World worldIn, BlockPos pos, IBlockState state)
181
    {
182
        IBlockState iblockstate = state;
183
184
        for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
185
        {
186
            PropertyBool propertybool = getPropertyFor(enumfacing);
187
188
            if (((Boolean)state.getValue(propertybool)).booleanValue() && !this.canPlaceOn(worldIn.getBlockState(pos.offset(enumfacing)).getBlock()))
189
            {
190
                IBlockState iblockstate1 = worldIn.getBlockState(pos.up());
191
192
                if (iblockstate1.getBlock() != this || !((Boolean)iblockstate1.getValue(propertybool)).booleanValue())
193
                {
194
                    state = state.withProperty(propertybool, Boolean.valueOf(false));
195
                }
196
            }
197
        }
198
199
        if (getNumGrownFaces(state) == 0)
200
        {
201
            return false;
202
        }
203
        else
204
        {
205
            if (iblockstate != state)
206
            {
207
                worldIn.setBlockState(pos, state, 2);
208
            }
209
210
            return true;
211
        }
212
    }
213
214
    public int getBlockColor()
215
    {
216
        return ColorizerFoliage.getFoliageColorBasic();
217
    }
218
219
    public int getRenderColor(IBlockState state)
220
    {
221
        return ColorizerFoliage.getFoliageColorBasic();
222
    }
223
224
    public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
225
    {
226
        return worldIn.getBiomeGenForCoords(pos).getFoliageColorAtPos(pos);
227
    }
228
229
    /**
230
     * Called when a neighboring block changes.
231
     */
232
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
233
    {
234
        if (!worldIn.isRemote && !this.recheckGrownSides(worldIn, pos, state))
235
        {
236
            this.dropBlockAsItem(worldIn, pos, state, 0);
237
            worldIn.setBlockToAir(pos);
238
        }
239
    }
240
241
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
242
    {
243
        if (!worldIn.isRemote)
244
        {
245
            if (worldIn.rand.nextInt(4) == 0)
246
            {
247
                int i = 4;
248
                int j = 5;
249
                boolean flag = false;
250
                label62:
251
252
                for (int k = -i; k <= i; ++k)
253
                {
254
                    for (int l = -i; l <= i; ++l)
255
                    {
256
                        for (int i1 = -1; i1 <= 1; ++i1)
257
                        {
258
                            if (worldIn.getBlockState(pos.add(k, i1, l)).getBlock() == this)
259
                            {
260
                                --j;
261
262
                                if (j <= 0)
263
                                {
264
                                    flag = true;
265
                                    break label62;
266
                                }
267
                            }
268
                        }
269
                    }
270
                }
271
272
                EnumFacing enumfacing1 = EnumFacing.random(rand);
273
                BlockPos blockpos1 = pos.up();
274
275
                if (enumfacing1 == EnumFacing.UP && pos.getY() < 255 && worldIn.isAirBlock(blockpos1))
276
                {
277
                    if (!flag)
278
                    {
279
                        IBlockState iblockstate2 = state;
280
281
                        for (EnumFacing enumfacing3 : EnumFacing.Plane.HORIZONTAL)
282
                        {
283
                            if (rand.nextBoolean() || !this.canPlaceOn(worldIn.getBlockState(blockpos1.offset(enumfacing3)).getBlock()))
284
                            {
285
                                iblockstate2 = iblockstate2.withProperty(getPropertyFor(enumfacing3), Boolean.valueOf(false));
286
                            }
287
                        }
288
289
                        if (((Boolean)iblockstate2.getValue(NORTH)).booleanValue() || ((Boolean)iblockstate2.getValue(EAST)).booleanValue() || ((Boolean)iblockstate2.getValue(SOUTH)).booleanValue() || ((Boolean)iblockstate2.getValue(WEST)).booleanValue())
290
                        {
291
                            worldIn.setBlockState(blockpos1, iblockstate2, 2);
292
                        }
293
                    }
294
                }
295
                else if (enumfacing1.getAxis().isHorizontal() && !((Boolean)state.getValue(getPropertyFor(enumfacing1))).booleanValue())
296
                {
297
                    if (!flag)
298
                    {
299
                        BlockPos blockpos3 = pos.offset(enumfacing1);
300
                        Block block1 = worldIn.getBlockState(blockpos3).getBlock();
301
302
                        if (block1.blockMaterial == Material.air)
303
                        {
304
                            EnumFacing enumfacing2 = enumfacing1.rotateY();
305
                            EnumFacing enumfacing4 = enumfacing1.rotateYCCW();
306
                            boolean flag1 = ((Boolean)state.getValue(getPropertyFor(enumfacing2))).booleanValue();
307
                            boolean flag2 = ((Boolean)state.getValue(getPropertyFor(enumfacing4))).booleanValue();
308
                            BlockPos blockpos4 = blockpos3.offset(enumfacing2);
309
                            BlockPos blockpos = blockpos3.offset(enumfacing4);
310
311
                            if (flag1 && this.canPlaceOn(worldIn.getBlockState(blockpos4).getBlock()))
312
                            {
313
                                worldIn.setBlockState(blockpos3, this.getDefaultState().withProperty(getPropertyFor(enumfacing2), Boolean.valueOf(true)), 2);
314
                            }
315
                            else if (flag2 && this.canPlaceOn(worldIn.getBlockState(blockpos).getBlock()))
316
                            {
317
                                worldIn.setBlockState(blockpos3, this.getDefaultState().withProperty(getPropertyFor(enumfacing4), Boolean.valueOf(true)), 2);
318
                            }
319
                            else if (flag1 && worldIn.isAirBlock(blockpos4) && this.canPlaceOn(worldIn.getBlockState(pos.offset(enumfacing2)).getBlock()))
320
                            {
321
                                worldIn.setBlockState(blockpos4, this.getDefaultState().withProperty(getPropertyFor(enumfacing1.getOpposite()), Boolean.valueOf(true)), 2);
322
                            }
323
                            else if (flag2 && worldIn.isAirBlock(blockpos) && this.canPlaceOn(worldIn.getBlockState(pos.offset(enumfacing4)).getBlock()))
324
                            {
325
                                worldIn.setBlockState(blockpos, this.getDefaultState().withProperty(getPropertyFor(enumfacing1.getOpposite()), Boolean.valueOf(true)), 2);
326
                            }
327
                            else if (this.canPlaceOn(worldIn.getBlockState(blockpos3.up()).getBlock()))
328
                            {
329
                                worldIn.setBlockState(blockpos3, this.getDefaultState(), 2);
330
                            }
331
                        }
332
                        else if (block1.blockMaterial.isOpaque() && block1.isFullCube())
333
                        {
334
                            worldIn.setBlockState(pos, state.withProperty(getPropertyFor(enumfacing1), Boolean.valueOf(true)), 2);
335
                        }
336
                    }
337
                }
338
                else
339
                {
340
                    if (pos.getY() > 1)
341
                    {
342
                        BlockPos blockpos2 = pos.down();
343
                        IBlockState iblockstate = worldIn.getBlockState(blockpos2);
344
                        Block block = iblockstate.getBlock();
345
346
                        if (block.blockMaterial == Material.air)
347
                        {
348
                            IBlockState iblockstate1 = state;
349
350
                            for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
351
                            {
352
                                if (rand.nextBoolean())
353
                                {
354
                                    iblockstate1 = iblockstate1.withProperty(getPropertyFor(enumfacing), Boolean.valueOf(false));
355
                                }
356
                            }
357
358
                            if (((Boolean)iblockstate1.getValue(NORTH)).booleanValue() || ((Boolean)iblockstate1.getValue(EAST)).booleanValue() || ((Boolean)iblockstate1.getValue(SOUTH)).booleanValue() || ((Boolean)iblockstate1.getValue(WEST)).booleanValue())
359
                            {
360
                                worldIn.setBlockState(blockpos2, iblockstate1, 2);
361
                            }
362
                        }
363
                        else if (block == this)
364
                        {
365
                            IBlockState iblockstate3 = iblockstate;
366
367
                            for (EnumFacing enumfacing5 : EnumFacing.Plane.HORIZONTAL)
368
                            {
369
                                PropertyBool propertybool = getPropertyFor(enumfacing5);
370
371
                                if (rand.nextBoolean() && ((Boolean)state.getValue(propertybool)).booleanValue())
372
                                {
373
                                    iblockstate3 = iblockstate3.withProperty(propertybool, Boolean.valueOf(true));
374
                                }
375
                            }
376
377
                            if (((Boolean)iblockstate3.getValue(NORTH)).booleanValue() || ((Boolean)iblockstate3.getValue(EAST)).booleanValue() || ((Boolean)iblockstate3.getValue(SOUTH)).booleanValue() || ((Boolean)iblockstate3.getValue(WEST)).booleanValue())
378
                            {
379
                                worldIn.setBlockState(blockpos2, iblockstate3, 2);
380
                            }
381
                        }
382
                    }
383
                }
384
            }
385
        }
386
    }
387
388
    /**
389
     * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
390
     * IBlockstate
391
     */
392
    public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
393
    {
394
        IBlockState iblockstate = this.getDefaultState().withProperty(UP, Boolean.valueOf(false)).withProperty(NORTH, Boolean.valueOf(false)).withProperty(EAST, Boolean.valueOf(false)).withProperty(SOUTH, Boolean.valueOf(false)).withProperty(WEST, Boolean.valueOf(false));
395
        return facing.getAxis().isHorizontal() ? iblockstate.withProperty(getPropertyFor(facing.getOpposite()), Boolean.valueOf(true)) : iblockstate;
396
    }
397
398
    /**
399
     * Get the Item that this Block should drop when harvested.
400
     */
401
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
402
    {
403
        return null;
404
    }
405
406
    /**
407
     * Returns the quantity of items to drop on block destruction.
408
     */
409
    public int quantityDropped(Random random)
410
    {
411
        return 0;
412
    }
413
414
    public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
415
    {
416
        if (!worldIn.isRemote && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears)
417
        {
418
            player.triggerAchievement(StatList.mineBlockStatArray[Block.getIdFromBlock(this)]);
419
            spawnAsEntity(worldIn, pos, new ItemStack(Blocks.vine, 1, 0));
420
        }
421
        else
422
        {
423
            super.harvestBlock(worldIn, player, pos, state, te);
424
        }
425
    }
426
427
    public EnumWorldBlockLayer getBlockLayer()
428
    {
429
        return EnumWorldBlockLayer.CUTOUT;
430
    }
431
432
    /**
433
     * Convert the given metadata into a BlockState for this Block
434
     */
435
    public IBlockState getStateFromMeta(int meta)
436
    {
437
        return this.getDefaultState().withProperty(SOUTH, Boolean.valueOf((meta & 1) > 0)).withProperty(WEST, Boolean.valueOf((meta & 2) > 0)).withProperty(NORTH, Boolean.valueOf((meta & 4) > 0)).withProperty(EAST, Boolean.valueOf((meta & 8) > 0));
438
    }
439
440
    /**
441
     * Convert the BlockState into the correct metadata value
442
     */
443
    public int getMetaFromState(IBlockState state)
444
    {
445
        int i = 0;
446
447
        if (((Boolean)state.getValue(SOUTH)).booleanValue())
448
        {
449
            i |= 1;
450
        }
451
452
        if (((Boolean)state.getValue(WEST)).booleanValue())
453
        {
454
            i |= 2;
455
        }
456
457
        if (((Boolean)state.getValue(NORTH)).booleanValue())
458
        {
459
            i |= 4;
460
        }
461
462
        if (((Boolean)state.getValue(EAST)).booleanValue())
463
        {
464
            i |= 8;
465
        }
466
467
        return i;
468
    }
469
470
    protected BlockState createBlockState()
471
    {
472
        return new BlockState(this, new IProperty[] {UP, NORTH, EAST, SOUTH, WEST});
473
    }
474
475
    public static PropertyBool getPropertyFor(EnumFacing side)
476
    {
477
        switch (side)
478
        {
479
            case UP:
480
                return UP;
481
482
            case NORTH:
483
                return NORTH;
484
485
            case SOUTH:
486
                return SOUTH;
487
488
            case EAST:
489
                return EAST;
490
491
            case WEST:
492
                return WEST;
493
494
            default:
495
                throw new IllegalArgumentException(side + " is an invalid choice");
496
        }
497
    }
498
499
    public static int getNumGrownFaces(IBlockState state)
500
    {
501
        int i = 0;
502
503
        for (PropertyBool propertybool : ALL_FACES)
504
        {
505
            if (((Boolean)state.getValue(propertybool)).booleanValue())
506
            {
507
                ++i;
508
            }
509
        }
510
511
        return i;
512
    }
513
}
514

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