BlockLadder .java

net.minecraft.block.BlockLadder (class, 165 lines): members: getSelectedBoundingBox, canBlockStay, FACING, canPlaceBlockAt, onBlockPlaced, getBlockLayer.

net.minecraft.blockclass165 linescommonextends Block5.2 KB

API Surface (13)

AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos)
void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
boolean isOpaqueCube()
boolean isFullCube()
boolean canPlaceBlockAt(World worldIn, BlockPos pos)
IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
boolean canBlockStay(World worldIn, BlockPos pos, EnumFacing facing)
EnumWorldBlockLayer getBlockLayer()
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()

Fields & Constants (1)

FACING

String literals (1)

"facing"

Full Source

BlockLadder.java165 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import net.minecraft.block.material.Material;
4
import net.minecraft.block.properties.IProperty;
5
import net.minecraft.block.properties.PropertyDirection;
6
import net.minecraft.block.state.BlockState;
7
import net.minecraft.block.state.IBlockState;
8
import net.minecraft.creativetab.CreativeTabs;
9
import net.minecraft.entity.EntityLivingBase;
10
import net.minecraft.util.AxisAlignedBB;
11
import net.minecraft.util.BlockPos;
12
import net.minecraft.util.EnumFacing;
13
import net.minecraft.util.EnumWorldBlockLayer;
14
import net.minecraft.world.IBlockAccess;
15
import net.minecraft.world.World;
16
17
public class BlockLadder extends Block
18
{
19
    public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
20
21
    protected BlockLadder()
22
    {
23
        super(Material.circuits);
24
        this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
25
        this.setCreativeTab(CreativeTabs.tabDecorations);
26
    }
27
28
    public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
29
    {
30
        this.setBlockBoundsBasedOnState(worldIn, pos);
31
        return super.getCollisionBoundingBox(worldIn, pos, state);
32
    }
33
34
    public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos)
35
    {
36
        this.setBlockBoundsBasedOnState(worldIn, pos);
37
        return super.getSelectedBoundingBox(worldIn, pos);
38
    }
39
40
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
41
    {
42
        IBlockState iblockstate = worldIn.getBlockState(pos);
43
44
        if (iblockstate.getBlock() == this)
45
        {
46
            float f = 0.125F;
47
48
            switch ((EnumFacing)iblockstate.getValue(FACING))
49
            {
50
                case NORTH:
51
                    this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
52
                    break;
53
54
                case SOUTH:
55
                    this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
56
                    break;
57
58
                case WEST:
59
                    this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
60
                    break;
61
62
                case EAST:
63
                default:
64
                    this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
65
            }
66
        }
67
    }
68
69
    /**
70
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
71
     */
72
    public boolean isOpaqueCube()
73
    {
74
        return false;
75
    }
76
77
    public boolean isFullCube()
78
    {
79
        return false;
80
    }
81
82
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
83
    {
84
        return worldIn.getBlockState(pos.west()).getBlock().isNormalCube() ? true : (worldIn.getBlockState(pos.east()).getBlock().isNormalCube() ? true : (worldIn.getBlockState(pos.north()).getBlock().isNormalCube() ? true : worldIn.getBlockState(pos.south()).getBlock().isNormalCube()));
85
    }
86
87
    /**
88
     * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
89
     * IBlockstate
90
     */
91
    public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
92
    {
93
        if (facing.getAxis().isHorizontal() && this.canBlockStay(worldIn, pos, facing))
94
        {
95
            return this.getDefaultState().withProperty(FACING, facing);
96
        }
97
        else
98
        {
99
            for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
100
            {
101
                if (this.canBlockStay(worldIn, pos, enumfacing))
102
                {
103
                    return this.getDefaultState().withProperty(FACING, enumfacing);
104
                }
105
            }
106
107
            return this.getDefaultState();
108
        }
109
    }
110
111
    /**
112
     * Called when a neighboring block changes.
113
     */
114
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
115
    {
116
        EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
117
118
        if (!this.canBlockStay(worldIn, pos, enumfacing))
119
        {
120
            this.dropBlockAsItem(worldIn, pos, state, 0);
121
            worldIn.setBlockToAir(pos);
122
        }
123
124
        super.onNeighborBlockChange(worldIn, pos, state, neighborBlock);
125
    }
126
127
    protected boolean canBlockStay(World worldIn, BlockPos pos, EnumFacing facing)
128
    {
129
        return worldIn.getBlockState(pos.offset(facing.getOpposite())).getBlock().isNormalCube();
130
    }
131
132
    public EnumWorldBlockLayer getBlockLayer()
133
    {
134
        return EnumWorldBlockLayer.CUTOUT;
135
    }
136
137
    /**
138
     * Convert the given metadata into a BlockState for this Block
139
     */
140
    public IBlockState getStateFromMeta(int meta)
141
    {
142
        EnumFacing enumfacing = EnumFacing.getFront(meta);
143
144
        if (enumfacing.getAxis() == EnumFacing.Axis.Y)
145
        {
146
            enumfacing = EnumFacing.NORTH;
147
        }
148
149
        return this.getDefaultState().withProperty(FACING, enumfacing);
150
    }
151
152
    /**
153
     * Convert the BlockState into the correct metadata value
154
     */
155
    public int getMetaFromState(IBlockState state)
156
    {
157
        return ((EnumFacing)state.getValue(FACING)).getIndex();
158
    }
159
160
    protected BlockState createBlockState()
161
    {
162
        return new BlockState(this, new IProperty[] {FACING});
163
    }
164
}
165

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