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 BlockEnchantmentTable extends BlockContainer
008    {
009        protected BlockEnchantmentTable(int par1)
010        {
011            super(par1, 166, Material.rock);
012            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
013            this.setLightOpacity(0);
014            this.setCreativeTab(CreativeTabs.tabDeco);
015        }
016    
017        /**
018         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
019         */
020        public boolean renderAsNormalBlock()
021        {
022            return false;
023        }
024    
025        @SideOnly(Side.CLIENT)
026    
027        /**
028         * A randomly called display update to be able to add particles or other items for display
029         */
030        public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
031        {
032            super.randomDisplayTick(par1World, par2, par3, par4, par5Random);
033    
034            for (int var6 = par2 - 2; var6 <= par2 + 2; ++var6)
035            {
036                for (int var7 = par4 - 2; var7 <= par4 + 2; ++var7)
037                {
038                    if (var6 > par2 - 2 && var6 < par2 + 2 && var7 == par4 - 1)
039                    {
040                        var7 = par4 + 2;
041                    }
042    
043                    if (par5Random.nextInt(16) == 0)
044                    {
045                        for (int var8 = par3; var8 <= par3 + 1; ++var8)
046                        {
047                            if (par1World.getBlockId(var6, var8, var7) == Block.bookShelf.blockID)
048                            {
049                                if (!par1World.isAirBlock((var6 - par2) / 2 + par2, var8, (var7 - par4) / 2 + par4))
050                                {
051                                    break;
052                                }
053    
054                                par1World.spawnParticle("enchantmenttable", (double)par2 + 0.5D, (double)par3 + 2.0D, (double)par4 + 0.5D, (double)((float)(var6 - par2) + par5Random.nextFloat()) - 0.5D, (double)((float)(var8 - par3) - par5Random.nextFloat() - 1.0F), (double)((float)(var7 - par4) + par5Random.nextFloat()) - 0.5D);
055                            }
056                        }
057                    }
058                }
059            }
060        }
061    
062        /**
063         * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
064         * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
065         */
066        public boolean isOpaqueCube()
067        {
068            return false;
069        }
070    
071        /**
072         * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
073         */
074        public int getBlockTextureFromSideAndMetadata(int par1, int par2)
075        {
076            return this.getBlockTextureFromSide(par1);
077        }
078    
079        /**
080         * Returns the block texture based on the side being looked at.  Args: side
081         */
082        public int getBlockTextureFromSide(int par1)
083        {
084            return par1 == 0 ? this.blockIndexInTexture + 17 : (par1 == 1 ? this.blockIndexInTexture : this.blockIndexInTexture + 16);
085        }
086    
087        /**
088         * each class overrdies this to return a new <className>
089         */
090        public TileEntity createNewTileEntity(World par1World)
091        {
092            return new TileEntityEnchantmentTable();
093        }
094    
095        /**
096         * Called upon block activation (right click on the block.)
097         */
098        public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
099        {
100            if (par1World.isRemote)
101            {
102                return true;
103            }
104            else
105            {
106                par5EntityPlayer.displayGUIEnchantment(par2, par3, par4);
107                return true;
108            }
109        }
110    }