001 package net.minecraft.block; 002 003 import cpw.mods.fml.common.Side; 004 import cpw.mods.fml.common.asm.SideOnly; 005 import java.util.Random; 006 import net.minecraft.block.material.Material; 007 import net.minecraft.creativetab.CreativeTabs; 008 import net.minecraft.util.AxisAlignedBB; 009 import net.minecraft.world.IBlockAccess; 010 import net.minecraft.world.World; 011 012 import net.minecraftforge.common.ForgeDirection; 013 import static net.minecraftforge.common.ForgeDirection.*; 014 015 public class BlockLadder extends Block 016 { 017 protected BlockLadder(int par1, int par2) 018 { 019 super(par1, par2, Material.circuits); 020 this.setCreativeTab(CreativeTabs.tabDecorations); 021 } 022 023 /** 024 * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been 025 * cleared to be reused) 026 */ 027 public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) 028 { 029 this.setBlockBoundsBasedOnState(par1World, par2, par3, par4); 030 return super.getCollisionBoundingBoxFromPool(par1World, par2, par3, par4); 031 } 032 033 @SideOnly(Side.CLIENT) 034 035 /** 036 * Returns the bounding box of the wired rectangular prism to render. 037 */ 038 public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4) 039 { 040 this.setBlockBoundsBasedOnState(par1World, par2, par3, par4); 041 return super.getSelectedBoundingBoxFromPool(par1World, par2, par3, par4); 042 } 043 044 /** 045 * Updates the blocks bounds based on its current state. Args: world, x, y, z 046 */ 047 public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) 048 { 049 this.func_85107_d(par1IBlockAccess.getBlockMetadata(par2, par3, par4)); 050 } 051 052 public void func_85107_d(int par1) 053 { 054 float var3 = 0.125F; 055 056 if (par1 == 2) 057 { 058 this.setBlockBounds(0.0F, 0.0F, 1.0F - var3, 1.0F, 1.0F, 1.0F); 059 } 060 061 if (par1 == 3) 062 { 063 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, var3); 064 } 065 066 if (par1 == 4) 067 { 068 this.setBlockBounds(1.0F - var3, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); 069 } 070 071 if (par1 == 5) 072 { 073 this.setBlockBounds(0.0F, 0.0F, 0.0F, var3, 1.0F, 1.0F); 074 } 075 } 076 077 /** 078 * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two 079 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. 080 */ 081 public boolean isOpaqueCube() 082 { 083 return false; 084 } 085 086 /** 087 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) 088 */ 089 public boolean renderAsNormalBlock() 090 { 091 return false; 092 } 093 094 /** 095 * The type of render function that is called for this block 096 */ 097 public int getRenderType() 098 { 099 return 8; 100 } 101 102 /** 103 * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z 104 */ 105 public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) 106 { 107 return par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST ) || 108 par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST ) || 109 par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH) || 110 par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH); 111 } 112 113 public int func_85104_a(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9) 114 { 115 int var10 = par9; 116 117 if ((var10 == 0 || par5 == 2) && par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH)) 118 { 119 var10 = 2; 120 } 121 122 if ((var10 == 0 || par5 == 3) && par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH)) 123 { 124 var10 = 3; 125 } 126 127 if ((var10 == 0 || par5 == 4) && par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST)) 128 { 129 var10 = 4; 130 } 131 132 if ((var10 == 0 || par5 == 5) && par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST)) 133 { 134 var10 = 5; 135 } 136 137 return var10; 138 } 139 140 /** 141 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are 142 * their own) Args: x, y, z, neighbor blockID 143 */ 144 public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) 145 { 146 int var6 = par1World.getBlockMetadata(par2, par3, par4); 147 boolean var7 = false; 148 149 if (var6 == 2 && par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH)) 150 { 151 var7 = true; 152 } 153 154 if (var6 == 3 && par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH)) 155 { 156 var7 = true; 157 } 158 159 if (var6 == 4 && par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST)) 160 { 161 var7 = true; 162 } 163 164 if (var6 == 5 && par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST)) 165 { 166 var7 = true; 167 } 168 169 if (!var7) 170 { 171 this.dropBlockAsItem(par1World, par2, par3, par4, var6, 0); 172 par1World.setBlockWithNotify(par2, par3, par4, 0); 173 } 174 175 super.onNeighborBlockChange(par1World, par2, par3, par4, par5); 176 } 177 178 /** 179 * Returns the quantity of items to drop on block destruction. 180 */ 181 public int quantityDropped(Random par1Random) 182 { 183 return 1; 184 } 185 186 @Override 187 public boolean isLadder(World world, int x, int y, int z) 188 { 189 return true; 190 } 191 }