Guest User

IronBlockFenceGate.java

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