lol123406

PortalFire.java

Feb 27th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 16.23 KB | None | 0 0
  1. package lol123406.mod;
  2.  
  3. import static net.minecraftforge.common.ForgeDirection.DOWN;
  4. import static net.minecraftforge.common.ForgeDirection.EAST;
  5. import static net.minecraftforge.common.ForgeDirection.NORTH;
  6. import static net.minecraftforge.common.ForgeDirection.SOUTH;
  7. import static net.minecraftforge.common.ForgeDirection.UP;
  8. import static net.minecraftforge.common.ForgeDirection.WEST;
  9. import java.util.Random;
  10. import cpw.mods.fml.relauncher.Side;
  11. import cpw.mods.fml.relauncher.SideOnly;
  12. import net.minecraft.block.Block;
  13. import net.minecraft.block.BlockFire;
  14. import net.minecraft.block.material.Material;
  15. import net.minecraft.client.renderer.texture.IconRegister;
  16. import net.minecraft.util.AxisAlignedBB;
  17. import net.minecraft.util.Icon;
  18. import net.minecraft.world.IBlockAccess;
  19. import net.minecraft.world.World;
  20. import net.minecraftforge.common.ForgeDirection;
  21. public class PortalFire extends BlockFire
  22. {
  23. public PortalFire(int par1, Material par2Material) {
  24. super(par1);
  25. }
  26. /** The chance this block will encourage nearby blocks to catch on fire */
  27. private int[] chanceToEncourageFire = new int[256];
  28. /**
  29. * This is an array indexed by block ID the larger the number in the array the more likely a block type will catch
  30. * fires
  31. */
  32. private int[] abilityToCatchFire = new int[256];
  33. @SideOnly(Side.CLIENT)
  34. private Icon[] iconArray;
  35. protected PortalFire(int par1)
  36. {
  37. super(par1);
  38. this.setTickRandomly(true);
  39. }
  40. /**
  41. * This method is called on a block after all other blocks gets already created. You can use it to reference and
  42. * configure something on the block that needs the others ones.
  43. */
  44. public void initializeBlock()
  45. {
  46. abilityToCatchFire = Block.blockFlammability;
  47. chanceToEncourageFire = Block.blockFireSpreadSpeed;
  48. this.setBurnRate(Block.planks.blockID, 5, 20);
  49. this.setBurnRate(Block.woodDoubleSlab.blockID, 5, 20);
  50. this.setBurnRate(Block.woodSingleSlab.blockID, 5, 20);
  51. this.setBurnRate(Block.fence.blockID, 5, 20);
  52. this.setBurnRate(Block.stairsWoodOak.blockID, 5, 20);
  53. this.setBurnRate(Block.stairsWoodBirch.blockID, 5, 20);
  54. this.setBurnRate(Block.stairsWoodSpruce.blockID, 5, 20);
  55. this.setBurnRate(Block.stairsWoodJungle.blockID, 5, 20);
  56. this.setBurnRate(Block.wood.blockID, 5, 5);
  57. this.setBurnRate(Block.leaves.blockID, 30, 60);
  58. this.setBurnRate(Block.bookShelf.blockID, 30, 20);
  59. this.setBurnRate(Block.tnt.blockID, 15, 100);
  60. this.setBurnRate(Block.tallGrass.blockID, 60, 100);
  61. this.setBurnRate(Block.cloth.blockID, 30, 60);
  62. this.setBurnRate(Block.vine.blockID, 15, 100);
  63. }
  64. /**
  65. * Sets the burn rate for a block. The larger abilityToCatchFire the more easily it will catch. The larger
  66. * chanceToEncourageFire the faster it will burn and spread to other blocks. Args: blockID, chanceToEncourageFire,
  67. * abilityToCatchFire
  68. */
  69. private void setBurnRate(int par1, int par2, int par3)
  70. {
  71. Block.setBurnProperties(par1, par2, par3);
  72. }
  73. /**
  74. * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
  75. * cleared to be reused)
  76. */
  77. public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
  78. {
  79. return null;
  80. }
  81. /**
  82. * Is this block (a) opaque and (B) a full 1m cube? This determines whether or not to render the shared face of two
  83. * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
  84. */
  85. public boolean isOpaqueCube()
  86. {
  87. return false;
  88. }
  89. /**
  90. * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
  91. */
  92. public boolean renderAsNormalBlock()
  93. {
  94. return false;
  95. }
  96. /**
  97. * The type of render function that is called for this block
  98. */
  99. public int getRenderType()
  100. {
  101. return 3;
  102. }
  103. /**
  104. * Returns the quantity of items to drop on block destruction.
  105. */
  106. public int quantityDropped(Random par1Random)
  107. {
  108. return 0;
  109. }
  110. /**
  111. * How many world ticks before ticking
  112. */
  113. public int tickRate(World par1World)
  114. {
  115. return 30;
  116. }
  117. /**
  118. * Ticks the block if it's been scheduled
  119. */
  120. public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
  121. {
  122. if (par1World.getGameRules().getGameRuleBooleanValue("doFireTick"))
  123. {
  124. Block base = Block.blocksList[par1World.getBlockId(par2, par3 - 1, par4)];
  125. boolean flag = (base != null && base.isFireSource(par1World, par2, par3 - 1, par4, par1World.getBlockMetadata(par2, par3 - 1, par4), UP));
  126. if (!this.canPlaceBlockAt(par1World, par2, par3, par4))
  127. {
  128. par1World.setBlockToAir(par2, par3, par4);
  129. }
  130. if (!flag && par1World.isRaining() && (par1World.canLightningStrikeAt(par2, par3, par4) || par1World.canLightningStrikeAt(par2 - 1, par3, par4) || par1World.canLightningStrikeAt(par2 + 1, par3, par4) || par1World.canLightningStrikeAt(par2, par3, par4 - 1) || par1World.canLightningStrikeAt(par2, par3, par4 + 1)))
  131. {
  132. par1World.setBlockToAir(par2, par3, par4);
  133. }
  134. else
  135. {
  136. int l = par1World.getBlockMetadata(par2, par3, par4);
  137. if (l < 15)
  138. {
  139. par1World.setBlockMetadataWithNotify(par2, par3, par4, l + par5Random.nextInt(3) / 2, 4);
  140. }
  141. par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate(par1World) + par5Random.nextInt(10));
  142. if (!flag && !this.canNeighborBurn(par1World, par2, par3, par4))
  143. {
  144. if (!par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4) || l > 3)
  145. {
  146. par1World.setBlockToAir(par2, par3, par4);
  147. }
  148. }
  149. else if (!flag && !this.canBlockCatchFire(par1World, par2, par3 - 1, par4, UP) && l == 15 && par5Random.nextInt(4) == 0)
  150. {
  151. par1World.setBlockToAir(par2, par3, par4);
  152. }
  153. else
  154. {
  155. boolean flag1 = par1World.isBlockHighHumidity(par2, par3, par4);
  156. byte b0 = 0;
  157. if (flag1)
  158. {
  159. b0 = -50;
  160. }
  161. this.tryToCatchBlockOnFire(par1World, par2 + 1, par3, par4, 300 + b0, par5Random, l, WEST );
  162. this.tryToCatchBlockOnFire(par1World, par2 - 1, par3, par4, 300 + b0, par5Random, l, EAST );
  163. this.tryToCatchBlockOnFire(par1World, par2, par3 - 1, par4, 250 + b0, par5Random, l, UP );
  164. this.tryToCatchBlockOnFire(par1World, par2, par3 + 1, par4, 250 + b0, par5Random, l, DOWN );
  165. this.tryToCatchBlockOnFire(par1World, par2, par3, par4 - 1, 300 + b0, par5Random, l, SOUTH);
  166. this.tryToCatchBlockOnFire(par1World, par2, par3, par4 + 1, 300 + b0, par5Random, l, NORTH);
  167. for (int i1 = par2 - 1; i1 <= par2 + 1; ++i1)
  168. {
  169. for (int j1 = par4 - 1; j1 <= par4 + 1; ++j1)
  170. {
  171. for (int k1 = par3 - 1; k1 <= par3 + 4; ++k1)
  172. {
  173. if (i1 != par2 || k1 != par3 || j1 != par4)
  174. {
  175. int l1 = 100;
  176. if (k1 > par3 + 1)
  177. {
  178. l1 += (k1 - (par3 + 1)) * 100;
  179. }
  180. int i2 = this.getChanceOfNeighborsEncouragingFire(par1World, i1, k1, j1);
  181. if (i2 > 0)
  182. {
  183. int j2 = (i2 + 40 + par1World.difficultySetting * 7) / (l + 30);
  184. if (flag1)
  185. {
  186. j2 /= 2;
  187. }
  188. if (j2 > 0 && par5Random.nextInt(l1) <= j2 && (!par1World.isRaining() || !par1World.canLightningStrikeAt(i1, k1, j1)) && !par1World.canLightningStrikeAt(i1 - 1, k1, par4) && !par1World.canLightningStrikeAt(i1 + 1, k1, j1) && !par1World.canLightningStrikeAt(i1, k1, j1 - 1) && !par1World.canLightningStrikeAt(i1, k1, j1 + 1))
  189. {
  190. int k2 = l + par5Random.nextInt(5) / 4;
  191. if (k2 > 15)
  192. {
  193. k2 = 15;
  194. }
  195. par1World.setBlock(i1, k1, j1, this.blockID, k2, 3);
  196. }
  197. }
  198. }
  199. }
  200. }
  201. }
  202. }
  203. }
  204. }
  205. }
  206. public boolean func_82506_l()
  207. {
  208. return false;
  209. }
  210. @Deprecated
  211. private void tryToCatchBlockOnFire(World par1World, int par2, int par3, int par4, int par5, Random par6Random, int par7)
  212. {
  213. tryToCatchBlockOnFire(par1World, par2, par3, par4, par5, par6Random, par7, UP);
  214. }
  215. private void tryToCatchBlockOnFire(World par1World, int par2, int par3, int par4, int par5, Random par6Random, int par7, ForgeDirection face)
  216. {
  217. int j1 = 0;
  218. Block block = Block.blocksList[par1World.getBlockId(par2, par3, par4)];
  219. if (block != null)
  220. {
  221. j1 = block.getFlammability(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), face);
  222. }
  223. if (par6Random.nextInt(par5) < j1)
  224. {
  225. boolean flag = par1World.getBlockId(par2, par3, par4) == Block.tnt.blockID;
  226. if (par6Random.nextInt(par7 + 10) < 5 && !par1World.canLightningStrikeAt(par2, par3, par4))
  227. {
  228. int k1 = par7 + par6Random.nextInt(5) / 4;
  229. if (k1 > 15)
  230. {
  231. k1 = 15;
  232. }
  233. par1World.setBlock(par2, par3, par4, this.blockID, k1, 3);
  234. }
  235. else
  236. {
  237. par1World.setBlockToAir(par2, par3, par4);
  238. }
  239. if (flag)
  240. {
  241. Block.tnt.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1);
  242. }
  243. }
  244. }
  245. /**
  246. * Returns true if at least one block next to this one can burn.
  247. */
  248. private boolean canNeighborBurn(World par1World, int par2, int par3, int par4)
  249. {
  250. return canBlockCatchFire(par1World, par2 + 1, par3, par4, WEST ) ||
  251. canBlockCatchFire(par1World, par2 - 1, par3, par4, EAST ) ||
  252. canBlockCatchFire(par1World, par2, par3 - 1, par4, UP ) ||
  253. canBlockCatchFire(par1World, par2, par3 + 1, par4, DOWN ) ||
  254. canBlockCatchFire(par1World, par2, par3, par4 - 1, SOUTH) ||
  255. canBlockCatchFire(par1World, par2, par3, par4 + 1, NORTH);
  256. }
  257. /**
  258. * Gets the highest chance of a neighbor block encouraging this block to catch fire
  259. */
  260. private int getChanceOfNeighborsEncouragingFire(World par1World, int par2, int par3, int par4)
  261. {
  262. byte b0 = 0;
  263. if (!par1World.isAirBlock(par2, par3, par4))
  264. {
  265. return 0;
  266. }
  267. else
  268. {
  269. int l = this.getChanceToEncourageFire(par1World, par2 + 1, par3, par4, b0, WEST);
  270. l = this.getChanceToEncourageFire(par1World, par2 - 1, par3, par4, l, EAST);
  271. l = this.getChanceToEncourageFire(par1World, par2, par3 - 1, par4, l, UP);
  272. l = this.getChanceToEncourageFire(par1World, par2, par3 + 1, par4, l, DOWN);
  273. l = this.getChanceToEncourageFire(par1World, par2, par3, par4 - 1, l, SOUTH);
  274. l = this.getChanceToEncourageFire(par1World, par2, par3, par4 + 1, l, NORTH);
  275. return l;
  276. }
  277. }
  278. /**
  279. * Returns if this block is collidable (only used by Fire). Args: x, y, z
  280. */
  281. public boolean isCollidable()
  282. {
  283. return false;
  284. }
  285. /**
  286. * Checks the specified block coordinate to see if it can catch fire. Args: blockAccess, x, y, z
  287. * Deprecated for a side-sensitive version
  288. */
  289. @Deprecated
  290. public boolean canBlockCatchFire(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
  291. {
  292. return canBlockCatchFire(par1IBlockAccess, par2, par3, par4, UP);
  293. }
  294. /**
  295. * Retrieves a specified block's chance to encourage their neighbors to burn and if the number is greater than the
  296. * current number passed in it will return its number instead of the passed in one. Args: world, x, y, z,
  297. * curChanceToEncourageFire
  298. * Deprecated for a side-sensitive version
  299. */
  300. @Deprecated
  301. public int getChanceToEncourageFire(World par1World, int par2, int par3, int par4, int par5)
  302. {
  303. return getChanceToEncourageFire(par1World, par2, par3, par4, par5, UP);
  304. }
  305. /**
  306. * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
  307. */
  308. public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
  309. {
  310. return par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4) || this.canNeighborBurn(par1World, par2, par3, par4);
  311. }
  312. /**
  313. * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
  314. * their own) Args: x, y, z, neighbor blockID
  315. */
  316. public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
  317. {
  318. if (!par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4) && !this.canNeighborBurn(par1World, par2, par3, par4))
  319. {
  320. par1World.setBlockToAir(par2, par3, par4);
  321. }
  322. }
  323. /**
  324. * Called whenever the block is added into the world. Args: world, x, y, z
  325. */
  326. public void onBlockAdded(World par1World, int par2, int par3, int par4)
  327. {
  328. if (par1World.provider.dimensionId > 0 || par1World.getBlockId(par2, par3 - 1, par4) != Lol123406mod.onyxblock.blockID || !((GemPortalblock) Lol123406mod.GemPortalblock).tryToCreatePortal(par1World, par2, par3, par4))
  329. if (!par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4) && !this.canNeighborBurn(par1World, par2, par3, par4))
  330. {
  331. par1World.setBlockToAir(par2, par3, par4);
  332. }
  333. else
  334. {
  335. par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate(par1World) + par1World.rand.nextInt(10));
  336. }
  337. }
  338. @SideOnly(Side.CLIENT)
  339. /**
  340. * A randomly called display update to be able to add particles or other items for display
  341. */
  342. public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
  343. {
  344. if (par5Random.nextInt(24) == 0)
  345. {
  346. par1World.playSound((double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F), "fire.fire", 1.0F + par5Random.nextFloat(), par5Random.nextFloat() * 0.7F + 0.3F, false);
  347. }
  348. int l;
  349. float f;
  350. float f1;
  351. float f2;
  352. if (!par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4) && !Block.fire.canBlockCatchFire(par1World, par2, par3 - 1, par4, UP))
  353. {
  354. if (Block.fire.canBlockCatchFire(par1World, par2 - 1, par3, par4, EAST))
  355. {
  356. for (l = 0; l < 2; ++l)
  357. {
  358. f = (float)par2 + par5Random.nextFloat() * 0.1F;
  359. f1 = (float)par3 + par5Random.nextFloat();
  360. f2 = (float)par4 + par5Random.nextFloat();
  361. par1World.spawnParticle("largesmoke", (double)f, (double)f1, (double)f2, 0.0D, 0.0D, 0.0D);
  362. }
  363. }
  364. if (Block.fire.canBlockCatchFire(par1World, par2 + 1, par3, par4, WEST))
  365. {
  366. for (l = 0; l < 2; ++l)
  367. {
  368. f = (float)(par2 + 1) - par5Random.nextFloat() * 0.1F;
  369. f1 = (float)par3 + par5Random.nextFloat();
  370. f2 = (float)par4 + par5Random.nextFloat();
  371. par1World.spawnParticle("largesmoke", (double)f, (double)f1, (double)f2, 0.0D, 0.0D, 0.0D);
  372. }
  373. }
  374. if (Block.fire.canBlockCatchFire(par1World, par2, par3, par4 - 1, SOUTH))
  375. {
  376. for (l = 0; l < 2; ++l)
  377. {
  378. f = (float)par2 + par5Random.nextFloat();
  379. f1 = (float)par3 + par5Random.nextFloat();
  380. f2 = (float)par4 + par5Random.nextFloat() * 0.1F;
  381. par1World.spawnParticle("largesmoke", (double)f, (double)f1, (double)f2, 0.0D, 0.0D, 0.0D);
  382. }
  383. }
  384. if (Block.fire.canBlockCatchFire(par1World, par2, par3, par4 + 1, NORTH))
  385. {
  386. for (l = 0; l < 2; ++l)
  387. {
  388. f = (float)par2 + par5Random.nextFloat();
  389. f1 = (float)par3 + par5Random.nextFloat();
  390. f2 = (float)(par4 + 1) - par5Random.nextFloat() * 0.1F;
  391. par1World.spawnParticle("largesmoke", (double)f, (double)f1, (double)f2, 0.0D, 0.0D, 0.0D);
  392. }
  393. }
  394. if (Block.fire.canBlockCatchFire(par1World, par2, par3 + 1, par4, DOWN))
  395. {
  396. for (l = 0; l < 2; ++l)
  397. {
  398. f = (float)par2 + par5Random.nextFloat();
  399. f1 = (float)(par3 + 1) - par5Random.nextFloat() * 0.1F;
  400. f2 = (float)par4 + par5Random.nextFloat();
  401. par1World.spawnParticle("largesmoke", (double)f, (double)f1, (double)f2, 0.0D, 0.0D, 0.0D);
  402. }
  403. }
  404. }
  405. else
  406. {
  407. for (l = 0; l < 3; ++l)
  408. {
  409. f = (float)par2 + par5Random.nextFloat();
  410. f1 = (float)par3 + par5Random.nextFloat() * 0.5F + 0.5F;
  411. f2 = (float)par4 + par5Random.nextFloat();
  412. par1World.spawnParticle("largesmoke", (double)f, (double)f1, (double)f2, 0.0D, 0.0D, 0.0D);
  413. }
  414. }
  415. }
  416. @SideOnly(Side.CLIENT)
  417. /**
  418. * When this method is called, your block should register all the icons it needs with the given IconRegister. This
  419. * is the only chance you get to register icons.
  420. */
  421. public void registerIcons(IconRegister par1IconRegister)
  422. {
  423. this.iconArray = new Icon[] {par1IconRegister.registerIcon("fire_0"), par1IconRegister.registerIcon("fire_1")};
  424. }
  425. @SideOnly(Side.CLIENT)
  426. public Icon func_94438_c(int par1)
  427. {
  428. return this.iconArray[par1];
  429. }
  430. @SideOnly(Side.CLIENT)
  431. /**
  432. * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
  433. */
  434. public Icon getIcon(int par1, int par2)
  435. {
  436. return this.iconArray[0];
  437. }
  438. /**
  439. * Side sensitive version that calls the block function.
  440. *
  441. * @param world The current world
  442. * @param x X Position
  443. * @param y Y Position
  444. * @param z Z Position
  445. * @param face The side the fire is coming from
  446. * @return True if the face can catch fire.
  447. */
  448. public boolean canBlockCatchFire(IBlockAccess world, int x, int y, int z, ForgeDirection face)
  449. {
  450. Block block = Block.blocksList[world.getBlockId(x, y, z)];
  451. if (block != null)
  452. {
  453. return block.isFlammable(world, x, y, z, world.getBlockMetadata(x, y, z), face);
  454. }
  455. return false;
  456. }
  457. /**
  458. * Side sensitive version that calls the block function.
  459. *
  460. * @param world The current world
  461. * @param x X Position
  462. * @param y Y Position
  463. * @param z Z Position
  464. * @param oldChance The previous maximum chance.
  465. * @param face The side the fire is coming from
  466. * @return The chance of the block catching fire, or oldChance if it is higher
  467. */
  468. public int getChanceToEncourageFire(World world, int x, int y, int z, int oldChance, ForgeDirection face)
  469. {
  470. int newChance = 0;
  471. Block block = Block.blocksList[world.getBlockId(x, y, z)];
  472. if (block != null)
  473. {
  474. newChance = block.getFireSpreadSpeed(world, x, y, z, world.getBlockMetadata(x, y, z), face);
  475. }
  476. return (newChance > oldChance ? newChance : oldChance);
  477. }
  478. }
Advertisement
Add Comment
Please, Sign In to add comment