/Client/src/net/minecraft/src/ChunkProviderHell.java

http://phantom-labs-mc.googlecode.com/ · Java · 551 lines · 426 code · 83 blank · 42 comment · 66 complexity · a1faf004b3e2fc837182f44dc0ad2802 MD5 · raw file

  1. package net.minecraft.src;
  2. import java.util.List;
  3. import java.util.Random;
  4. public class ChunkProviderHell implements IChunkProvider
  5. {
  6. private Random hellRNG;
  7. /** A NoiseGeneratorOctaves used in generating nether terrain */
  8. private NoiseGeneratorOctaves netherNoiseGen1;
  9. private NoiseGeneratorOctaves netherNoiseGen2;
  10. private NoiseGeneratorOctaves netherNoiseGen3;
  11. /** Determines whether slowsand or gravel can be generated at a location */
  12. private NoiseGeneratorOctaves slowsandGravelNoiseGen;
  13. /**
  14. * Determines whether something other than nettherack can be generated at a location
  15. */
  16. private NoiseGeneratorOctaves netherrackExculsivityNoiseGen;
  17. public NoiseGeneratorOctaves netherNoiseGen6;
  18. public NoiseGeneratorOctaves netherNoiseGen7;
  19. /** Is the world that the nether is getting generated. */
  20. private World worldObj;
  21. private double field_4163_o[];
  22. public MapGenNetherBridge genNetherBridge;
  23. private double slowsandNoise[];
  24. private double gravelNoise[];
  25. private double netherrackExclusivityNoise[];
  26. private MapGenBase netherCaveGenerator;
  27. double noiseData1[];
  28. double noiseData2[];
  29. double noiseData3[];
  30. double noiseData4[];
  31. double noiseData5[];
  32. public ChunkProviderHell(World par1World, long par2)
  33. {
  34. genNetherBridge = new MapGenNetherBridge();
  35. slowsandNoise = new double[256];
  36. gravelNoise = new double[256];
  37. netherrackExclusivityNoise = new double[256];
  38. netherCaveGenerator = new MapGenCavesHell();
  39. worldObj = par1World;
  40. hellRNG = new Random(par2);
  41. netherNoiseGen1 = new NoiseGeneratorOctaves(hellRNG, 16);
  42. netherNoiseGen2 = new NoiseGeneratorOctaves(hellRNG, 16);
  43. netherNoiseGen3 = new NoiseGeneratorOctaves(hellRNG, 8);
  44. slowsandGravelNoiseGen = new NoiseGeneratorOctaves(hellRNG, 4);
  45. netherrackExculsivityNoiseGen = new NoiseGeneratorOctaves(hellRNG, 4);
  46. netherNoiseGen6 = new NoiseGeneratorOctaves(hellRNG, 10);
  47. netherNoiseGen7 = new NoiseGeneratorOctaves(hellRNG, 16);
  48. }
  49. /**
  50. * Generates the shape of the terrain in the nether.
  51. */
  52. public void generateNetherTerrain(int par1, int par2, byte par3ArrayOfByte[])
  53. {
  54. byte byte0 = 4;
  55. byte byte1 = 32;
  56. int i = byte0 + 1;
  57. byte byte2 = 17;
  58. int j = byte0 + 1;
  59. field_4163_o = func_4057_a(field_4163_o, par1 * byte0, 0, par2 * byte0, i, byte2, j);
  60. for (int k = 0; k < byte0; k++)
  61. {
  62. for (int l = 0; l < byte0; l++)
  63. {
  64. for (int i1 = 0; i1 < 16; i1++)
  65. {
  66. double d = 0.125D;
  67. double d1 = field_4163_o[((k + 0) * j + (l + 0)) * byte2 + (i1 + 0)];
  68. double d2 = field_4163_o[((k + 0) * j + (l + 1)) * byte2 + (i1 + 0)];
  69. double d3 = field_4163_o[((k + 1) * j + (l + 0)) * byte2 + (i1 + 0)];
  70. double d4 = field_4163_o[((k + 1) * j + (l + 1)) * byte2 + (i1 + 0)];
  71. double d5 = (field_4163_o[((k + 0) * j + (l + 0)) * byte2 + (i1 + 1)] - d1) * d;
  72. double d6 = (field_4163_o[((k + 0) * j + (l + 1)) * byte2 + (i1 + 1)] - d2) * d;
  73. double d7 = (field_4163_o[((k + 1) * j + (l + 0)) * byte2 + (i1 + 1)] - d3) * d;
  74. double d8 = (field_4163_o[((k + 1) * j + (l + 1)) * byte2 + (i1 + 1)] - d4) * d;
  75. for (int j1 = 0; j1 < 8; j1++)
  76. {
  77. double d9 = 0.25D;
  78. double d10 = d1;
  79. double d11 = d2;
  80. double d12 = (d3 - d1) * d9;
  81. double d13 = (d4 - d2) * d9;
  82. for (int k1 = 0; k1 < 4; k1++)
  83. {
  84. int l1 = k1 + k * 4 << 11 | 0 + l * 4 << 7 | i1 * 8 + j1;
  85. char c = '\200';
  86. double d14 = 0.25D;
  87. double d15 = d10;
  88. double d16 = (d11 - d10) * d14;
  89. for (int i2 = 0; i2 < 4; i2++)
  90. {
  91. int j2 = 0;
  92. if (i1 * 8 + j1 < byte1)
  93. {
  94. j2 = Block.lavaStill.blockID;
  95. }
  96. if (d15 > 0.0D)
  97. {
  98. j2 = Block.netherrack.blockID;
  99. }
  100. par3ArrayOfByte[l1] = (byte)j2;
  101. l1 += c;
  102. d15 += d16;
  103. }
  104. d10 += d12;
  105. d11 += d13;
  106. }
  107. d1 += d5;
  108. d2 += d6;
  109. d3 += d7;
  110. d4 += d8;
  111. }
  112. }
  113. }
  114. }
  115. }
  116. public void func_4058_b(int par1, int par2, byte par3ArrayOfByte[])
  117. {
  118. byte byte0 = 64;
  119. double d = 0.03125D;
  120. slowsandNoise = slowsandGravelNoiseGen.generateNoiseOctaves(slowsandNoise, par1 * 16, par2 * 16, 0, 16, 16, 1, d, d, 1.0D);
  121. gravelNoise = slowsandGravelNoiseGen.generateNoiseOctaves(gravelNoise, par1 * 16, 109, par2 * 16, 16, 1, 16, d, 1.0D, d);
  122. netherrackExclusivityNoise = netherrackExculsivityNoiseGen.generateNoiseOctaves(netherrackExclusivityNoise, par1 * 16, par2 * 16, 0, 16, 16, 1, d * 2D, d * 2D, d * 2D);
  123. for (int i = 0; i < 16; i++)
  124. {
  125. for (int j = 0; j < 16; j++)
  126. {
  127. boolean flag = slowsandNoise[i + j * 16] + hellRNG.nextDouble() * 0.20000000000000001D > 0.0D;
  128. boolean flag1 = gravelNoise[i + j * 16] + hellRNG.nextDouble() * 0.20000000000000001D > 0.0D;
  129. int k = (int)(netherrackExclusivityNoise[i + j * 16] / 3D + 3D + hellRNG.nextDouble() * 0.25D);
  130. int l = -1;
  131. byte byte1 = (byte)Block.netherrack.blockID;
  132. byte byte2 = (byte)Block.netherrack.blockID;
  133. for (int i1 = 127; i1 >= 0; i1--)
  134. {
  135. int j1 = (j * 16 + i) * 128 + i1;
  136. if (i1 >= 127 - hellRNG.nextInt(5))
  137. {
  138. par3ArrayOfByte[j1] = (byte)Block.bedrock.blockID;
  139. continue;
  140. }
  141. if (i1 <= 0 + hellRNG.nextInt(5))
  142. {
  143. par3ArrayOfByte[j1] = (byte)Block.bedrock.blockID;
  144. continue;
  145. }
  146. byte byte3 = par3ArrayOfByte[j1];
  147. if (byte3 == 0)
  148. {
  149. l = -1;
  150. continue;
  151. }
  152. if (byte3 != Block.netherrack.blockID)
  153. {
  154. continue;
  155. }
  156. if (l == -1)
  157. {
  158. if (k <= 0)
  159. {
  160. byte1 = 0;
  161. byte2 = (byte)Block.netherrack.blockID;
  162. }
  163. else if (i1 >= byte0 - 4 && i1 <= byte0 + 1)
  164. {
  165. byte1 = (byte)Block.netherrack.blockID;
  166. byte2 = (byte)Block.netherrack.blockID;
  167. if (flag1)
  168. {
  169. byte1 = (byte)Block.gravel.blockID;
  170. }
  171. if (flag1)
  172. {
  173. byte2 = (byte)Block.netherrack.blockID;
  174. }
  175. if (flag)
  176. {
  177. byte1 = (byte)Block.slowSand.blockID;
  178. }
  179. if (flag)
  180. {
  181. byte2 = (byte)Block.slowSand.blockID;
  182. }
  183. }
  184. if (i1 < byte0 && byte1 == 0)
  185. {
  186. byte1 = (byte)Block.lavaStill.blockID;
  187. }
  188. l = k;
  189. if (i1 >= byte0 - 1)
  190. {
  191. par3ArrayOfByte[j1] = byte1;
  192. }
  193. else
  194. {
  195. par3ArrayOfByte[j1] = byte2;
  196. }
  197. continue;
  198. }
  199. if (l > 0)
  200. {
  201. l--;
  202. par3ArrayOfByte[j1] = byte2;
  203. }
  204. }
  205. }
  206. }
  207. }
  208. /**
  209. * loads or generates the chunk at the chunk location specified
  210. */
  211. public Chunk loadChunk(int par1, int par2)
  212. {
  213. return provideChunk(par1, par2);
  214. }
  215. /**
  216. * Will return back a chunk, if it doesn't exist and its not a MP client it will generates all the blocks for the
  217. * specified chunk from the map seed and chunk seed
  218. */
  219. public Chunk provideChunk(int par1, int par2)
  220. {
  221. hellRNG.setSeed((long)par1 * 0x4f9939f508L + (long)par2 * 0x1ef1565bd5L);
  222. byte abyte0[] = new byte[32768];
  223. generateNetherTerrain(par1, par2, abyte0);
  224. func_4058_b(par1, par2, abyte0);
  225. netherCaveGenerator.generate(this, worldObj, par1, par2, abyte0);
  226. genNetherBridge.generate(this, worldObj, par1, par2, abyte0);
  227. Chunk chunk = new Chunk(worldObj, abyte0, par1, par2);
  228. BiomeGenBase abiomegenbase[] = worldObj.getWorldChunkManager().loadBlockGeneratorData(null, par1 * 16, par2 * 16, 16, 16);
  229. byte abyte1[] = chunk.getBiomeArray();
  230. for (int i = 0; i < abyte1.length; i++)
  231. {
  232. abyte1[i] = (byte)abiomegenbase[i].biomeID;
  233. }
  234. chunk.resetRelightChecks();
  235. return chunk;
  236. }
  237. private double[] func_4057_a(double par1ArrayOfDouble[], int par2, int par3, int par4, int par5, int par6, int par7)
  238. {
  239. if (par1ArrayOfDouble == null)
  240. {
  241. par1ArrayOfDouble = new double[par5 * par6 * par7];
  242. }
  243. double d = 684.41200000000003D;
  244. double d1 = 2053.2359999999999D;
  245. noiseData4 = netherNoiseGen6.generateNoiseOctaves(noiseData4, par2, par3, par4, par5, 1, par7, 1.0D, 0.0D, 1.0D);
  246. noiseData5 = netherNoiseGen7.generateNoiseOctaves(noiseData5, par2, par3, par4, par5, 1, par7, 100D, 0.0D, 100D);
  247. noiseData1 = netherNoiseGen3.generateNoiseOctaves(noiseData1, par2, par3, par4, par5, par6, par7, d / 80D, d1 / 60D, d / 80D);
  248. noiseData2 = netherNoiseGen1.generateNoiseOctaves(noiseData2, par2, par3, par4, par5, par6, par7, d, d1, d);
  249. noiseData3 = netherNoiseGen2.generateNoiseOctaves(noiseData3, par2, par3, par4, par5, par6, par7, d, d1, d);
  250. int i = 0;
  251. int j = 0;
  252. double ad[] = new double[par6];
  253. for (int k = 0; k < par6; k++)
  254. {
  255. ad[k] = Math.cos(((double)k * Math.PI * 6D) / (double)par6) * 2D;
  256. double d2 = k;
  257. if (k > par6 / 2)
  258. {
  259. d2 = par6 - 1 - k;
  260. }
  261. if (d2 < 4D)
  262. {
  263. d2 = 4D - d2;
  264. ad[k] -= d2 * d2 * d2 * 10D;
  265. }
  266. }
  267. for (int l = 0; l < par5; l++)
  268. {
  269. for (int i1 = 0; i1 < par7; i1++)
  270. {
  271. double d3 = (noiseData4[j] + 256D) / 512D;
  272. if (d3 > 1.0D)
  273. {
  274. d3 = 1.0D;
  275. }
  276. double d4 = 0.0D;
  277. double d5 = noiseData5[j] / 8000D;
  278. if (d5 < 0.0D)
  279. {
  280. d5 = -d5;
  281. }
  282. d5 = d5 * 3D - 3D;
  283. if (d5 < 0.0D)
  284. {
  285. d5 /= 2D;
  286. if (d5 < -1D)
  287. {
  288. d5 = -1D;
  289. }
  290. d5 /= 1.3999999999999999D;
  291. d5 /= 2D;
  292. d3 = 0.0D;
  293. }
  294. else
  295. {
  296. if (d5 > 1.0D)
  297. {
  298. d5 = 1.0D;
  299. }
  300. d5 /= 6D;
  301. }
  302. d3 += 0.5D;
  303. d5 = (d5 * (double)par6) / 16D;
  304. j++;
  305. for (int j1 = 0; j1 < par6; j1++)
  306. {
  307. double d6 = 0.0D;
  308. double d7 = ad[j1];
  309. double d8 = noiseData2[i] / 512D;
  310. double d9 = noiseData3[i] / 512D;
  311. double d10 = (noiseData1[i] / 10D + 1.0D) / 2D;
  312. if (d10 < 0.0D)
  313. {
  314. d6 = d8;
  315. }
  316. else if (d10 > 1.0D)
  317. {
  318. d6 = d9;
  319. }
  320. else
  321. {
  322. d6 = d8 + (d9 - d8) * d10;
  323. }
  324. d6 -= d7;
  325. if (j1 > par6 - 4)
  326. {
  327. double d11 = (float)(j1 - (par6 - 4)) / 3F;
  328. d6 = d6 * (1.0D - d11) + -10D * d11;
  329. }
  330. if ((double)j1 < d4)
  331. {
  332. double d12 = (d4 - (double)j1) / 4D;
  333. if (d12 < 0.0D)
  334. {
  335. d12 = 0.0D;
  336. }
  337. if (d12 > 1.0D)
  338. {
  339. d12 = 1.0D;
  340. }
  341. d6 = d6 * (1.0D - d12) + -10D * d12;
  342. }
  343. par1ArrayOfDouble[i] = d6;
  344. i++;
  345. }
  346. }
  347. }
  348. return par1ArrayOfDouble;
  349. }
  350. /**
  351. * Checks to see if a chunk exists at x, y
  352. */
  353. public boolean chunkExists(int par1, int par2)
  354. {
  355. return true;
  356. }
  357. /**
  358. * Populates chunk with ores etc etc
  359. */
  360. public void populate(IChunkProvider par1IChunkProvider, int par2, int par3)
  361. {
  362. BlockSand.fallInstantly = true;
  363. int i = par2 * 16;
  364. int j = par3 * 16;
  365. genNetherBridge.generateStructuresInChunk(worldObj, hellRNG, par2, par3);
  366. for (int k = 0; k < 8; k++)
  367. {
  368. int i1 = i + hellRNG.nextInt(16) + 8;
  369. int k2 = hellRNG.nextInt(120) + 4;
  370. int i4 = j + hellRNG.nextInt(16) + 8;
  371. (new WorldGenHellLava(Block.lavaMoving.blockID)).generate(worldObj, hellRNG, i1, k2, i4);
  372. }
  373. int l = hellRNG.nextInt(hellRNG.nextInt(10) + 1) + 1;
  374. for (int j1 = 0; j1 < l; j1++)
  375. {
  376. int l2 = i + hellRNG.nextInt(16) + 8;
  377. int j4 = hellRNG.nextInt(120) + 4;
  378. int k5 = j + hellRNG.nextInt(16) + 8;
  379. (new WorldGenFire()).generate(worldObj, hellRNG, l2, j4, k5);
  380. }
  381. l = hellRNG.nextInt(hellRNG.nextInt(10) + 1);
  382. for (int k1 = 0; k1 < l; k1++)
  383. {
  384. int i3 = i + hellRNG.nextInt(16) + 8;
  385. int k4 = hellRNG.nextInt(120) + 4;
  386. int l5 = j + hellRNG.nextInt(16) + 8;
  387. (new WorldGenGlowStone1()).generate(worldObj, hellRNG, i3, k4, l5);
  388. }
  389. for (int l1 = 0; l1 < 10; l1++)
  390. {
  391. int j3 = i + hellRNG.nextInt(16) + 8;
  392. int l4 = hellRNG.nextInt(128);
  393. int i6 = j + hellRNG.nextInt(16) + 8;
  394. (new WorldGenGlowStone2()).generate(worldObj, hellRNG, j3, l4, i6);
  395. }
  396. if (hellRNG.nextInt(1) == 0)
  397. {
  398. int i2 = i + hellRNG.nextInt(16) + 8;
  399. int k3 = hellRNG.nextInt(128);
  400. int i5 = j + hellRNG.nextInt(16) + 8;
  401. (new WorldGenFlowers(Block.mushroomBrown.blockID)).generate(worldObj, hellRNG, i2, k3, i5);
  402. }
  403. if (hellRNG.nextInt(1) == 0)
  404. {
  405. int j2 = i + hellRNG.nextInt(16) + 8;
  406. int l3 = hellRNG.nextInt(128);
  407. int j5 = j + hellRNG.nextInt(16) + 8;
  408. (new WorldGenFlowers(Block.mushroomRed.blockID)).generate(worldObj, hellRNG, j2, l3, j5);
  409. }
  410. BlockSand.fallInstantly = false;
  411. }
  412. /**
  413. * Two modes of operation: if passed true, save all Chunks in one go. If passed false, save up to two chunks.
  414. * Return true if all chunks have been saved.
  415. */
  416. public boolean saveChunks(boolean par1, IProgressUpdate par2IProgressUpdate)
  417. {
  418. return true;
  419. }
  420. /**
  421. * Unloads the 100 oldest chunks from memory, due to a bug with chunkSet.add() never being called it thinks the list
  422. * is always empty and will not remove any chunks.
  423. */
  424. public boolean unload100OldestChunks()
  425. {
  426. return false;
  427. }
  428. /**
  429. * Returns if the IChunkProvider supports saving.
  430. */
  431. public boolean canSave()
  432. {
  433. return true;
  434. }
  435. /**
  436. * Converts the instance data to a readable string.
  437. */
  438. public String makeString()
  439. {
  440. return "HellRandomLevelSource";
  441. }
  442. /**
  443. * Returns a list of creatures of the specified type that can spawn at the given location.
  444. */
  445. public List getPossibleCreatures(EnumCreatureType par1EnumCreatureType, int par2, int par3, int par4)
  446. {
  447. if (par1EnumCreatureType == EnumCreatureType.monster && genNetherBridge.func_40483_a(par2, par3, par4))
  448. {
  449. return genNetherBridge.getSpawnList();
  450. }
  451. BiomeGenBase biomegenbase = worldObj.func_48454_a(par2, par4);
  452. if (biomegenbase == null)
  453. {
  454. return null;
  455. }
  456. else
  457. {
  458. return biomegenbase.getSpawnableList(par1EnumCreatureType);
  459. }
  460. }
  461. /**
  462. * Returns the location of the closest structure of the specified type. If not found returns null.
  463. */
  464. public ChunkPosition findClosestStructure(World par1World, String par2Str, int par3, int i, int j)
  465. {
  466. return null;
  467. }
  468. }