BlockDoublePlant .java

net.minecraft.block.BlockDoublePlant (class): members: EnumPlantType, placeAt, checkAndDropBlock, EnumBlockHalf, getOffsetType, HALF, getVariant, canGrow.

net.minecraft.blockclass406 linescommonextends BlockBush15.3 KB

Implements

API Surface (30)

void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
BlockDoublePlant.EnumPlantType getVariant(IBlockAccess worldIn, BlockPos pos)
boolean canPlaceBlockAt(World worldIn, BlockPos pos)
boolean isReplaceable(World worldIn, BlockPos pos)
void checkAndDropBlock(World worldIn, BlockPos pos, IBlockState state)
boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
Item getItemDropped(IBlockState state, Random rand, int fortune)
int damageDropped(IBlockState state)
int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
void placeAt(World worldIn, BlockPos lowerPos, BlockDoublePlant.EnumPlantType variant, int flags)
void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
int getDamageValue(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)
IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
int getMetaFromState(IBlockState state)
BlockState createBlockState()
Block.EnumOffsetType getOffsetType()
String toString()
String getName()
int getMeta()
String toString()
BlockDoublePlant.EnumPlantType byMetadata(int meta)
String getName()
String getUnlocalizedName()

Fields & Constants (3)

VARIANT
HALF
FACING

String literals (14)

"variant"
"half"
"doublePlant"
"upper"
"lower"
"sunflower"
"syringa"
"double_grass"
"grass"
"double_fern"
"fern"
"double_rose"
"rose"
"paeonia"

Full Source

BlockDoublePlant.java406 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import java.util.List;
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.PropertyEnum;
8
import net.minecraft.block.state.BlockState;
9
import net.minecraft.block.state.IBlockState;
10
import net.minecraft.creativetab.CreativeTabs;
11
import net.minecraft.entity.EntityLivingBase;
12
import net.minecraft.entity.player.EntityPlayer;
13
import net.minecraft.init.Blocks;
14
import net.minecraft.init.Items;
15
import net.minecraft.item.Item;
16
import net.minecraft.item.ItemStack;
17
import net.minecraft.stats.StatList;
18
import net.minecraft.tileentity.TileEntity;
19
import net.minecraft.util.BlockPos;
20
import net.minecraft.util.EnumFacing;
21
import net.minecraft.util.IStringSerializable;
22
import net.minecraft.world.IBlockAccess;
23
import net.minecraft.world.World;
24
import net.minecraft.world.biome.BiomeColorHelper;
25
26
public class BlockDoublePlant extends BlockBush implements IGrowable
27
{
28
    public static final PropertyEnum<BlockDoublePlant.EnumPlantType> VARIANT = PropertyEnum.<BlockDoublePlant.EnumPlantType>create("variant", BlockDoublePlant.EnumPlantType.class);
29
    public static final PropertyEnum<BlockDoublePlant.EnumBlockHalf> HALF = PropertyEnum.<BlockDoublePlant.EnumBlockHalf>create("half", BlockDoublePlant.EnumBlockHalf.class);
30
    public static final PropertyEnum<EnumFacing> FACING = BlockDirectional.FACING;
31
32
    public BlockDoublePlant()
33
    {
34
        super(Material.vine);
35
        this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockDoublePlant.EnumPlantType.SUNFLOWER).withProperty(HALF, BlockDoublePlant.EnumBlockHalf.LOWER).withProperty(FACING, EnumFacing.NORTH));
36
        this.setHardness(0.0F);
37
        this.setStepSound(soundTypeGrass);
38
        this.setUnlocalizedName("doublePlant");
39
    }
40
41
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
42
    {
43
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
44
    }
45
46
    public BlockDoublePlant.EnumPlantType getVariant(IBlockAccess worldIn, BlockPos pos)
47
    {
48
        IBlockState iblockstate = worldIn.getBlockState(pos);
49
50
        if (iblockstate.getBlock() == this)
51
        {
52
            iblockstate = this.getActualState(iblockstate, worldIn, pos);
53
            return (BlockDoublePlant.EnumPlantType)iblockstate.getValue(VARIANT);
54
        }
55
        else
56
        {
57
            return BlockDoublePlant.EnumPlantType.FERN;
58
        }
59
    }
60
61
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
62
    {
63
        return super.canPlaceBlockAt(worldIn, pos) && worldIn.isAirBlock(pos.up());
64
    }
65
66
    /**
67
     * Whether this Block can be replaced directly by other blocks (true for e.g. tall grass)
68
     */
69
    public boolean isReplaceable(World worldIn, BlockPos pos)
70
    {
71
        IBlockState iblockstate = worldIn.getBlockState(pos);
72
73
        if (iblockstate.getBlock() != this)
74
        {
75
            return true;
76
        }
77
        else
78
        {
79
            BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)this.getActualState(iblockstate, worldIn, pos).getValue(VARIANT);
80
            return blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.FERN || blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.GRASS;
81
        }
82
    }
83
84
    protected void checkAndDropBlock(World worldIn, BlockPos pos, IBlockState state)
