BlockMycelium .java

net.minecraft.block.BlockMycelium (class, 99 lines): members: SNOWY, randomDisplayTick, getActualState, updateTick, getItemDropped, createBlockState.

net.minecraft.blockclass99 linescommonextends Block3.8 KB

API Surface (6)

IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
Item getItemDropped(IBlockState state, Random rand, int fortune)
int getMetaFromState(IBlockState state)
BlockState createBlockState()

Fields & Constants (1)

SNOWY

String literals (1)

"snowy"

Full Source

BlockMycelium.java99 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import java.util.Random;
4
import net.minecraft.block.material.MapColor;
5
import net.minecraft.block.material.Material;
6
import net.minecraft.block.properties.IProperty;
7
import net.minecraft.block.properties.PropertyBool;
8
import net.minecraft.block.state.BlockState;
9
import net.minecraft.block.state.IBlockState;
10
import net.minecraft.creativetab.CreativeTabs;
11
import net.minecraft.init.Blocks;
12
import net.minecraft.item.Item;
13
import net.minecraft.util.BlockPos;
14
import net.minecraft.util.EnumParticleTypes;
15
import net.minecraft.world.IBlockAccess;
16
import net.minecraft.world.World;
17
18
public class BlockMycelium extends Block
19
{
20
    public static final PropertyBool SNOWY = PropertyBool.create("snowy");
21
22
    protected BlockMycelium()
23
    {
24
        super(Material.grass, MapColor.purpleColor);
25
        this.setDefaultState(this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)));
26
        this.setTickRandomly(true);
27
        this.setCreativeTab(CreativeTabs.tabBlock);
28
    }
29
30
    /**
31
     * Get the actual Block state of this Block at the given position. This applies properties not visible in the
32
     * metadata, such as fence connections.
33
     */
34
    public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
35
    {
36
        Block block = worldIn.getBlockState(pos.up()).getBlock();
37
        return state.withProperty(SNOWY, Boolean.valueOf(block == Blocks.snow || block == Blocks.snow_layer));
38
    }
39
40
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
41
    {
42
        if (!worldIn.isRemote)
43
        {
44
            if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getBlock().getLightOpacity() > 2)
45
            {
46
                worldIn.setBlockState(pos, Blocks.dirt.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT));
47
            }
48
            else
49
            {
50
                if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
51
                {
52
                    for (int i = 0; i < 4; ++i)
53
                    {
54
                        BlockPos blockpos = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);
55
                        IBlockState iblockstate = worldIn.getBlockState(blockpos);
56
                        Block block = worldIn.getBlockState(blockpos.up()).getBlock();
57
58
                        if (iblockstate.getBlock() == Blocks.dirt && iblockstate.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && block.getLightOpacity() <= 2)
59
                        {
60
                            worldIn.setBlockState(blockpos, this.getDefaultState());
61
                        }
62
                    }
63
                }
64
            }
65
        }
66
    }
67
68
    public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
69
    {
70
        super.randomDisplayTick(worldIn, pos, state, rand);
71
72
        if (rand.nextInt(10) == 0)
73
        {
74
            worldIn.spawnParticle(EnumParticleTypes.TOWN_AURA, (double)((float)pos.getX() + rand.nextFloat()), (double)((float)pos.getY() + 1.1F), (double)((float)pos.getZ() + rand.nextFloat()), 0.0D, 0.0D, 0.0D, new int[0]);
75
        }
76
    }
77
78
    /**
79
     * Get the Item that this Block should drop when harvested.
80
     */
81
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
82
    {
83
        return Blocks.dirt.getItemDropped(Blocks.dirt.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT), rand, fortune);
84
    }
85
86
    /**
87
     * Convert the BlockState into the correct metadata value
88
     */
89
    public int getMetaFromState(IBlockState state)
90
    {
91
        return 0;
92
    }
93
94
    protected BlockState createBlockState()
95
    {
96
        return new BlockState(this, new IProperty[] {SNOWY});
97
    }
98
}
99

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