Advertisement
Guest User

BlockCopperDoor

a guest
Oct 29th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.63 KB | None | 0 0
  1. package com.smith.mod.doors;
  2.  
  3. import java.util.Random;
  4.  
  5. import com.smith.mod.Smithing;
  6.  
  7. import net.minecraft.block.Block;
  8. import net.minecraft.block.material.Material;
  9. import net.minecraft.client.renderer.IconFlipped;
  10. import net.minecraft.client.renderer.texture.IIconRegister;
  11. import net.minecraft.entity.player.EntityPlayer;
  12. import net.minecraft.init.Items;
  13. import net.minecraft.item.Item;
  14. import net.minecraft.util.AxisAlignedBB;
  15. import net.minecraft.util.IIcon;
  16. import net.minecraft.util.MovingObjectPosition;
  17. import net.minecraft.util.Vec3;
  18. import net.minecraft.world.IBlockAccess;
  19. import net.minecraft.world.World;
  20. import cpw.mods.fml.relauncher.Side;
  21. import cpw.mods.fml.relauncher.SideOnly;
  22.  
  23. public class BlockCopperDoor extends Block {
  24.  
  25. @SideOnly(Side.CLIENT)
  26. private IIcon[] blockicona;
  27. @SideOnly(Side.CLIENT)
  28. private IIcon[] blockiconb;
  29. private static final String __OBFID = "CL_00000230";
  30.  
  31. public BlockCopperDoor(Material material)
  32. {
  33. super(material);
  34. float f = 0.5F;
  35. float f1 = 1.0F;
  36. this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f1, 0.5F + f);
  37. }
  38.  
  39. /**
  40. * Gets the block's texture. Args: side, meta
  41. */
  42. @SideOnly(Side.CLIENT)
  43. public IIcon getIcon(int p_149691_1_, int p_149691_2_)
  44. {
  45. return this.blockiconb[0];
  46. }
  47.  
  48. @SideOnly(Side.CLIENT)
  49. public IIcon getIcon(IBlockAccess p_149673_1_, int p_149673_2_, int p_149673_3_, int p_149673_4_, int p_149673_5_)
  50. {
  51. if (p_149673_5_ != 1 && p_149673_5_ != 0)
  52. {
  53. int i1 = this.func_150012_g(p_149673_1_, p_149673_2_, p_149673_3_, p_149673_4_);
  54. int j1 = i1 & 3;
  55. boolean flag = (i1 & 4) != 0;
  56. boolean flag1 = false;
  57. boolean flag2 = (i1 & 8) != 0;
  58.  
  59. if (flag)
  60. {
  61. if (j1 == 0 && p_149673_5_ == 2)
  62. {
  63. flag1 = !flag1;
  64. }
  65. else if (j1 == 1 && p_149673_5_ == 5)
  66. {
  67. flag1 = !flag1;
  68. }
  69. else if (j1 == 2 && p_149673_5_ == 3)
  70. {
  71. flag1 = !flag1;
  72. }
  73. else if (j1 == 3 && p_149673_5_ == 4)
  74. {
  75. flag1 = !flag1;
  76. }
  77. }
  78. else
  79. {
  80. if (j1 == 0 && p_149673_5_ == 5)
  81. {
  82. flag1 = !flag1;
  83. }
  84. else if (j1 == 1 && p_149673_5_ == 3)
  85. {
  86. flag1 = !flag1;
  87. }
  88. else if (j1 == 2 && p_149673_5_ == 4)
  89. {
  90. flag1 = !flag1;
  91. }
  92. else if (j1 == 3 && p_149673_5_ == 2)
  93. {
  94. flag1 = !flag1;
  95. }
  96.  
  97. if ((i1 & 16) != 0)
  98. {
  99. flag1 = !flag1;
  100. }
  101. }
  102.  
  103. return flag2 ? this.blockicona[flag1?1:0] : this.blockiconb[flag1?1:0];
  104. }
  105. else
  106. {
  107. return this.blockiconb[0];
  108. }
  109. }
  110.  
  111. @SideOnly(Side.CLIENT)
  112. public void registerBlockIcons(IIconRegister p_149651_1_)
  113. {
  114. this.blockicona = new IIcon[2];
  115. this.blockiconb = new IIcon[2];
  116. this.blockicona[0] = p_149651_1_.registerIcon(Smithing.modid + ":" + this.getUnlocalizedName().substring(5) + "_Upper");
  117. this.blockiconb[0] = p_149651_1_.registerIcon(Smithing.modid + ":" + this.getUnlocalizedName().substring(5) + "_Lower");
  118. this.blockicona[1] = new IconFlipped(this.blockicona[0], true, false);
  119. this.blockiconb[1] = new IconFlipped(this.blockiconb[0], true, false);
  120. }
  121.  
  122. /**
  123. * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two
  124. * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
  125. */
  126. public boolean isOpaqueCube()
  127. {
  128. return false;
  129. }
  130.  
  131. public boolean getBlocksMovement(IBlockAccess p_149655_1_, int p_149655_2_, int p_149655_3_, int p_149655_4_)
  132. {
  133. int l = this.func_150012_g(p_149655_1_, p_149655_2_, p_149655_3_, p_149655_4_);
  134. return (l & 4) != 0;
  135. }
  136.  
  137. /**
  138. * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
  139. */
  140. public boolean renderAsNormalBlock()
  141. {
  142. return false;
  143. }
  144.  
  145. /**
  146. * The type of render function that is called for this block
  147. */
  148. public int getRenderType()
  149. {
  150. return 7;
  151. }
  152.  
  153. /**
  154. * Returns the bounding box of the wired rectangular prism to render.
  155. */
  156. @SideOnly(Side.CLIENT)
  157. public AxisAlignedBB getSelectedBoundingBoxFromPool(World p_149633_1_, int p_149633_2_, int p_149633_3_, int p_149633_4_)
  158. {
  159. this.setBlockBoundsBasedOnState(p_149633_1_, p_149633_2_, p_149633_3_, p_149633_4_);
  160. return super.getSelectedBoundingBoxFromPool(p_149633_1_, p_149633_2_, p_149633_3_, p_149633_4_);
  161. }
  162.  
  163. /**
  164. * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
  165. * cleared to be reused)
  166. */
  167. public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int p_149668_2_, int p_149668_3_, int p_149668_4_)
  168. {
  169. this.setBlockBoundsBasedOnState(p_149668_1_, p_149668_2_, p_149668_3_, p_149668_4_);
  170. return super.getCollisionBoundingBoxFromPool(p_149668_1_, p_149668_2_, p_149668_3_, p_149668_4_);
  171. }
  172.  
  173. /**
  174. * Updates the blocks bounds based on its current state. Args: world, x, y, z
  175. */
  176. public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, int p_149719_4_)
  177. {
  178. this.func_150011_b(this.func_150012_g(p_149719_1_, p_149719_2_, p_149719_3_, p_149719_4_));
  179. }
  180.  
  181. public int func_150013_e(IBlockAccess p_150013_1_, int p_150013_2_, int p_150013_3_, int p_150013_4_)
  182. {
  183. return this.func_150012_g(p_150013_1_, p_150013_2_, p_150013_3_, p_150013_4_) & 3;
  184. }
  185.  
  186. public boolean func_150015_f(IBlockAccess p_150015_1_, int p_150015_2_, int p_150015_3_, int p_150015_4_)
  187. {
  188. return (this.func_150012_g(p_150015_1_, p_150015_2_, p_150015_3_, p_150015_4_) & 4) != 0;
  189. }
  190.  
  191. private void func_150011_b(int p_150011_1_)
  192. {
  193. float f = 0.1875F;
  194. this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F);
  195. int j = p_150011_1_ & 3;
  196. boolean flag = (p_150011_1_ & 4) != 0;
  197. boolean flag1 = (p_150011_1_ & 16) != 0;
  198.  
  199. if (j == 0)
  200. {
  201. if (flag)
  202. {
  203. if (!flag1)
  204. {
  205. this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
  206. }
  207. else
  208. {
  209. this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
  210. }
  211. }
  212. else
  213. {
  214. this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
  215. }
  216. }
  217. else if (j == 1)
  218. {
  219. if (flag)
  220. {
  221. if (!flag1)
  222. {
  223. this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
  224. }
  225. else
  226. {
  227. this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
  228. }
  229. }
  230. else
  231. {
  232. this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
  233. }
  234. }
  235. else if (j == 2)
  236. {
  237. if (flag)
  238. {
  239. if (!flag1)
  240. {
  241. this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
  242. }
  243. else
  244. {
  245. this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
  246. }
  247. }
  248. else
  249. {
  250. this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
  251. }
  252. }
  253. else if (j == 3)
  254. {
  255. if (flag)
  256. {
  257. if (!flag1)
  258. {
  259. this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
  260. }
  261. else
  262. {
  263. this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
  264. }
  265. }
  266. else
  267. {
  268. this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
  269. }
  270. }
  271. }
  272.  
  273. /**
  274. * Called when a player hits the block. Args: world, x, y, z, player
  275. */
  276. public void onBlockClicked(World p_149699_1_, int p_149699_2_, int p_149699_3_, int p_149699_4_, EntityPlayer p_149699_5_) {}
  277.  
  278. /**
  279. * Called upon block activation (right click on the block.)
  280. */
  281. 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_)
  282. {
  283. if (this.blockMaterial == Material.iron)
  284. {
  285. return false; //Allow items to interact with the door
  286. }
  287. else
  288. {
  289. int i1 = this.func_150012_g(p_149727_1_, p_149727_2_, p_149727_3_, p_149727_4_);
  290. int j1 = i1 & 7;
  291. j1 ^= 4;
  292.  
  293. if ((i1 & 8) == 0)
  294. {
  295. p_149727_1_.setBlockMetadataWithNotify(p_149727_2_, p_149727_3_, p_149727_4_, j1, 2);
  296. p_149727_1_.markBlockRangeForRenderUpdate(p_149727_2_, p_149727_3_, p_149727_4_, p_149727_2_, p_149727_3_, p_149727_4_);
  297. }
  298. else
  299. {
  300. p_149727_1_.setBlockMetadataWithNotify(p_149727_2_, p_149727_3_ - 1, p_149727_4_, j1, 2);
  301. p_149727_1_.markBlockRangeForRenderUpdate(p_149727_2_, p_149727_3_ - 1, p_149727_4_, p_149727_2_, p_149727_3_, p_149727_4_);
  302. }
  303.  
  304. p_149727_1_.playAuxSFXAtEntity(p_149727_5_, 1003, p_149727_2_, p_149727_3_, p_149727_4_, 0);
  305. return true;
  306. }
  307. }
  308.  
  309. public void func_150014_a(World p_150014_1_, int p_150014_2_, int p_150014_3_, int p_150014_4_, boolean p_150014_5_)
  310. {
  311. int l = this.func_150012_g(p_150014_1_, p_150014_2_, p_150014_3_, p_150014_4_);
  312. boolean flag1 = (l & 4) != 0;
  313.  
  314. if (flag1 != p_150014_5_)
  315. {
  316. int i1 = l & 7;
  317. i1 ^= 4;
  318.  
  319. if ((l & 8) == 0)
  320. {
  321. p_150014_1_.setBlockMetadataWithNotify(p_150014_2_, p_150014_3_, p_150014_4_, i1, 2);
  322. p_150014_1_.markBlockRangeForRenderUpdate(p_150014_2_, p_150014_3_, p_150014_4_, p_150014_2_, p_150014_3_, p_150014_4_);
  323. }
  324. else
  325. {
  326. p_150014_1_.setBlockMetadataWithNotify(p_150014_2_, p_150014_3_ - 1, p_150014_4_, i1, 2);
  327. p_150014_1_.markBlockRangeForRenderUpdate(p_150014_2_, p_150014_3_ - 1, p_150014_4_, p_150014_2_, p_150014_3_, p_150014_4_);
  328. }
  329.  
  330. p_150014_1_.playAuxSFXAtEntity((EntityPlayer)null, 1003, p_150014_2_, p_150014_3_, p_150014_4_, 0);
  331. }
  332. }
  333.  
  334. /**
  335. * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
  336. * their own) Args: x, y, z, neighbor Block
  337. */
  338. public void onNeighborBlockChange(World p_149695_1_, int p_149695_2_, int p_149695_3_, int p_149695_4_, Block p_149695_5_)
  339. {
  340. int l = p_149695_1_.getBlockMetadata(p_149695_2_, p_149695_3_, p_149695_4_);
  341.  
  342. if ((l & 8) == 0)
  343. {
  344. boolean flag = false;
  345.  
  346. if (p_149695_1_.getBlock(p_149695_2_, p_149695_3_ + 1, p_149695_4_) != this)
  347. {
  348. p_149695_1_.setBlockToAir(p_149695_2_, p_149695_3_, p_149695_4_);
  349. flag = true;
  350. }
  351.  
  352. if (!World.doesBlockHaveSolidTopSurface(p_149695_1_, p_149695_2_, p_149695_3_ - 1, p_149695_4_))
  353. {
  354. p_149695_1_.setBlockToAir(p_149695_2_, p_149695_3_, p_149695_4_);
  355. flag = true;
  356.  
  357. if (p_149695_1_.getBlock(p_149695_2_, p_149695_3_ + 1, p_149695_4_) == this)
  358. {
  359. p_149695_1_.setBlockToAir(p_149695_2_, p_149695_3_ + 1, p_149695_4_);
  360. }
  361. }
  362.  
  363. if (flag)
  364. {
  365. if (!p_149695_1_.isRemote)
  366. {
  367. this.dropBlockAsItem(p_149695_1_, p_149695_2_, p_149695_3_, p_149695_4_, l, 0);
  368. }
  369. }
  370. else
  371. {
  372. boolean flag1 = p_149695_1_.isBlockIndirectlyGettingPowered(p_149695_2_, p_149695_3_, p_149695_4_) || p_149695_1_.isBlockIndirectlyGettingPowered(p_149695_2_, p_149695_3_ + 1, p_149695_4_);
  373.  
  374. if ((flag1 || p_149695_5_.canProvidePower()) && p_149695_5_ != this)
  375. {
  376. this.func_150014_a(p_149695_1_, p_149695_2_, p_149695_3_, p_149695_4_, flag1);
  377. }
  378. }
  379. }
  380. else
  381. {
  382. if (p_149695_1_.getBlock(p_149695_2_, p_149695_3_ - 1, p_149695_4_) != this)
  383. {
  384. p_149695_1_.setBlockToAir(p_149695_2_, p_149695_3_, p_149695_4_);
  385. }
  386.  
  387. if (p_149695_5_ != this)
  388. {
  389. this.onNeighborBlockChange(p_149695_1_, p_149695_2_, p_149695_3_ - 1, p_149695_4_, p_149695_5_);
  390. }
  391. }
  392. }
  393.  
  394. public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
  395. {
  396. return (p_149650_1_ & 8) != 0 ? null : (this.blockMaterial == Material.iron ? Items.iron_door : Items.wooden_door);
  397. }
  398.  
  399. /**
  400. * Ray traces through the blocks collision from start vector to end vector returning a ray trace hit. Args: world,
  401. * x, y, z, startVec, endVec
  402. */
  403. public MovingObjectPosition collisionRayTrace(World p_149731_1_, int p_149731_2_, int p_149731_3_, int p_149731_4_, Vec3 p_149731_5_, Vec3 p_149731_6_)
  404. {
  405. this.setBlockBoundsBasedOnState(p_149731_1_, p_149731_2_, p_149731_3_, p_149731_4_);
  406. return super.collisionRayTrace(p_149731_1_, p_149731_2_, p_149731_3_, p_149731_4_, p_149731_5_, p_149731_6_);
  407. }
  408.  
  409. /**
  410. * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
  411. */
  412. public boolean canPlaceBlockAt(World p_149742_1_, int p_149742_2_, int p_149742_3_, int p_149742_4_)
  413. {
  414. return p_149742_3_ >= p_149742_1_.getHeight() - 1 ? false : World.doesBlockHaveSolidTopSurface(p_149742_1_, p_149742_2_, p_149742_3_ - 1, p_149742_4_) && super.canPlaceBlockAt(p_149742_1_, p_149742_2_, p_149742_3_, p_149742_4_) && super.canPlaceBlockAt(p_149742_1_, p_149742_2_, p_149742_3_ + 1, p_149742_4_);
  415. }
  416.  
  417. /**
  418. * Returns the mobility information of the block, 0 = free, 1 = can't push but can move over, 2 = total immobility
  419. * and stop pistons
  420. */
  421. public int getMobilityFlag()
  422. {
  423. return 1;
  424. }
  425.  
  426. public int func_150012_g(IBlockAccess p_150012_1_, int p_150012_2_, int p_150012_3_, int p_150012_4_)
  427. {
  428. int l = p_150012_1_.getBlockMetadata(p_150012_2_, p_150012_3_, p_150012_4_);
  429. boolean flag = (l & 8) != 0;
  430. int i1;
  431. int j1;
  432.  
  433. if (flag)
  434. {
  435. i1 = p_150012_1_.getBlockMetadata(p_150012_2_, p_150012_3_ - 1, p_150012_4_);
  436. j1 = l;
  437. }
  438. else
  439. {
  440. i1 = l;
  441. j1 = p_150012_1_.getBlockMetadata(p_150012_2_, p_150012_3_ + 1, p_150012_4_);
  442. }
  443.  
  444. boolean flag1 = (j1 & 1) != 0;
  445. return i1 & 7 | (flag ? 8 : 0) | (flag1 ? 16 : 0);
  446. }
  447.  
  448. /**
  449. * Gets an item for the block being called on. Args: world, x, y, z
  450. */
  451. @SideOnly(Side.CLIENT)
  452. public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_, int p_149694_4_)
  453. {
  454. return this.blockMaterial == Material.iron ? Items.iron_door : Items.wooden_door;
  455. }
  456.  
  457. /**
  458. * Called when the block is attempted to be harvested
  459. */
  460. public void onBlockHarvested(World p_149681_1_, int p_149681_2_, int p_149681_3_, int p_149681_4_, int p_149681_5_, EntityPlayer p_149681_6_)
  461. {
  462. if (p_149681_6_.capabilities.isCreativeMode && (p_149681_5_ & 8) != 0 && p_149681_1_.getBlock(p_149681_2_, p_149681_3_ - 1, p_149681_4_) == this)
  463. {
  464. p_149681_1_.setBlockToAir(p_149681_2_, p_149681_3_ - 1, p_149681_4_);
  465. }
  466. }
  467. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement