BlockMushroom .java

net.minecraft.block.BlockMushroom (class): members: generateBigMushroom, canPlaceBlockOn, canUseBonemeal, canGrow, grow, canBlockStay, canPlaceBlockAt.

net.minecraft.blockclass128 linescommonextends BlockBush3.9 KB

Implements

API Surface (8)

void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
boolean canPlaceBlockAt(World worldIn, BlockPos pos)
boolean canPlaceBlockOn(Block ground)
boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
boolean generateBigMushroom(World worldIn, BlockPos pos, IBlockState state, Random rand)
boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)

Full Source

BlockMushroom.java128 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import java.util.Random;
4
import net.minecraft.block.state.IBlockState;
5
import net.minecraft.init.Blocks;
6
import net.minecraft.util.BlockPos;
7
import net.minecraft.world.World;
8
import net.minecraft.world.gen.feature.WorldGenBigMushroom;
9
import net.minecraft.world.gen.feature.WorldGenerator;
10
11
public class BlockMushroom extends BlockBush implements IGrowable
12
{
13
    protected BlockMushroom()
14
    {
15
        float f = 0.2F;
16
        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 2.0F, 0.5F + f);
17
        this.setTickRandomly(true);
18
    }
19
20
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
21
    {
22
        if (rand.nextInt(25) == 0)
23
        {
24
            int i = 5;
25
            int j = 4;
26
27
            for (BlockPos blockpos : BlockPos.getAllInBoxMutable(pos.add(-4, -1, -4), pos.add(4, 1, 4)))
28
            {
29
                if (worldIn.getBlockState(blockpos).getBlock() == this)
30
                {
31
                    --i;
32
33
                    if (i <= 0)
34
                    {
35
                        return;
36
                    }
37
                }
38
            }
39
40
            BlockPos blockpos1 = pos.add(rand.nextInt(3) - 1, rand.nextInt(2) - rand.nextInt(2), rand.nextInt(3) - 1);
41
42
            for (int k = 0; k < 4; ++k)
43
            {
44
                if (worldIn.isAirBlock(blockpos1) && this.canBlockStay(worldIn, blockpos1, this.getDefaultState()))
45
                {
46
                    pos = blockpos1;
47
                }
48
49
                blockpos1 = pos.add(rand.nextInt(3) - 1, rand.nextInt(2) - rand.nextInt(2), rand.nextInt(3) - 1);
50
            }
51
52
            if (worldIn.isAirBlock(blockpos1) && this.canBlockStay(worldIn, blockpos1, this.getDefaultState()))
53
            {
54
                worldIn.setBlockState(blockpos1, this.getDefaultState(), 2);
55
            }
56
        }
57
    }
58
59
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
60
    {
61
        return super.canPlaceBlockAt(worldIn, pos) && this.canBlockStay(worldIn, pos, this.getDefaultState());
62
    }
63
64
    /**
65
     * is the block grass, dirt or farmland
66
     */
67
    protected boolean canPlaceBlockOn(Block ground)
68
    {
69
        return ground.isFullBlock();
70
    }
71
72
    public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
73
    {
74
        if (pos.getY() >= 0 && pos.getY() < 256)
75
        {
76
            IBlockState iblockstate = worldIn.getBlockState(pos.down());
77
            return iblockstate.getBlock() == Blocks.mycelium ? true : (iblockstate.getBlock() == Blocks.dirt && iblockstate.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.PODZOL ? true : worldIn.getLight(pos) < 13 && this.canPlaceBlockOn(iblockstate.getBlock()));
78
        }
79
        else
80
        {
81
            return false;
82
        }
83
    }
84
85
    public boolean generateBigMushroom(World worldIn, BlockPos pos, IBlockState state, Random rand)
86
    {
87
        worldIn.setBlockToAir(pos);
88
        WorldGenerator worldgenerator = null;
89
90
        if (this == Blocks.brown_mushroom)
91
        {
92
            worldgenerator = new WorldGenBigMushroom(Blocks.brown_mushroom_block);
93
        }
94
        else if (this == Blocks.red_mushroom)
95
        {
96
            worldgenerator = new WorldGenBigMushroom(Blocks.red_mushroom_block);
97
        }
98
99
        if (worldgenerator != null && worldgenerator.generate(worldIn, rand, pos))
100
        {
101
            return true;
102
        }
103
        else
104
        {
105
            worldIn.setBlockState(pos, state, 3);
106
            return false;
107
        }
108
    }
109
110
    /**
111
     * Whether this IGrowable can grow
112
     */
113
    public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
114
    {
115
        return true;
116
    }
117
118
    public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
119
    {
120
        return (double)rand.nextFloat() < 0.4D;
121
    }
122
123
    public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
124
    {
125
        this.generateBigMushroom(worldIn, pos, state, rand);
126
    }
127
}
128

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