001package net.minecraft.block; 002 003import cpw.mods.fml.relauncher.Side; 004import cpw.mods.fml.relauncher.SideOnly; 005import java.util.List; 006import net.minecraft.block.material.Material; 007import net.minecraft.client.renderer.texture.IconRegister; 008import net.minecraft.creativetab.CreativeTabs; 009import net.minecraft.entity.Entity; 010import net.minecraft.util.AxisAlignedBB; 011import net.minecraft.world.IBlockAccess; 012import net.minecraft.world.World; 013 014public class BlockFence extends Block 015{ 016 private final String field_94464_a; 017 018 public BlockFence(int par1, String par2Str, Material par3Material) 019 { 020 super(par1, par3Material); 021 this.field_94464_a = par2Str; 022 this.setCreativeTab(CreativeTabs.tabDecorations); 023 } 024 025 /** 026 * Adds all intersecting collision boxes to a list. (Be sure to only add boxes to the list if they intersect the 027 * mask.) Parameters: World, X, Y, Z, mask, list, colliding entity 028 */ 029 public void addCollisionBoxesToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity) 030 { 031 boolean flag = this.canConnectFenceTo(par1World, par2, par3, par4 - 1); 032 boolean flag1 = this.canConnectFenceTo(par1World, par2, par3, par4 + 1); 033 boolean flag2 = this.canConnectFenceTo(par1World, par2 - 1, par3, par4); 034 boolean flag3 = this.canConnectFenceTo(par1World, par2 + 1, par3, par4); 035 float f = 0.375F; 036 float f1 = 0.625F; 037 float f2 = 0.375F; 038 float f3 = 0.625F; 039 040 if (flag) 041 { 042 f2 = 0.0F; 043 } 044 045 if (flag1) 046 { 047 f3 = 1.0F; 048 } 049 050 if (flag || flag1) 051 { 052 this.setBlockBounds(f, 0.0F, f2, f1, 1.5F, f3); 053 super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity); 054 } 055 056 f2 = 0.375F; 057 f3 = 0.625F; 058 059 if (flag2) 060 { 061 f = 0.0F; 062 } 063 064 if (flag3) 065 { 066 f1 = 1.0F; 067 } 068 069 if (flag2 || flag3 || !flag && !flag1) 070 { 071 this.setBlockBounds(f, 0.0F, f2, f1, 1.5F, f3); 072 super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity); 073 } 074 075 if (flag) 076 { 077 f2 = 0.0F; 078 } 079 080 if (flag1) 081 { 082 f3 = 1.0F; 083 } 084 085 this.setBlockBounds(f, 0.0F, f2, f1, 1.0F, f3); 086 } 087 088 /** 089 * Updates the blocks bounds based on its current state. Args: world, x, y, z 090 */ 091 public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) 092 { 093 boolean flag = this.canConnectFenceTo(par1IBlockAccess, par2, par3, par4 - 1); 094 boolean flag1 = this.canConnectFenceTo(par1IBlockAccess, par2, par3, par4 + 1); 095 boolean flag2 = this.canConnectFenceTo(par1IBlockAccess, par2 - 1, par3, par4); 096 boolean flag3 = this.canConnectFenceTo(par1IBlockAccess, par2 + 1, par3, par4); 097 float f = 0.375F; 098 float f1 = 0.625F; 099 float f2 = 0.375F; 100 float f3 = 0.625F; 101 102 if (flag) 103 { 104 f2 = 0.0F; 105 } 106 107 if (flag1) 108 { 109 f3 = 1.0F; 110 } 111 112 if (flag2) 113 { 114 f = 0.0F; 115 } 116 117 if (flag3) 118 { 119 f1 = 1.0F; 120 } 121 122 this.setBlockBounds(f, 0.0F, f2, f1, 1.0F, f3); 123 } 124 125 /** 126 * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two 127 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. 128 */ 129 public boolean isOpaqueCube() 130 { 131 return false; 132 } 133 134 /** 135 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) 136 */ 137 public boolean renderAsNormalBlock() 138 { 139 return false; 140 } 141 142 public boolean getBlocksMovement(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) 143 { 144 return false; 145 } 146 147 /** 148 * The type of render function that is called for this block 149 */ 150 public int getRenderType() 151 { 152 return 11; 153 } 154 155 /** 156 * Returns true if the specified block can be connected by a fence 157 */ 158 public boolean canConnectFenceTo(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) 159 { 160 int l = par1IBlockAccess.getBlockId(par2, par3, par4); 161 162 if (l != this.blockID && l != Block.fenceGate.blockID) 163 { 164 Block block = Block.blocksList[l]; 165 return block != null && block.blockMaterial.isOpaque() && block.renderAsNormalBlock() ? block.blockMaterial != Material.pumpkin : false; 166 } 167 else 168 { 169 return true; 170 } 171 } 172 173 public static boolean isIdAFence(int par0) 174 { 175 return par0 == Block.fence.blockID || par0 == Block.netherFence.blockID; 176 } 177 178 @SideOnly(Side.CLIENT) 179 180 /** 181 * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given 182 * coordinates. Args: blockAccess, x, y, z, side 183 */ 184 public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) 185 { 186 return true; 187 } 188 189 @SideOnly(Side.CLIENT) 190 191 /** 192 * When this method is called, your block should register all the icons it needs with the given IconRegister. This 193 * is the only chance you get to register icons. 194 */ 195 public void registerIcons(IconRegister par1IconRegister) 196 { 197 this.blockIcon = par1IconRegister.registerIcon(this.field_94464_a); 198 } 199}