001 package net.minecraft.src; 002 003 import cpw.mods.fml.common.Side; 004 import cpw.mods.fml.common.asm.SideOnly; 005 006 public class BlockFenceGate extends BlockDirectional 007 { 008 public BlockFenceGate(int par1, int par2) 009 { 010 super(par1, par2, Material.wood); 011 this.setCreativeTab(CreativeTabs.tabRedstone); 012 } 013 014 /** 015 * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z 016 */ 017 public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) 018 { 019 return !par1World.getBlockMaterial(par2, par3 - 1, par4).isSolid() ? false : super.canPlaceBlockAt(par1World, par2, par3, par4); 020 } 021 022 /** 023 * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been 024 * cleared to be reused) 025 */ 026 public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) 027 { 028 int var5 = par1World.getBlockMetadata(par2, par3, par4); 029 return isFenceGateOpen(var5) ? null : (var5 != 2 && var5 != 0 ? AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)((float)par2 + 0.375F), (double)par3, (double)par4, (double)((float)par2 + 0.625F), (double)((float)par3 + 1.5F), (double)(par4 + 1)) : AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)par2, (double)par3, (double)((float)par4 + 0.375F), (double)(par2 + 1), (double)((float)par3 + 1.5F), (double)((float)par4 + 0.625F))); 030 } 031 032 /** 033 * Updates the blocks bounds based on its current state. Args: world, x, y, z 034 */ 035 public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) 036 { 037 int var5 = getDirection(par1IBlockAccess.getBlockMetadata(par2, par3, par4)); 038 039 if (var5 != 2 && var5 != 0) 040 { 041 this.setBlockBounds(0.375F, 0.0F, 0.0F, 0.625F, 1.0F, 1.0F); 042 } 043 else 044 { 045 this.setBlockBounds(0.0F, 0.0F, 0.375F, 1.0F, 1.0F, 0.625F); 046 } 047 } 048 049 /** 050 * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two 051 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. 052 */ 053 public boolean isOpaqueCube() 054 { 055 return false; 056 } 057 058 /** 059 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) 060 */ 061 public boolean renderAsNormalBlock() 062 { 063 return false; 064 } 065 066 public boolean getBlocksMovement(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) 067 { 068 return isFenceGateOpen(par1IBlockAccess.getBlockMetadata(par2, par3, par4)); 069 } 070 071 /** 072 * The type of render function that is called for this block 073 */ 074 public int getRenderType() 075 { 076 return 21; 077 } 078 079 /** 080 * Called when the block is placed in the world. 081 */ 082 public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving) 083 { 084 int var6 = (MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) % 4; 085 par1World.setBlockMetadataWithNotify(par2, par3, par4, var6); 086 } 087 088 /** 089 * Called upon block activation (right click on the block.) 090 */ 091 public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) 092 { 093 int var10 = par1World.getBlockMetadata(par2, par3, par4); 094 095 if (isFenceGateOpen(var10)) 096 { 097 par1World.setBlockMetadataWithNotify(par2, par3, par4, var10 & -5); 098 } 099 else 100 { 101 int var11 = (MathHelper.floor_double((double)(par5EntityPlayer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) % 4; 102 int var12 = getDirection(var10); 103 104 if (var12 == (var11 + 2) % 4) 105 { 106 var10 = var11; 107 } 108 109 par1World.setBlockMetadataWithNotify(par2, par3, par4, var10 | 4); 110 } 111 112 par1World.playAuxSFXAtEntity(par5EntityPlayer, 1003, par2, par3, par4, 0); 113 return true; 114 } 115 116 /** 117 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are 118 * their own) Args: x, y, z, neighbor blockID 119 */ 120 public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) 121 { 122 if (!par1World.isRemote) 123 { 124 int var6 = par1World.getBlockMetadata(par2, par3, par4); 125 boolean var7 = par1World.isBlockIndirectlyGettingPowered(par2, par3, par4); 126 127 if (var7 || par5 > 0 && Block.blocksList[par5].canProvidePower() || par5 == 0) 128 { 129 if (var7 && !isFenceGateOpen(var6)) 130 { 131 par1World.setBlockMetadataWithNotify(par2, par3, par4, var6 | 4); 132 par1World.playAuxSFXAtEntity((EntityPlayer)null, 1003, par2, par3, par4, 0); 133 } 134 else if (!var7 && isFenceGateOpen(var6)) 135 { 136 par1World.setBlockMetadataWithNotify(par2, par3, par4, var6 & -5); 137 par1World.playAuxSFXAtEntity((EntityPlayer)null, 1003, par2, par3, par4, 0); 138 } 139 } 140 } 141 } 142 143 /** 144 * Returns if the fence gate is open according to its metadata. 145 */ 146 public static boolean isFenceGateOpen(int par0) 147 { 148 return (par0 & 4) != 0; 149 } 150 151 @SideOnly(Side.CLIENT) 152 153 /** 154 * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given 155 * coordinates. Args: blockAccess, x, y, z, side 156 */ 157 public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) 158 { 159 return true; 160 } 161 }