BlockStem .java

net.minecraft.block.BlockStem (class): members: getSeedItem, growStem, crop, canPlaceBlockOn, AGE, getRenderColor, canUseBonemeal, canGrow, grow, FACING.

net.minecraft.blockclass238 linescommonextends BlockBush7.5 KB

Implements

API Surface (19)

boolean apply(EnumFacing p_apply_1_)
IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
boolean canPlaceBlockOn(Block ground)
void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
void growStem(World worldIn, BlockPos pos, IBlockState state)
int getRenderColor(IBlockState state)
int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
void setBlockBoundsForItemRender()
void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
Item getSeedItem()
Item getItemDropped(IBlockState state, Random rand, int fortune)
Item getItem(World worldIn, BlockPos pos)
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)
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()

Fields & Constants (3)

AGE
FACING
crop

String literals (1)

"facing"

Full Source

BlockStem.java238 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import com.google.common.base.Predicate;
4
import java.util.Random;
5
import net.minecraft.block.material.Material;
6
import net.minecraft.block.properties.IProperty;
7
import net.minecraft.block.properties.PropertyDirection;
8
import net.minecraft.block.properties.PropertyInteger;
9
import net.minecraft.block.state.BlockState;
10
import net.minecraft.block.state.IBlockState;
11
import net.minecraft.creativetab.CreativeTabs;
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.util.BlockPos;
17
import net.minecraft.util.EnumFacing;
18
import net.minecraft.util.MathHelper;
19
import net.minecraft.world.IBlockAccess;
20
import net.minecraft.world.World;
21
22
public class BlockStem extends BlockBush implements IGrowable
23
{
24
    public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 7);
25
    public static final PropertyDirection FACING = PropertyDirection.create("facing", new Predicate<EnumFacing>()
26
    {
27
        public boolean apply(EnumFacing p_apply_1_)
28
        {
29
            return p_apply_1_ != EnumFacing.DOWN;
30
        }
31
    });
32
    private final Block crop;
33
34
    protected BlockStem(Block crop)
35
    {
36
        this.setDefaultState(this.blockState.getBaseState().withProperty(AGE, Integer.valueOf(0)).withProperty(FACING, EnumFacing.UP));
37
        this.crop = crop;
38
        this.setTickRandomly(true);
39
        float f = 0.125F;
40
        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f);
41
        this.setCreativeTab((CreativeTabs)null);
42
    }
43
44
    /**
45
     * Get the actual Block state of this Block at the given position. This applies properties not visible in the
46
     * metadata, such as fence connections.
47
     */
48
    public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
49
    {
50
        state = state.withProperty(FACING, EnumFacing.UP);
51
52
        for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
53
        {
54
            if (worldIn.getBlockState(pos.offset(enumfacing)).getBlock() == this.crop)
55
            {
56
                state = state.withProperty(FACING, enumfacing);
57
                break;
58
            }
59
        }
60
61
        return state;
62
    }
63
64
    /**
65
     * is the block grass, dirt or farmland
66
     */
67
    protected boolean canPlaceBlockOn(Block ground)
68
    {
69
        return ground == Blocks.farmland;
70
    }
71
72
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
73
    {
74
        super.updateTick(worldIn, pos, state, rand);
75
76
        if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
77
        {
78
            float f = BlockCrops.getGrowthChance(this, worldIn, pos);
79
80
            if (rand.nextInt((int)(25.0F / f) + 1) == 0)
81
            {
82
                int i = ((Integer)state.getValue(AGE)).intValue();
83
84
                if (i < 7)
85
                {
86
                    state = state.withProperty(AGE, Integer.valueOf(i + 1));
87
                    worldIn.setBlockState(pos, state, 2);
88
                }
89
                else
90
                {
91
                    for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
92
                    {
93
                        if (worldIn.getBlockState(pos.offset(enumfacing)).getBlock() == this.crop)
94
                        {
95
                            return;
96
                        }
97
                    }
98
99
                    pos = pos.offset(EnumFacing.Plane.HORIZONTAL.random(rand));
100
                    Block block = worldIn.getBlockState(pos.down()).getBlock();
101
102
                    if (worldIn.getBlockState(pos).getBlock().blockMaterial == Material.air && (block == Blocks.farmland || block == Blocks.dirt || block == Blocks.grass))
103
                    {
104
                        worldIn.setBlockState(pos, this.crop.getDefaultState());
105
                    }
106
                }
107
            }
108
        }
109
    }
