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 BlockEnderChest extends BlockContainer
008    {
009        protected BlockEnderChest(int par1)
010        {
011            super(par1, Material.rock);
012            this.blockIndexInTexture = 37;
013            this.setCreativeTab(CreativeTabs.tabDecorations);
014        }
015    
016        /**
017         * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
018         * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
019         */
020        public boolean isOpaqueCube()
021        {
022            return false;
023        }
024    
025        /**
026         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
027         */
028        public boolean renderAsNormalBlock()
029        {
030            return false;
031        }
032    
033        /**
034         * The type of render function that is called for this block
035         */
036        public int getRenderType()
037        {
038            return 22;
039        }
040    
041        /**
042         * Returns the ID of the items to drop on destruction.
043         */
044        public int idDropped(int par1, Random par2Random, int par3)
045        {
046            return Block.obsidian.blockID;
047        }
048    
049        /**
050         * Returns the quantity of items to drop on block destruction.
051         */
052        public int quantityDropped(Random par1Random)
053        {
054            return 8;
055        }
056    
057        /**
058         * Return true if a player with Silk Touch can harvest this block directly, and not its normal drops.
059         */
060        protected boolean canSilkHarvest()
061        {
062            return true;
063        }
064    
065        /**
066         * Called when the block is placed in the world.
067         */
068        public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving)
069        {
070            byte var6 = 0;
071            int var7 = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
072    
073            if (var7 == 0)
074            {
075                var6 = 2;
076            }
077    
078            if (var7 == 1)
079            {
080                var6 = 5;
081            }
082    
083            if (var7 == 2)
084            {
085                var6 = 3;
086            }
087    
088            if (var7 == 3)
089            {
090                var6 = 4;
091            }
092    
093            par1World.setBlockMetadataWithNotify(par2, par3, par4, var6);
094        }
095    
096        /**
097         * Called upon block activation (right click on the block.)
098         */
099        public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
100        {
101            InventoryEnderChest var10 = par5EntityPlayer.getInventoryEnderChest();
102            TileEntityEnderChest var11 = (TileEntityEnderChest)par1World.getBlockTileEntity(par2, par3, par4);
103    
104            if (var10 != null && var11 != null)
105            {
106                if (par1World.isBlockNormalCube(par2, par3 + 1, par4))
107                {
108                    return true;
109                }
110                else if (par1World.isRemote)
111                {
112                    return true;
113                }
114                else
115                {
116                    var10.setAssociatedChest(var11);
117                    par5EntityPlayer.displayGUIChest(var10);
118                    return true;
119                }
120            }
121            else
122            {
123                return true;
124            }
125        }
126    
127        /**
128         * Returns a new instance of a block's tile entity class. Called on placing the block.
129         */
130        public TileEntity createNewTileEntity(World par1World)
131        {
132            return new TileEntityEnderChest();
133        }
134    
135        @SideOnly(Side.CLIENT)
136    
137        /**
138         * A randomly called display update to be able to add particles or other items for display
139         */
140        public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
141        {
142            for (int var6 = 0; var6 < 3; ++var6)
143            {
144                double var10000 = (double)((float)par2 + par5Random.nextFloat());
145                double var9 = (double)((float)par3 + par5Random.nextFloat());
146                var10000 = (double)((float)par4 + par5Random.nextFloat());
147                double var13 = 0.0D;
148                double var15 = 0.0D;
149                double var17 = 0.0D;
150                int var19 = par5Random.nextInt(2) * 2 - 1;
151                int var20 = par5Random.nextInt(2) * 2 - 1;
152                var13 = ((double)par5Random.nextFloat() - 0.5D) * 0.125D;
153                var15 = ((double)par5Random.nextFloat() - 0.5D) * 0.125D;
154                var17 = ((double)par5Random.nextFloat() - 0.5D) * 0.125D;
155                double var11 = (double)par4 + 0.5D + 0.25D * (double)var20;
156                var17 = (double)(par5Random.nextFloat() * 1.0F * (float)var20);
157                double var7 = (double)par2 + 0.5D + 0.25D * (double)var19;
158                var13 = (double)(par5Random.nextFloat() * 1.0F * (float)var19);
159                par1World.spawnParticle("portal", var7, var9, var11, var13, var15, var17);
160            }
161        }
162    }