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