85
    {
86
        if (!this.canBlockStay(worldIn, pos, state))
87
        {
88
            boolean flag = state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER;
89
            BlockPos blockpos = flag ? pos : pos.up();
90
            BlockPos blockpos1 = flag ? pos.down() : pos;
91
            Block block = (Block)(flag ? this : worldIn.getBlockState(blockpos).getBlock());
92
            Block block1 = (Block)(flag ? worldIn.getBlockState(blockpos1).getBlock() : this);
93
94
            if (block == this)
95
            {
96
                worldIn.setBlockState(blockpos, Blocks.air.getDefaultState(), 2);
97
            }
98
99
            if (block1 == this)
100
            {
101
                worldIn.setBlockState(blockpos1, Blocks.air.getDefaultState(), 3);
102
103
                if (!flag)
104
                {
105
                    this.dropBlockAsItem(worldIn, blockpos1, state, 0);
106
                }
107
            }
108
        }
109
    }
110
111
    public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
112
    {
113
        if (state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
114
        {
115
            return worldIn.getBlockState(pos.down()).getBlock() == this;
116
        }
117
        else
118
        {
119
            IBlockState iblockstate = worldIn.getBlockState(pos.up());
120
            return iblockstate.getBlock() == this && super.canBlockStay(worldIn, pos, iblockstate);
121
        }
122
    }
123
124
    /**
125
     * Get the Item that this Block should drop when harvested.
126
     */
127
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
128
    {
129
        if (state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
130
        {
131
            return null;
132
        }
133
        else
134
        {
135
            BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)state.getValue(VARIANT);
136
            return blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.FERN ? null : (blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.GRASS ? (rand.nextInt(8) == 0 ? Items.wheat_seeds : null) : Item.getItemFromBlock(this));
137
        }
138
    }
139
140
    /**
141
     * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
142
     * returns the metadata of the dropped item based on the old metadata of the block.
143
     */
144
    public int damageDropped(IBlockState state)
145
    {
146
        return state.getValue(HALF) != BlockDoublePlant.EnumBlockHalf.UPPER && state.getValue(VARIANT) != BlockDoublePlant.EnumPlantType.GRASS ? ((BlockDoublePlant.EnumPlantType)state.getValue(VARIANT)).getMeta() : 0;
147
    }
148
149
    public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
150
    {
151
        BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = this.getVariant(worldIn, pos);
152
        return blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN ? 16777215 : BiomeColorHelper.getGrassColorAtPos(worldIn, pos);
153
    }
154
155
    public void placeAt(World worldIn, BlockPos lowerPos, BlockDoublePlant.EnumPlantType variant, int flags)
156
    {
157
        worldIn.setBlockState(lowerPos, this.getDefaultState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.LOWER).withProperty(VARIANT, variant), flags);
158
        worldIn.setBlockState(lowerPos.up(), this.getDefaultState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.UPPER), flags);
159
    }
160
161
    /**
162
     * Called by ItemBlocks after a block is set in the world, to allow post-place logic
163
     */
164
    public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
165
    {
166
        worldIn.setBlockState(pos.up(), this.getDefaultState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.UPPER), 2);
167
    }
168
169
    public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
170
    {
171
        if (worldIn.isRemote || player.getCurrentEquippedItem() == null || player.getCurrentEquippedItem().getItem() != Items.shears || state.getValue(HALF) != BlockDoublePlant.EnumBlockHalf.LOWER || !this.onHarvest(worldIn, pos, state, player))
172
        {
173
            super.harvestBlock(worldIn, player, pos, state, te);
174
        }
175
    }
176
177
    public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
178
    {
179
        if (state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
180
        {
181
            if (worldIn.getBlockState(pos.down()).getBlock() == this)
182
            {
183
                if (!player.capabilities.isCreativeMode)
184
                {
185
                    IBlockState iblockstate = worldIn.getBlockState(pos.down());
186
                    BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)iblockstate.getValue(VARIANT);
187
188
                    if (blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS)
189
                    {
190
                        worldIn.destroyBlock(pos.down(), true);
191
                    }
192
                    else if (!worldIn.isRemote)
193
                    {
194
                        if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears)
195
                        {
196
                            this.onHarvest(worldIn, pos, iblockstate, player);
197
                            worldIn.setBlockToAir(pos.down());
198
                        }
199
                        else
200
                        {
201
                            worldIn.destroyBlock(pos.down(), true);
202
                        }
203
                    }
204
                    else
205
                    {
206
                        worldIn.setBlockToAir(pos.down());
207
                    }
208
                }
209
                else
210
                {
211
                    worldIn.setBlockToAir(pos.down());
212
                }
213
            }
214
        }
215
        else if (player.capabilities.isCreativeMode && worldIn.getBlockState(pos.up()).getBlock() == this)
216
        {
217
            worldIn.setBlockState(pos.up(), Blocks.air.getDefaultState(), 2);
218
        }
219
220
        super.onBlockHarvested(worldIn, pos, state, player);
221
    }