110
111
    public void growStem(World worldIn, BlockPos pos, IBlockState state)
112
    {
113
        int i = ((Integer)state.getValue(AGE)).intValue() + MathHelper.getRandomIntegerInRange(worldIn.rand, 2, 5);
114
        worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(Math.min(7, i))), 2);
115
    }
116
117
    public int getRenderColor(IBlockState state)
118
    {
119
        if (state.getBlock() != this)
120
        {
121
            return super.getRenderColor(state);
122
        }
123
        else
124
        {
125
            int i = ((Integer)state.getValue(AGE)).intValue();
126
            int j = i * 32;
127
            int k = 255 - i * 8;
128
            int l = i * 4;
129
            return j << 16 | k << 8 | l;
130
        }
131
    }
132
133
    public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
134
    {
135
        return this.getRenderColor(worldIn.getBlockState(pos));
136
    }
137
138
    /**
139
     * Sets the block's bounds for rendering it as an item
140
     */
141
    public void setBlockBoundsForItemRender()
142
    {
143
        float f = 0.125F;
144
        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f);
145
    }
146
147
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
148
    {
149
        this.maxY = (double)((float)(((Integer)worldIn.getBlockState(pos).getValue(AGE)).intValue() * 2 + 2) / 16.0F);
150
        float f = 0.125F;
151
        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, (float)this.maxY, 0.5F + f);
152
    }
153
154
    /**
155
     * Spawns this Block's drops into the World as EntityItems.
156
     */
157
    public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
158
    {
159
        super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);
160
161
        if (!worldIn.isRemote)
162
        {
163
            Item item = this.getSeedItem();
164
165
            if (item != null)
166
            {
167
                int i = ((Integer)state.getValue(AGE)).intValue();
168
169
                for (int j = 0; j < 3; ++j)
170
                {
171
                    if (worldIn.rand.nextInt(15) <= i)
172
                    {
173
                        spawnAsEntity(worldIn, pos, new ItemStack(item));
174
                    }
175
                }
176
            }
177
        }
178
    }
179
180
    protected Item getSeedItem()
181
    {
182
        return this.crop == Blocks.pumpkin ? Items.pumpkin_seeds : (this.crop == Blocks.melon_block ? Items.melon_seeds : null);
183
    }
184
185
    /**
186
     * Get the Item that this Block should drop when harvested.
187
     */
188
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
189
    {
190
        return null;
191
    }
192
193
    public Item getItem(World worldIn, BlockPos pos)
194
    {
195
        Item item = this.getSeedItem();
196
        return item != null ? item : null;
197
    }
198
199
    /**
200
     * Whether this IGrowable can grow
201
     */
202
    public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
203
    {
204
        return ((Integer)state.getValue(AGE)).intValue() != 7;
205
    }
206
207
    public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
208
    {
209
        return true;
210
    }
211
212
    public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
213
    {
214
        this.growStem(worldIn, pos, state);
215
    }
216
217
    /**
218
     * Convert the given metadata into a BlockState for this Block
219
     */
220
    public IBlockState getStateFromMeta(int meta)
221
    {
222
        return this.getDefaultState().withProperty(AGE, Integer.valueOf(meta));
223
    }
224
225
    /**
226
     * Convert the BlockState into the correct metadata value
227
     */
228
    public int getMetaFromState(IBlockState state)
229
    {
230
        return ((Integer)state.getValue(AGE)).intValue();
231
    }
232
233
    protected BlockState createBlockState()
234
    {
235
        return new BlockState(this, new IProperty[] {AGE, FACING});
236
    }
237
}
238

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