BlockWoodSlab .java

net.minecraft.block.BlockWoodSlab (class): members: getVariantProperty, getVariant, getUnlocalizedName, VARIANT, damageDropped, getSubBlocks, getMapColor.

net.minecraft.blockclass134 linescommonextends BlockSlab4.1 KB

API Surface (11)

MapColor getMapColor(IBlockState state)
Item getItemDropped(IBlockState state, Random rand, int fortune)
Item getItem(World worldIn, BlockPos pos)
String getUnlocalizedName(int meta)
IProperty<?> getVariantProperty()
Object getVariant(ItemStack stack)
void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()
int damageDropped(IBlockState state)

Fields & Constants (1)

VARIANT

String literals (1)

"variant"

Full Source

BlockWoodSlab.java134 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.MapColor;
6
import net.minecraft.block.material.Material;
7
import net.minecraft.block.properties.IProperty;
8
import net.minecraft.block.properties.PropertyEnum;
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.item.Item;
14
import net.minecraft.item.ItemStack;
15
import net.minecraft.util.BlockPos;
16
import net.minecraft.world.World;
17
18
public abstract class BlockWoodSlab extends BlockSlab
19
{
20
    public static final PropertyEnum<BlockPlanks.EnumType> VARIANT = PropertyEnum.<BlockPlanks.EnumType>create("variant", BlockPlanks.EnumType.class);
21
22
    public BlockWoodSlab()
23
    {
24
        super(Material.wood);
25
        IBlockState iblockstate = this.blockState.getBaseState();
26
27
        if (!this.isDouble())
28
        {
29
            iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM);
30
        }
31
32
        this.setDefaultState(iblockstate.withProperty(VARIANT, BlockPlanks.EnumType.OAK));
33
        this.setCreativeTab(CreativeTabs.tabBlock);
34
    }
35
36
    /**
37
     * Get the MapColor for this Block and the given BlockState
38
     */
39
    public MapColor getMapColor(IBlockState state)
40
    {
41
        return ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMapColor();
42
    }
43
44
    /**
45
     * Get the Item that this Block should drop when harvested.
46
     */
47
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
48
    {
49
        return Item.getItemFromBlock(Blocks.wooden_slab);
50
    }
51
52
    public Item getItem(World worldIn, BlockPos pos)
53
    {
54
        return Item.getItemFromBlock(Blocks.wooden_slab);
55
    }
56
57
    /**
58
     * Returns the slab block name with the type associated with it
59
     */
60
    public String getUnlocalizedName(int meta)
61
    {
62
        return super.getUnlocalizedName() + "." + BlockPlanks.EnumType.byMetadata(meta).getUnlocalizedName();
63
    }
64
65
    public IProperty<?> getVariantProperty()
66
    {
67
        return VARIANT;
68
    }
69
70
    public Object getVariant(ItemStack stack)
71
    {
72
        return BlockPlanks.EnumType.byMetadata(stack.getMetadata() & 7);
73
    }
74
75
    /**
76
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
77
     */
78
    public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
79
    {
80
        if (itemIn != Item.getItemFromBlock(Blocks.double_wooden_slab))
81
        {
82
            for (BlockPlanks.EnumType blockplanks$enumtype : BlockPlanks.EnumType.values())
83
            {
84
                list.add(new ItemStack(itemIn, 1, blockplanks$enumtype.getMetadata()));
85
            }
86
        }
87
    }
88
89
    /**
90
     * Convert the given metadata into a BlockState for this Block
91
     */
92
    public IBlockState getStateFromMeta(int meta)
93
    {
94
        IBlockState iblockstate = this.getDefaultState().withProperty(VARIANT, BlockPlanks.EnumType.byMetadata(meta & 7));
95
96
        if (!this.isDouble())
97
        {
98
            iblockstate = iblockstate.withProperty(HALF, (meta & 8) == 0 ? BlockSlab.EnumBlockHalf.BOTTOM : BlockSlab.EnumBlockHalf.TOP);
99
        }
100
101
        return iblockstate;
102
    }
103
104
    /**
105
     * Convert the BlockState into the correct metadata value
106
     */
107
    public int getMetaFromState(IBlockState state)
108
    {
109
        int i = 0;
110
        i = i | ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata();
111
112
        if (!this.isDouble() && state.getValue(HALF) == BlockSlab.EnumBlockHalf.TOP)
113
        {
114
            i |= 8;
115
        }
116
117
        return i;
118
    }
119
120
    protected BlockState createBlockState()
121
    {
122
        return this.isDouble() ? new BlockState(this, new IProperty[] {VARIANT}): new BlockState(this, new IProperty[] {HALF, VARIANT});
123
    }
124
125
    /**
126
     * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
127
     * returns the metadata of the dropped item based on the old metadata of the block.
128
     */
129
    public int damageDropped(IBlockState state)
130
    {
131
        return ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata();
132
    }
133
}
134

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