    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.client.renderer.texture.IconRegister;
    008import net.minecraft.item.Item;
    009import net.minecraft.tileentity.TileEntity;
    010import net.minecraft.util.AxisAlignedBB;
    011import net.minecraft.util.Icon;
    012import net.minecraft.world.IBlockAccess;
    013import net.minecraft.world.World;
    014
    015public class BlockSign extends BlockContainer
    016{
    017    private Class signEntityClass;
    018
    019    /** Whether this is a freestanding sign or a wall-mounted sign */
    020    private boolean isFreestanding;
    021
    022    protected BlockSign(int par1, Class par2Class, boolean par3)
    023    {
    024        super(par1, Material.wood);
    025        this.isFreestanding = par3;
    026        this.signEntityClass = par2Class;
    027        float f = 0.25F;
    028        float f1 = 1.0F;
    029        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f1, 0.5F + f);
    030    }
    031
    032    @SideOnly(Side.CLIENT)
    033
    034    /**
    035     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
    036     */
    037    public Icon getBlockTextureFromSideAndMetadata(int par1, int par2)
    038    {
    039        return Block.planks.getBlockTextureFromSide(par1);
    040    }
    041
    042    /**
    043     * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
    044     * cleared to be reused)
    045     */
    046    public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    047    {
    048        return null;
    049    }
    050
    051    @SideOnly(Side.CLIENT)
    052
    053    /**
    054     * Returns the bounding box of the wired rectangular prism to render.
    055     */
    056    public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    057    {
    058        this.setBlockBoundsBasedOnState(par1World, par2, par3, par4);
    059        return super.getSelectedBoundingBoxFromPool(par1World, par2, par3, par4);
    060    }
    061
    062    /**
    063     * Updates the blocks bounds based on its current state. Args: world, x, y, z
    064     */
    065    public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    066    {
    067        if (!this.isFreestanding)
    068        {
    069            int l = par1IBlockAccess.getBlockMetadata(par2, par3, par4);
    070            float f = 0.28125F;
    071            float f1 = 0.78125F;
    072            float f2 = 0.0F;
    073            float f3 = 1.0F;
    074            float f4 = 0.125F;
    075            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
    076
    077            if (l == 2)
    078            {
    079                this.setBlockBounds(f2, f, 1.0F - f4, f3, f1, 1.0F);
    080            }
    081
    082            if (l == 3)
    083            {
    084                this.setBlockBounds(f2, f, 0.0F, f3, f1, f4);
    085            }
    086
    087            if (l == 4)
    088            {
    089                this.setBlockBounds(1.0F - f4, f, f2, 1.0F, f1, f3);
    090            }
    091
    092            if (l == 5)
    093            {
    094                this.setBlockBounds(0.0F, f, f2, f4, f1, f3);
    095            }
    096        }
    097    }
    098
    099    /**
    100     * The type of render function that is called for this block
    101     */
    102    public int getRenderType()
    103    {
    104        return -1;
    105    }
    106
    107    /**
    108     * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
    109     */
    110    public boolean renderAsNormalBlock()
    111    {
    112        return false;
    113    }
    114
    115    public boolean getBlocksMovement(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    116    {
    117        return true;
    118    }
    119
    120    /**
    121     * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
    122     * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
    123     */
    124    public boolean isOpaqueCube()
    125    {
    126        return false;
    127    }
    128
    129    /**
    130     * Returns a new instance of a block's tile entity class. Called on placing the block.
    131     */
    132    public TileEntity createNewTileEntity(World par1World)
    133    {
    134        try
    135        {
    136            return (TileEntity)this.signEntityClass.newInstance();
    137        }
    138        catch (Exception exception)
    139        {
    140            throw new RuntimeException(exception);
    141        }
    142    }
    143
    144    /**
    145     * Returns the ID of the items to drop on destruction.
    146     */
    147    public int idDropped(int par1, Random par2Random, int par3)
    148    {
    149        return Item.sign.itemID;
    150    }
    151
    152    /**
    153     * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
    154     * their own) Args: x, y, z, neighbor blockID
    155     */
    156    public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    157    {
    158        boolean flag = false;
    159
    160        if (this.isFreestanding)
    161        {
    162            if (!par1World.getBlockMaterial(par2, par3 - 1, par4).isSolid())
    163            {
    164                flag = true;
    165            }
    166        }
    167        else
    168        {
    169            int i1 = par1World.getBlockMetadata(par2, par3, par4);
    170            flag = true;
    171
    172            if (i1 == 2 && par1World.getBlockMaterial(par2, par3, par4 + 1).isSolid())
    173            {
    174                flag = false;
    175            }
    176
    177            if (i1 == 3 && par1World.getBlockMaterial(par2, par3, par4 - 1).isSolid())
    178            {
    179                flag = false;
    180            }
    181
    182            if (i1 == 4 && par1World.getBlockMaterial(par2 + 1, par3, par4).isSolid())
    183            {
    184                flag = false;
    185            }
    186
    187            if (i1 == 5 && par1World.getBlockMaterial(par2 - 1, par3, par4).isSolid())
    188            {
    189                flag = false;
    190            }
    191        }
    192
    193        if (flag)
    194        {
    195            this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
    196            par1World.func_94571_i(par2, par3, par4);
    197        }
    198
    199        super.onNeighborBlockChange(par1World, par2, par3, par4, par5);
    200    }
    201
    202    @SideOnly(Side.CLIENT)
    203
    204    /**
    205     * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
    206     */
    207    public int idPicked(World par1World, int par2, int par3, int par4)
    208    {
    209        return Item.sign.itemID;
    210    }
    211
    212    @SideOnly(Side.CLIENT)
    213    public void func_94332_a(IconRegister par1IconRegister) {}
    214}