BlockReed .java

net.minecraft.block.BlockReed (class): members: checkForDrop, AGE, canBlockStay, colorMultiplier, canPlaceBlockAt, getBlockLayer, getItem, updateTick.

net.minecraft.blockclass178 linescommonextends Block4.9 KB

API Surface (15)

void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
boolean canPlaceBlockAt(World worldIn, BlockPos pos)
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
boolean checkForDrop(World worldIn, BlockPos pos, IBlockState state)
boolean canBlockStay(World worldIn, BlockPos pos)
AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
Item getItemDropped(IBlockState state, Random rand, int fortune)
boolean isOpaqueCube()
boolean isFullCube()
Item getItem(World worldIn, BlockPos pos)
int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
EnumWorldBlockLayer getBlockLayer()
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()

Fields & Constants (1)

AGE

Full Source

BlockReed.java178 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.init.Blocks;
10
import net.minecraft.init.Items;
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.EnumWorldBlockLayer;
16
import net.minecraft.world.IBlockAccess;
17
import net.minecraft.world.World;
18
19
public class BlockReed extends Block
20
{
21
    public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 15);
22
23
    protected BlockReed()
24
    {
25
        super(Material.plants);
26
        this.setDefaultState(this.blockState.getBaseState().withProperty(AGE, Integer.valueOf(0)));
27
        float f = 0.375F;
28
        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 1.0F, 0.5F + f);
29
        this.setTickRandomly(true);
30
    }
31
32
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
33
    {
34
        if (worldIn.getBlockState(pos.down()).getBlock() == Blocks.reeds || this.checkForDrop(worldIn, pos, state))
35
        {
36
            if (worldIn.isAirBlock(pos.up()))
37
            {
38
                int i;
39
40
                for (i = 1; worldIn.getBlockState(pos.down(i)).getBlock() == this; ++i)
41
                {
42
                    ;
43
                }
44
45
                if (i < 3)
46
                {
47
                    int j = ((Integer)state.getValue(AGE)).intValue();
48
49
                    if (j == 15)
50
                    {
51
                        worldIn.setBlockState(pos.up(), this.getDefaultState());
52
                        worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(0)), 4);
53
                    }
54
                    else
55
                    {
56
                        worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(j + 1)), 4);
57
                    }
58
                }
59
            }
60
        }
61
    }
62
63
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
64
    {
65
        Block block = worldIn.getBlockState(pos.down()).getBlock();
66
67
        if (block == this)
68
        {
69
            return true;
70
        }
71
        else if (block != Blocks.grass && block != Blocks.dirt && block != Blocks.sand)
72
        {
73
            return false;
74
        }
75
        else
76
        {
77
            for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
78
            {
79
                if (worldIn.getBlockState(pos.offset(enumfacing).down()).getBlock().getMaterial() == Material.water)
80
                {
81
                    return true;
82
                }
83
            }
84
85
            return false;
86
        }
87
    }
88
89
    /**
90
     * Called when a neighboring block changes.
91
     */
92
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
93
    {
94
        this.checkForDrop(worldIn, pos, state);
95
    }
96
97
    protected final boolean checkForDrop(World worldIn, BlockPos pos, IBlockState state)
98
    {
99
        if (this.canBlockStay(worldIn, pos))
100
        {
101
            return true;
102
        }
103
        else
104
        {
105
            this.dropBlockAsItem(worldIn, pos, state, 0);
106
            worldIn.setBlockToAir(pos);
107
            return false;
108
        }
109
    }
110
111
    public boolean canBlockStay(World worldIn, BlockPos pos)
112
    {
113
        return this.canPlaceBlockAt(worldIn, pos);
114
    }
115
116
    public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
117
    {
118
        return null;
119
    }
120
121
    /**
122
     * Get the Item that this Block should drop when harvested.
123
     */
124
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
125
    {
126
        return Items.reeds;
127
    }
128
129
    /**
130
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
131
     */
132
    public boolean isOpaqueCube()
133
    {
134
        return false;
135
    }
136
137
    public boolean isFullCube()
138
    {
139
        return false;
140
    }
141
142
    public Item getItem(World worldIn, BlockPos pos)
143
    {
144
        return Items.reeds;
145
    }
146
147
    public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
148
    {
149
        return worldIn.getBiomeGenForCoords(pos).getGrassColorAtPos(pos);
150
    }
151
152
    public EnumWorldBlockLayer getBlockLayer()
153
    {
154
        return EnumWorldBlockLayer.CUTOUT;
155
    }
156
157
    /**
158
     * Convert the given metadata into a BlockState for this Block
159
     */
160
    public IBlockState getStateFromMeta(int meta)
161
    {
162
        return this.getDefaultState().withProperty(AGE, Integer.valueOf(meta));
163
    }
164
165
    /**
166
     * Convert the BlockState into the correct metadata value
167
     */
168
    public int getMetaFromState(IBlockState state)
169
    {
170
        return ((Integer)state.getValue(AGE)).intValue();
171
    }
172
173
    protected BlockState createBlockState()
174
    {
175
        return new BlockState(this, new IProperty[] {AGE});
176
    }
177
}
178

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