222
223
    private boolean onHarvest(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
224
    {
225
        BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)state.getValue(VARIANT);
226
227
        if (blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS)
228
        {
229
            return false;
230
        }
231
        else
232
        {
233
            player.triggerAchievement(StatList.mineBlockStatArray[Block.getIdFromBlock(this)]);
234
            int i = (blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.GRASS ? BlockTallGrass.EnumType.GRASS : BlockTallGrass.EnumType.FERN).getMeta();
235
            spawnAsEntity(worldIn, pos, new ItemStack(Blocks.tallgrass, 2, i));
236
            return true;
237
        }
238
    }
239
240
    /**
241
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
242
     */
243
    public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
244
    {
245
        for (BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype : BlockDoublePlant.EnumPlantType.values())
246
        {
247
            list.add(new ItemStack(itemIn, 1, blockdoubleplant$enumplanttype.getMeta()));
248
        }
249
    }
250
251
    /**
252
     * Gets the meta to use for the Pick Block ItemStack result
253
     */
254
    public int getDamageValue(World worldIn, BlockPos pos)
255
    {
256
        return this.getVariant(worldIn, pos).getMeta();
257
    }
258
259
    /**
260
     * Whether this IGrowable can grow
261
     */
262
    public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
263
    {
264
        BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = this.getVariant(worldIn, pos);
265
        return blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN;
266
    }
267
268
    public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
269
    {
270
        return true;
271
    }
272
273
    public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
274
    {
275
        spawnAsEntity(worldIn, pos, new ItemStack(this, 1, this.getVariant(worldIn, pos).getMeta()));
276
    }
277
278
    /**
279
     * Convert the given metadata into a BlockState for this Block
280
     */
281
    public IBlockState getStateFromMeta(int meta)
282
    {
283
        return (meta & 8) > 0 ? this.getDefaultState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.UPPER) : this.getDefaultState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.LOWER).withProperty(VARIANT, BlockDoublePlant.EnumPlantType.byMetadata(meta & 7));
284
    }
285
286
    /**
287
     * Get the actual Block state of this Block at the given position. This applies properties not visible in the
288
     * metadata, such as fence connections.
289
     */
290
    public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
291
    {
292
        if (state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
293
        {
294
            IBlockState iblockstate = worldIn.getBlockState(pos.down());
295
296
            if (iblockstate.getBlock() == this)
297
            {
298
                state = state.withProperty(VARIANT, iblockstate.getValue(VARIANT));
299
            }
300
        }
301
302
        return state;
303
    }
304
305
    /**
306
     * Convert the BlockState into the correct metadata value
307
     */
308
    public int getMetaFromState(IBlockState state)
309
    {
310
        return state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER ? 8 | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex() : ((BlockDoublePlant.EnumPlantType)state.getValue(VARIANT)).getMeta();
311
    }
312
313
    protected BlockState createBlockState()
314
    {
315
        return new BlockState(this, new IProperty[] {HALF, VARIANT, FACING});
316
    }
317
318
    /**
319
     * Get the OffsetType for this Block. Determines if the model is rendered slightly offset.
320
     */
321
    public Block.EnumOffsetType getOffsetType()
322
    {
323
        return Block.EnumOffsetType.XZ;
324
    }
325
326
    public static enum EnumBlockHalf implements IStringSerializable
327
    {
328
        UPPER,
329
        LOWER;
330
331
        public String toString()
332
        {
333
            return this.getName();
334
        }
335
336
        public String getName()
337
        {
338
            return this == UPPER ? "upper" : "lower";
339
        }
340
    }
341
342
    public static enum EnumPlantType implements IStringSerializable
343
    {
344
        SUNFLOWER(0, "sunflower"),
345
        SYRINGA(1, "syringa"),
346
        GRASS(2, "double_grass", "grass"),
347
        FERN(3, "double_fern", "fern"),
348
        ROSE(4, "double_rose", "rose"),
349
        PAEONIA(5, "paeonia");
350
351
        private static final BlockDoublePlant.EnumPlantType[] META_LOOKUP = new BlockDoublePlant.EnumPlantType[values().length];
352
        private final int meta;
353
        private final String name;
354
        private final String unlocalizedName;
355
356
        private EnumPlantType(int meta, String name)
357
        {
358
            this(meta, name, name);
359
        }
360
361
        private EnumPlantType(int meta, String name, String unlocalizedName)
362
        {
363
            this.meta = meta;
364
            this.name = name;
365
            this.unlocalizedName = unlocalizedName;
366
        }
367
368
        public int getMeta()
369
        {
370
            return this.meta;
371
        }
372
373
        public String toString()
374
        {
375
            return this.name;
376
        }
377
378
        public static BlockDoublePlant.EnumPlantType byMetadata(int meta)
379
        {
380
            if (meta < 0 || meta >= META_LOOKUP.length)
381
            {
382
                meta = 0;
383
            }
384
385
            return META_LOOKUP[meta];
386
        }
387
388
        public String getName()
389
        {
390
            return this.name;
391
        }
392
393
        public String getUnlocalizedName()
394
        {
395
            return this.unlocalizedName;
396
        }
397
398
        static {
399
            for (BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype : values())
400
            {
401
                META_LOOKUP[blockdoubleplant$enumplanttype.getMeta()] = blockdoubleplant$enumplanttype;
402
            }
403
        }
404
    }
405
}
406

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