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