001 package net.minecraft.block; 002 003 import cpw.mods.fml.relauncher.Side; 004 import cpw.mods.fml.relauncher.SideOnly; 005 import java.util.List; 006 import java.util.Random; 007 import net.minecraft.block.material.Material; 008 import net.minecraft.entity.Entity; 009 import net.minecraft.util.AxisAlignedBB; 010 import net.minecraft.util.Facing; 011 import net.minecraft.world.IBlockAccess; 012 import net.minecraft.world.World; 013 014 public abstract class BlockHalfSlab extends Block 015 { 016 private final boolean isDoubleSlab; 017 018 public BlockHalfSlab(int par1, boolean par2, Material par3Material) 019 { 020 super(par1, 6, par3Material); 021 this.isDoubleSlab = par2; 022 023 if (par2) 024 { 025 opaqueCubeLookup[par1] = true; 026 } 027 else 028 { 029 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F); 030 } 031 032 this.setLightOpacity(255); 033 } 034 035 /** 036 * Updates the blocks bounds based on its current state. Args: world, x, y, z 037 */ 038 public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) 039 { 040 if (this.isDoubleSlab) 041 { 042 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); 043 } 044 else 045 { 046 boolean var5 = (par1IBlockAccess.getBlockMetadata(par2, par3, par4) & 8) != 0; 047 048 if (var5) 049 { 050 this.setBlockBounds(0.0F, 0.5F, 0.0F, 1.0F, 1.0F, 1.0F); 051 } 052 else 053 { 054 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F); 055 } 056 } 057 } 058 059 /** 060 * Sets the block's bounds for rendering it as an item 061 */ 062 public void setBlockBoundsForItemRender() 063 { 064 if (this.isDoubleSlab) 065 { 066 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); 067 } 068 else 069 { 070 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F); 071 } 072 } 073 074 /** 075 * if the specified block is in the given AABB, add its collision bounding box to the given list 076 */ 077 public void addCollidingBlockToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity) 078 { 079 this.setBlockBoundsBasedOnState(par1World, par2, par3, par4); 080 super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity); 081 } 082 083 /** 084 * Returns the block texture based on the side being looked at. Args: side 085 */ 086 public int getBlockTextureFromSide(int par1) 087 { 088 return this.getBlockTextureFromSideAndMetadata(par1, 0); 089 } 090 091 /** 092 * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two 093 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. 094 */ 095 public boolean isOpaqueCube() 096 { 097 return this.isDoubleSlab; 098 } 099 100 public int func_85104_a(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9) 101 { 102 return this.isDoubleSlab ? par9 : (par5 != 0 && (par5 == 1 || (double)par7 <= 0.5D) ? par9 : par9 | 8); 103 } 104 105 /** 106 * Returns the quantity of items to drop on block destruction. 107 */ 108 public int quantityDropped(Random par1Random) 109 { 110 return this.isDoubleSlab ? 2 : 1; 111 } 112 113 /** 114 * Determines the damage on the item the block drops. Used in cloth and wood. 115 */ 116 public int damageDropped(int par1) 117 { 118 return par1 & 7; 119 } 120 121 /** 122 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) 123 */ 124 public boolean renderAsNormalBlock() 125 { 126 return this.isDoubleSlab; 127 } 128 129 @SideOnly(Side.CLIENT) 130 131 /** 132 * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given 133 * coordinates. Args: blockAccess, x, y, z, side 134 */ 135 public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) 136 { 137 if (this.isDoubleSlab) 138 { 139 return super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5); 140 } 141 else if (par5 != 1 && par5 != 0 && !super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5)) 142 { 143 return false; 144 } 145 else 146 { 147 int var6 = par2 + Facing.offsetsXForSide[Facing.faceToSide[par5]]; 148 int var7 = par3 + Facing.offsetsYForSide[Facing.faceToSide[par5]]; 149 int var8 = par4 + Facing.offsetsZForSide[Facing.faceToSide[par5]]; 150 boolean var9 = (par1IBlockAccess.getBlockMetadata(var6, var7, var8) & 8) != 0; 151 return var9 ? (par5 == 0 ? true : (par5 == 1 && super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5) ? true : !isBlockSingleSlab(par1IBlockAccess.getBlockId(par2, par3, par4)) || (par1IBlockAccess.getBlockMetadata(par2, par3, par4) & 8) == 0)) : (par5 == 1 ? true : (par5 == 0 && super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5) ? true : !isBlockSingleSlab(par1IBlockAccess.getBlockId(par2, par3, par4)) || (par1IBlockAccess.getBlockMetadata(par2, par3, par4) & 8) != 0)); 152 } 153 } 154 155 @SideOnly(Side.CLIENT) 156 157 /** 158 * Takes a block ID, returns true if it's the same as the ID for a stone or wooden single slab. 159 */ 160 private static boolean isBlockSingleSlab(int par0) 161 { 162 return par0 == Block.stoneSingleSlab.blockID || par0 == Block.woodSingleSlab.blockID; 163 } 164 165 /** 166 * Returns the slab block name with step type. 167 */ 168 public abstract String getFullSlabName(int var1); 169 170 /** 171 * Get the block's damage value (for use with pick block). 172 */ 173 public int getDamageValue(World par1World, int par2, int par3, int par4) 174 { 175 return super.getDamageValue(par1World, par2, par3, par4) & 7; 176 } 177 178 @SideOnly(Side.CLIENT) 179 180 /** 181 * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative) 182 */ 183 public int idPicked(World par1World, int par2, int par3, int par4) 184 { 185 return isBlockSingleSlab(this.blockID) ? this.blockID : (this.blockID == Block.stoneDoubleSlab.blockID ? Block.stoneSingleSlab.blockID : (this.blockID == Block.woodDoubleSlab.blockID ? Block.woodSingleSlab.blockID : Block.stoneSingleSlab.blockID)); 186 } 187 }