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