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.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.updateLadderBounds(par1IBlockAccess.getBlockMetadata(par2, par3, par4));
050 }
051
052 /**
053 * Update the ladder block bounds based on the given metadata value.
054 */
055 public void updateLadderBounds(int par1)
056 {
057 float var3 = 0.125F;
058
059 if (par1 == 2)
060 {
061 this.setBlockBounds(0.0F, 0.0F, 1.0F - var3, 1.0F, 1.0F, 1.0F);
062 }
063
064 if (par1 == 3)
065 {
066 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, var3);
067 }
068
069 if (par1 == 4)
070 {
071 this.setBlockBounds(1.0F - var3, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
072 }
073
074 if (par1 == 5)
075 {
076 this.setBlockBounds(0.0F, 0.0F, 0.0F, var3, 1.0F, 1.0F);
077 }
078 }
079
080 /**
081 * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two
082 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
083 */
084 public boolean isOpaqueCube()
085 {
086 return false;
087 }
088
089 /**
090 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
091 */
092 public boolean renderAsNormalBlock()
093 {
094 return false;
095 }
096
097 /**
098 * The type of render function that is called for this block
099 */
100 public int getRenderType()
101 {
102 return 8;
103 }
104
105 /**
106 * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
107 */
108 public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
109 {
110 return par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST ) ||
111 par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST ) ||
112 par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH) ||
113 par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH);
114 }
115
116 public int func_85104_a(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9)
117 {
118 int var10 = par9;
119
120 if ((var10 == 0 || par5 == 2) && par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH))
121 {
122 var10 = 2;
123 }
124
125 if ((var10 == 0 || par5 == 3) && par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH))
126 {
127 var10 = 3;
128 }
129
130 if ((var10 == 0 || par5 == 4) && par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST))
131 {
132 var10 = 4;
133 }
134
135 if ((var10 == 0 || par5 == 5) && par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST))
136 {
137 var10 = 5;
138 }
139
140 return var10;
141 }
142
143 /**
144 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
145 * their own) Args: x, y, z, neighbor blockID
146 */
147 public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
148 {
149 int var6 = par1World.getBlockMetadata(par2, par3, par4);
150 boolean var7 = false;
151
152 if (var6 == 2 && par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH))
153 {
154 var7 = true;
155 }
156
157 if (var6 == 3 && par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH))
158 {
159 var7 = true;
160 }
161
162 if (var6 == 4 && par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST))
163 {
164 var7 = true;
165 }
166
167 if (var6 == 5 && par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST))
168 {
169 var7 = true;
170 }
171
172 if (!var7)
173 {
174 this.dropBlockAsItem(par1World, par2, par3, par4, var6, 0);
175 par1World.setBlockWithNotify(par2, par3, par4, 0);
176 }
177
178 super.onNeighborBlockChange(par1World, par2, par3, par4, par5);
179 }
180
181 /**
182 * Returns the quantity of items to drop on block destruction.
183 */
184 public int quantityDropped(Random par1Random)
185 {
186 return 1;
187 }
188
189 @Override
190 public boolean isLadder(World world, int x, int y, int z)
191 {
192 return true;
193 }
194 }