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.creativetab.CreativeTabs;
009import net.minecraft.entity.EntityLiving;
010import net.minecraft.entity.player.EntityPlayer;
011import net.minecraft.item.ItemStack;
012import net.minecraft.tileentity.TileEntity;
013import net.minecraft.tileentity.TileEntityEnchantmentTable;
014import net.minecraft.util.Icon;
015import net.minecraft.world.World;
016
017public class BlockEnchantmentTable extends BlockContainer
018{
019    @SideOnly(Side.CLIENT)
020    private Icon field_94461_a;
021    @SideOnly(Side.CLIENT)
022    private Icon field_94460_b;
023
024    protected BlockEnchantmentTable(int par1)
025    {
026        super(par1, Material.rock);
027        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
028        this.setLightOpacity(0);
029        this.setCreativeTab(CreativeTabs.tabDecorations);
030    }
031
032    /**
033     * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
034     */
035    public boolean renderAsNormalBlock()
036    {
037        return false;
038    }
039
040    @SideOnly(Side.CLIENT)
041
042    /**
043     * A randomly called display update to be able to add particles or other items for display
044     */
045    public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
046    {
047        super.randomDisplayTick(par1World, par2, par3, par4, par5Random);
048
049        for (int l = par2 - 2; l <= par2 + 2; ++l)
050        {
051            for (int i1 = par4 - 2; i1 <= par4 + 2; ++i1)
052            {
053                if (l > par2 - 2 && l < par2 + 2 && i1 == par4 - 1)
054                {
055                    i1 = par4 + 2;
056                }
057
058                if (par5Random.nextInt(16) == 0)
059                {
060                    for (int j1 = par3; j1 <= par3 + 1; ++j1)
061                    {
062                        if (par1World.getBlockId(l, j1, i1) == Block.bookShelf.blockID)
063                        {
064                            if (!par1World.isAirBlock((l - par2) / 2 + par2, j1, (i1 - par4) / 2 + par4))
065                            {
066                                break;
067                            }
068
069                            par1World.spawnParticle("enchantmenttable", (double)par2 + 0.5D, (double)par3 + 2.0D, (double)par4 + 0.5D, (double)((float)(l - par2) + par5Random.nextFloat()) - 0.5D, (double)((float)(j1 - par3) - par5Random.nextFloat() - 1.0F), (double)((float)(i1 - par4) + par5Random.nextFloat()) - 0.5D);
070                        }
071                    }
072                }
073            }
074        }
075    }
076
077    /**
078     * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
079     * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
080     */
081    public boolean isOpaqueCube()
082    {
083        return false;
084    }
085
086    @SideOnly(Side.CLIENT)
087
088    /**
089     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
090     */
091    public Icon getIcon(int par1, int par2)
092    {
093        return par1 == 0 ? this.field_94460_b : (par1 == 1 ? this.field_94461_a : this.blockIcon);
094    }
095
096    /**
097     * Returns a new instance of a block's tile entity class. Called on placing the block.
098     */
099    public TileEntity createNewTileEntity(World par1World)
100    {
101        return new TileEntityEnchantmentTable();
102    }
103
104    /**
105     * Called upon block activation (right click on the block.)
106     */
107    public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
108    {
109        if (par1World.isRemote)
110        {
111            return true;
112        }
113        else
114        {
115            TileEntityEnchantmentTable tileentityenchantmenttable = (TileEntityEnchantmentTable)par1World.getBlockTileEntity(par2, par3, par4);
116            par5EntityPlayer.displayGUIEnchantment(par2, par3, par4, tileentityenchantmenttable.func_94135_b() ? tileentityenchantmenttable.func_94133_a() : null);
117            return true;
118        }
119    }
120
121    /**
122     * Called when the block is placed in the world.
123     */
124    public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving, ItemStack par6ItemStack)
125    {
126        super.onBlockPlacedBy(par1World, par2, par3, par4, par5EntityLiving, par6ItemStack);
127
128        if (par6ItemStack.hasDisplayName())
129        {
130            ((TileEntityEnchantmentTable)par1World.getBlockTileEntity(par2, par3, par4)).func_94134_a(par6ItemStack.getDisplayName());
131        }
132    }
133
134    @SideOnly(Side.CLIENT)
135
136    /**
137     * When this method is called, your block should register all the icons it needs with the given IconRegister. This
138     * is the only chance you get to register icons.
139     */
140    public void registerIcons(IconRegister par1IconRegister)
141    {
142        this.blockIcon = par1IconRegister.registerIcon("enchantment_side");
143        this.field_94461_a = par1IconRegister.registerIcon("enchantment_top");
144        this.field_94460_b = par1IconRegister.registerIcon("enchantment_bottom");
145    }
146}