BlockNewLog .java

net.minecraft.block.BlockNewLog (class, 140 lines): members: createStackedBlock, VARIANT, damageDropped, getSubBlocks, getMapColor, getStateFromMeta.

net.minecraft.blockclass140 linescommonextends BlockLog4.2 KB

API Surface (8)

boolean apply(BlockPlanks.EnumType p_apply_1_)
MapColor getMapColor(IBlockState state)
void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()
ItemStack createStackedBlock(IBlockState state)
int damageDropped(IBlockState state)

Fields & Constants (1)

VARIANT

String literals (2)

"variant"
"incomplete-switch"

Full Source

BlockNewLog.java140 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import com.google.common.base.Predicate;
4
import java.util.List;
5
import net.minecraft.block.material.MapColor;
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.item.Item;
12
import net.minecraft.item.ItemStack;
13
14
public class BlockNewLog extends BlockLog
15
{
16
    public static final PropertyEnum<BlockPlanks.EnumType> VARIANT = PropertyEnum.<BlockPlanks.EnumType>create("variant", BlockPlanks.EnumType.class, new Predicate<BlockPlanks.EnumType>()
17
    {
18
        public boolean apply(BlockPlanks.EnumType p_apply_1_)
19
        {
20
            return p_apply_1_.getMetadata() >= 4;
21
        }
22
    });
23
24
    public BlockNewLog()
25
    {
26
        this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockPlanks.EnumType.ACACIA).withProperty(LOG_AXIS, BlockLog.EnumAxis.Y));
27
    }
28
29
    /**
30
     * Get the MapColor for this Block and the given BlockState
31
     */
32
    public MapColor getMapColor(IBlockState state)
33
    {
34
        BlockPlanks.EnumType blockplanks$enumtype = (BlockPlanks.EnumType)state.getValue(VARIANT);
35
36
        switch ((BlockLog.EnumAxis)state.getValue(LOG_AXIS))
37
        {
38
            case X:
39
            case Z:
40
            case NONE:
41
            default:
42
                switch (blockplanks$enumtype)
43
                {
44
                    case ACACIA:
45
                    default:
46
                        return MapColor.stoneColor;
47
48
                    case DARK_OAK:
49
                        return BlockPlanks.EnumType.DARK_OAK.getMapColor();
50
                }
51
52
            case Y:
53
                return blockplanks$enumtype.getMapColor();
54
        }
55
    }
56
57
    /**
58
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
59
     */
60
    public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
61
    {
62
        list.add(new ItemStack(itemIn, 1, BlockPlanks.EnumType.ACACIA.getMetadata() - 4));
63
        list.add(new ItemStack(itemIn, 1, BlockPlanks.EnumType.DARK_OAK.getMetadata() - 4));
64
    }
65
66
    /**
67
     * Convert the given metadata into a BlockState for this Block
68
     */
69
    public IBlockState getStateFromMeta(int meta)
70
    {
71
        IBlockState iblockstate = this.getDefaultState().withProperty(VARIANT, BlockPlanks.EnumType.byMetadata((meta & 3) + 4));
72
73
        switch (meta & 12)
74
        {
75
            case 0:
76
                iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.Y);
77
                break;
78
79
            case 4:
80
                iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.X);
81
                break;
82
83
            case 8:
84
                iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.Z);
85
                break;
86
87
            default:
88
                iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.NONE);
89
        }
90
91
        return iblockstate;
92
    }
93
94
    @SuppressWarnings("incomplete-switch")
95
96
    /**
97
     * Convert the BlockState into the correct metadata value
98
     */
99
    public int getMetaFromState(IBlockState state)
100
    {
101
        int i = 0;
102
        i = i | ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata() - 4;
103
104
        switch ((BlockLog.EnumAxis)state.getValue(LOG_AXIS))
105
        {
106
            case X:
107
                i |= 4;
108
                break;
109
110
            case Z:
111
                i |= 8;
112
                break;
113
114
            case NONE:
115
                i |= 12;
116
        }
117
118
        return i;
119
    }
120
121
    protected BlockState createBlockState()
122
    {
123
        return new BlockState(this, new IProperty[] {VARIANT, LOG_AXIS});
124
    }
125
126
    protected ItemStack createStackedBlock(IBlockState state)
127
    {
128
        return new ItemStack(Item.getItemFromBlock(this), 1, ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata() - 4);
129
    }
130
131
    /**
132
     * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
133
     * returns the metadata of the dropped item based on the old metadata of the block.
134
     */
135
    public int damageDropped(IBlockState state)
136
    {
137
        return ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata() - 4;
138
    }
139
}
140

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