Guest User

BlockFenceGate.class

a guest
Nov 22nd, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.50 KB | None | 0 0
  1. package net.minecraft.block;
  2.  
  3. import cpw.mods.fml.relauncher.Side;
  4. import cpw.mods.fml.relauncher.SideOnly;
  5. import net.minecraft.block.material.Material;
  6. import net.minecraft.client.renderer.texture.IIconRegister;
  7. import net.minecraft.creativetab.CreativeTabs;
  8. import net.minecraft.entity.EntityLivingBase;
  9. import net.minecraft.entity.player.EntityPlayer;
  10. import net.minecraft.init.Blocks;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.util.AxisAlignedBB;
  13. import net.minecraft.util.IIcon;
  14. import net.minecraft.util.MathHelper;
  15. import net.minecraft.world.IBlockAccess;
  16. import net.minecraft.world.World;
  17.  
  18. public class BlockFenceGate extends BlockDirectional
  19. {
  20. private static final String __OBFID = "CL_00000243";
  21.  
  22. public BlockFenceGate()
  23. {
  24. super(Material.wood);
  25. this.setCreativeTab(CreativeTabs.tabRedstone);
  26. }
  27.  
  28. /**
  29. * Gets the block's texture. Args: side, meta
  30. */
  31. @SideOnly(Side.CLIENT)
  32. public IIcon getIcon(int p_149691_1_, int p_149691_2_)
  33. {
  34. return Blocks.planks.getBlockTextureFromSide(p_149691_1_);
  35. }
  36.  
  37. /**
  38. * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
  39. */
  40. public boolean canPlaceBlockAt(World p_149742_1_, int p_149742_2_, int p_149742_3_, int p_149742_4_)
  41. {
  42. return !p_149742_1_.getBlock(p_149742_2_, p_149742_3_ - 1, p_149742_4_).getMaterial().isSolid() ? false : super.canPlaceBlockAt(p_149742_1_, p_149742_2_, p_149742_3_, p_149742_4_);
  43. }
  44.  
  45. /**
  46. * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
  47. * cleared to be reused)
  48. */
  49. public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int p_149668_2_, int p_149668_3_, int p_149668_4_)
  50. {
  51. int l = p_149668_1_.getBlockMetadata(p_149668_2_, p_149668_3_, p_149668_4_);
  52. /**
  53. * Returns if the fence gate is open according to its metadata.
  54. */
  55. return isFenceGateOpen(l) ? null : (l != 2 && l != 0 ? AxisAlignedBB.getBoundingBox((double)((float)p_149668_2_ + 0.375F), (double)p_149668_3_, (double)p_149668_4_, (double)((float)p_149668_2_ + 0.625F), (double)((float)p_149668_3_ + 1.5F), (double)(p_149668_4_ + 1)) : AxisAlignedBB.getBoundingBox((double)p_149668_2_, (double)p_149668_3_, (double)((float)p_149668_4_ + 0.375F), (double)(p_149668_2_ + 1), (double)((float)p_149668_3_ + 1.5F), (double)((float)p_149668_4_ + 0.625F)));
  56. }
  57.  
  58. /**
  59. * Updates the blocks bounds based on its current state. Args: world, x, y, z
  60. */
  61. public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, int p_149719_4_)
  62. {
  63. int l = getDirection(p_149719_1_.getBlockMetadata(p_149719_2_, p_149719_3_, p_149719_4_));
  64.  
  65. if (l != 2 && l != 0)
  66. {
  67. this.setBlockBounds(0.375F, 0.0F, 0.0F, 0.625F, 1.0F, 1.0F);
  68. }
  69. else
  70. {
  71. this.setBlockBounds(0.0F, 0.0F, 0.375F, 1.0F, 1.0F, 0.625F);
  72. }
  73. }
  74.  
  75. /**
  76. * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two
  77. * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
  78. */
  79. public boolean isOpaqueCube()
  80. {
  81. return false;
  82. }
  83.  
  84. /**
  85. * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
  86. */
  87. public boolean renderAsNormalBlock()
  88. {
  89. return false;
  90. }
  91.  
  92. public boolean getBlocksMovement(IBlockAccess p_149655_1_, int p_149655_2_, int p_149655_3_, int p_149655_4_)
  93. {
  94. /**
  95. * Returns if the fence gate is open according to its metadata.
  96. */
  97. return isFenceGateOpen(p_149655_1_.getBlockMetadata(p_149655_2_, p_149655_3_, p_149655_4_));
  98. }
  99.  
  100. /**
  101. * The type of render function that is called for this block
  102. */
  103. public int getRenderType()
  104. {
  105. return 21;
  106. }
  107.  
  108. /**
  109. * Called when the block is placed in the world.
  110. */
  111. public void onBlockPlacedBy(World p_149689_1_, int p_149689_2_, int p_149689_3_, int p_149689_4_, EntityLivingBase p_149689_5_, ItemStack p_149689_6_)
  112. {
  113. int l = (MathHelper.floor_double((double)(p_149689_5_.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) % 4;
  114. p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, l, 2);
  115. }
  116.  
  117. /**
  118. * Called upon block activation (right click on the block.)
  119. */
  120. public boolean onBlockActivated(World p_149727_1_, int p_149727_2_, int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)
  121. {
  122. int i1 = p_149727_1_.getBlockMetadata(p_149727_2_, p_149727_3_, p_149727_4_);
  123.  
  124. if (isFenceGateOpen(i1))
  125. {
  126. p_149727_1_.setBlockMetadataWithNotify(p_149727_2_, p_149727_3_, p_149727_4_, i1 & -5, 2);
  127. }
  128. else
  129. {
  130. int j1 = (MathHelper.floor_double((double)(p_149727_5_.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) % 4;
  131. int k1 = getDirection(i1);
  132.  
  133. if (k1 == (j1 + 2) % 4)
  134. {
  135. i1 = j1;
  136. }
  137.  
  138. p_149727_1_.setBlockMetadataWithNotify(p_149727_2_, p_149727_3_, p_149727_4_, i1 | 4, 2);
  139. }
  140.  
  141. p_149727_1_.playAuxSFXAtEntity(p_149727_5_, 1003, p_149727_2_, p_149727_3_, p_149727_4_, 0);
  142. return true;
  143. }
  144.  
  145. /**
  146. * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
  147. * their own) Args: x, y, z, neighbor Block
  148. */
  149. public void onNeighborBlockChange(World p_149695_1_, int p_149695_2_, int p_149695_3_, int p_149695_4_, Block p_149695_5_)
  150. {
  151. if (!p_149695_1_.isRemote)
  152. {
  153. int l = p_149695_1_.getBlockMetadata(p_149695_2_, p_149695_3_, p_149695_4_);
  154. boolean flag = p_149695_1_.isBlockIndirectlyGettingPowered(p_149695_2_, p_149695_3_, p_149695_4_);
  155.  
  156. if (flag || p_149695_5_.canProvidePower())
  157. {
  158. if (flag && !isFenceGateOpen(l))
  159. {
  160. p_149695_1_.setBlockMetadataWithNotify(p_149695_2_, p_149695_3_, p_149695_4_, l | 4, 2);
  161. p_149695_1_.playAuxSFXAtEntity((EntityPlayer)null, 1003, p_149695_2_, p_149695_3_, p_149695_4_, 0);
  162. }
  163. else if (!flag && isFenceGateOpen(l))
  164. {
  165. p_149695_1_.setBlockMetadataWithNotify(p_149695_2_, p_149695_3_, p_149695_4_, l & -5, 2);
  166. p_149695_1_.playAuxSFXAtEntity((EntityPlayer)null, 1003, p_149695_2_, p_149695_3_, p_149695_4_, 0);
  167. }
  168. }
  169. }
  170. }
  171.  
  172. /**
  173. * Returns if the fence gate is open according to its metadata.
  174. */
  175. public static boolean isFenceGateOpen(int p_149896_0_)
  176. {
  177. return (p_149896_0_ & 4) != 0;
  178. }
  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. @SideOnly(Side.CLIENT)
  185. public boolean shouldSideBeRendered(IBlockAccess p_149646_1_, int p_149646_2_, int p_149646_3_, int p_149646_4_, int p_149646_5_)
  186. {
  187. return true;
  188. }
  189.  
  190. @SideOnly(Side.CLIENT)
  191. public void registerBlockIcons(IIconRegister p_149651_1_) {}
  192. }
Advertisement
Add Comment
Please, Sign In to add comment