Guest User

Block

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