    001package net.minecraft.block;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import java.util.Random;
    006import net.minecraft.block.material.Material;
    007import net.minecraft.creativetab.CreativeTabs;
    008import net.minecraft.util.AxisAlignedBB;
    009import net.minecraft.world.IBlockAccess;
    010import net.minecraft.world.World;
    011
    012import net.minecraftforge.common.ForgeDirection;
    013import static net.minecraftforge.common.ForgeDirection.*;
    014
    015public class BlockLadder extends Block
    016{
    017    protected BlockLadder(int par1, int par2)
    018    {
    019        super(par1, par2, Material.circuits);
    020        this.setCreativeTab(CreativeTabs.tabDecorations);
    021    }
    022
    023    /**
    024     * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
    025     * cleared to be reused)
    026     */
    027    public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    028    {
    029        this.setBlockBoundsBasedOnState(par1World, par2, par3, par4);
    030        return super.getCollisionBoundingBoxFromPool(par1World, par2, par3, par4);
    031    }
    032
    033    @SideOnly(Side.CLIENT)
    034
    035    /**
    036     * Returns the bounding box of the wired rectangular prism to render.
    037     */
    038    public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    039    {
    040        this.setBlockBoundsBasedOnState(par1World, par2, par3, par4);
    041        return super.getSelectedBoundingBoxFromPool(par1World, par2, par3, par4);
    042    }
    043
    044    /**
    045     * Updates the blocks bounds based on its current state. Args: world, x, y, z
    046     */
    047    public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    048    {
    049        this.updateLadderBounds(par1IBlockAccess.getBlockMetadata(par2, par3, par4));
    050    }
    051
    052    /**
    053     * Update the ladder block bounds based on the given metadata value.
    054     */
    055    public void updateLadderBounds(int par1)
    056    {
    057        float var3 = 0.125F;
    058
    059        if (par1 == 2)
    060        {
    061            this.setBlockBounds(0.0F, 0.0F, 1.0F - var3, 1.0F, 1.0F, 1.0F);
    062        }
    063
    064        if (par1 == 3)
    065        {
    066            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, var3);
    067        }
    068
    069        if (par1 == 4)
    070        {
    071            this.setBlockBounds(1.0F - var3, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
    072        }
    073
    074        if (par1 == 5)
    075        {
    076            this.setBlockBounds(0.0F, 0.0F, 0.0F, var3, 1.0F, 1.0F);
    077        }
    078    }
    079
    080    /**
    081     * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
    082     * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
    083     */
    084    public boolean isOpaqueCube()
    085    {
    086        return false;
    087    }
    088
    089    /**
    090     * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
    091     */
    092    public boolean renderAsNormalBlock()
    093    {
    094        return false;
    095    }
    096
    097    /**
    098     * The type of render function that is called for this block
    099     */
    100    public int getRenderType()
    101    {
    102        return 8;
    103    }
    104
    105    /**
    106     * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
    107     */
    108    public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
    109    {
    110        return par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST ) ||
    111               par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST ) ||
    112               par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH) ||
    113               par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH);
    114    }
    115
    116    /**
    117     * Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata
    118     */
    119    public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9)
    120    {
    121        int var10 = par9;
    122
    123        if ((var10 == 0 || par5 == 2) && par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH))
    124        {
    125            var10 = 2;
    126        }
    127
    128        if ((var10 == 0 || par5 == 3) && par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH))
    129        {
    130            var10 = 3;
    131        }
    132
    133        if ((var10 == 0 || par5 == 4) && par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST))
    134        {
    135            var10 = 4;
    136        }
    137
    138        if ((var10 == 0 || par5 == 5) && par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST))
    139        {
    140            var10 = 5;
    141        }
    142
    143        return var10;
    144    }
    145
    146    /**
    147     * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
    148     * their own) Args: x, y, z, neighbor blockID
    149     */
    150    public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    151    {
    152        int var6 = par1World.getBlockMetadata(par2, par3, par4);
    153        boolean var7 = false;
    154
    155        if (var6 == 2 && par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH))
    156        {
    157            var7 = true;
    158        }
    159
    160        if (var6 == 3 && par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH))
    161        {
    162            var7 = true;
    163        }
    164
    165        if (var6 == 4 && par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST))
    166        {
    167            var7 = true;
    168        }
    169
    170        if (var6 == 5 && par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST))
    171        {
    172            var7 = true;
    173        }
    174
    175        if (!var7)
    176        {
    177            this.dropBlockAsItem(par1World, par2, par3, par4, var6, 0);
    178            par1World.setBlockWithNotify(par2, par3, par4, 0);
    179        }
    180
    181        super.onNeighborBlockChange(par1World, par2, par3, par4, par5);
    182    }
    183
    184    /**
    185     * Returns the quantity of items to drop on block destruction.
    186     */
    187    public int quantityDropped(Random par1Random)
    188    {
    189        return 1;
    190    }
    191
    192    @Override
    193    public boolean isLadder(World world, int x, int y, int z)
    194    {
    195        return true;
    196    }
    197}