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