PageRenderTime 28ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/minecraft/net/minecraft/src/ChunkProviderEnd.java

https://bitbucket.org/Cocanuta/cookie
Java | 407 lines | 314 code | 60 blank | 33 comment | 41 complexity | 26a6a1d925d05346adab520df4de1721 MD5 | raw file
  1. package net.minecraft.src;
  2. import java.util.List;
  3. import java.util.Random;
  4. public class ChunkProviderEnd implements IChunkProvider
  5. {
  6. private Random endRNG;
  7. private NoiseGeneratorOctaves noiseGen1;
  8. private NoiseGeneratorOctaves noiseGen2;
  9. private NoiseGeneratorOctaves noiseGen3;
  10. public NoiseGeneratorOctaves noiseGen4;
  11. public NoiseGeneratorOctaves noiseGen5;
  12. private World endWorld;
  13. private double densities[];
  14. private BiomeGenBase biomesForGeneration[];
  15. double noiseData1[];
  16. double noiseData2[];
  17. double noiseData3[];
  18. double noiseData4[];
  19. double noiseData5[];
  20. int field_40395_h[][];
  21. public ChunkProviderEnd(World par1World, long par2)
  22. {
  23. field_40395_h = new int[32][32];
  24. endWorld = par1World;
  25. endRNG = new Random(par2);
  26. noiseGen1 = new NoiseGeneratorOctaves(endRNG, 16);
  27. noiseGen2 = new NoiseGeneratorOctaves(endRNG, 16);
  28. noiseGen3 = new NoiseGeneratorOctaves(endRNG, 8);
  29. noiseGen4 = new NoiseGeneratorOctaves(endRNG, 10);
  30. noiseGen5 = new NoiseGeneratorOctaves(endRNG, 16);
  31. }
  32. public void func_40380_a(int par1, int par2, byte par3ArrayOfByte[], BiomeGenBase par4ArrayOfBiomeGenBase[])
  33. {
  34. byte byte0 = 2;
  35. int i = byte0 + 1;
  36. byte byte1 = 33;
  37. int j = byte0 + 1;
  38. densities = func_40379_a(densities, par1 * byte0, 0, par2 * byte0, i, byte1, j);
  39. for (int k = 0; k < byte0; k++)
  40. {
  41. for (int l = 0; l < byte0; l++)
  42. {
  43. for (int i1 = 0; i1 < 32; i1++)
  44. {
  45. double d = 0.25D;
  46. double d1 = densities[((k + 0) * j + (l + 0)) * byte1 + (i1 + 0)];
  47. double d2 = densities[((k + 0) * j + (l + 1)) * byte1 + (i1 + 0)];
  48. double d3 = densities[((k + 1) * j + (l + 0)) * byte1 + (i1 + 0)];
  49. double d4 = densities[((k + 1) * j + (l + 1)) * byte1 + (i1 + 0)];
  50. double d5 = (densities[((k + 0) * j + (l + 0)) * byte1 + (i1 + 1)] - d1) * d;
  51. double d6 = (densities[((k + 0) * j + (l + 1)) * byte1 + (i1 + 1)] - d2) * d;
  52. double d7 = (densities[((k + 1) * j + (l + 0)) * byte1 + (i1 + 1)] - d3) * d;
  53. double d8 = (densities[((k + 1) * j + (l + 1)) * byte1 + (i1 + 1)] - d4) * d;
  54. for (int j1 = 0; j1 < 4; j1++)
  55. {
  56. double d9 = 0.125D;
  57. double d10 = d1;
  58. double d11 = d2;
  59. double d12 = (d3 - d1) * d9;
  60. double d13 = (d4 - d2) * d9;
  61. for (int k1 = 0; k1 < 8; k1++)
  62. {
  63. int l1 = k1 + k * 8 << 11 | 0 + l * 8 << 7 | i1 * 4 + j1;
  64. char c = '\200';
  65. double d14 = 0.125D;
  66. double d15 = d10;
  67. double d16 = (d11 - d10) * d14;
  68. for (int i2 = 0; i2 < 8; i2++)
  69. {
  70. int j2 = 0;
  71. if (d15 > 0.0D)
  72. {
  73. j2 = Block.whiteStone.blockID;
  74. }
  75. par3ArrayOfByte[l1] = (byte)j2;
  76. l1 += c;
  77. d15 += d16;
  78. }
  79. d10 += d12;
  80. d11 += d13;
  81. }
  82. d1 += d5;
  83. d2 += d6;
  84. d3 += d7;
  85. d4 += d8;
  86. }
  87. }
  88. }
  89. }
  90. }
  91. public void func_40381_b(int par1, int par2, byte par3ArrayOfByte[], BiomeGenBase par4ArrayOfBiomeGenBase[])
  92. {
  93. for (int i = 0; i < 16; i++)
  94. {
  95. for (int j = 0; j < 16; j++)
  96. {
  97. int k = 1;
  98. int l = -1;
  99. byte byte0 = (byte)Block.whiteStone.blockID;
  100. byte byte1 = (byte)Block.whiteStone.blockID;
  101. for (int i1 = 127; i1 >= 0; i1--)
  102. {
  103. int j1 = (j * 16 + i) * 128 + i1;
  104. byte byte2 = par3ArrayOfByte[j1];
  105. if (byte2 == 0)
  106. {
  107. l = -1;
  108. continue;
  109. }
  110. if (byte2 != Block.stone.blockID)
  111. {
  112. continue;
  113. }
  114. if (l == -1)
  115. {
  116. if (k <= 0)
  117. {
  118. byte0 = 0;
  119. byte1 = (byte)Block.whiteStone.blockID;
  120. }
  121. l = k;
  122. if (i1 >= 0)
  123. {
  124. par3ArrayOfByte[j1] = byte0;
  125. }
  126. else
  127. {
  128. par3ArrayOfByte[j1] = byte1;
  129. }
  130. continue;
  131. }
  132. if (l > 0)
  133. {
  134. l--;
  135. par3ArrayOfByte[j1] = byte1;
  136. }
  137. }
  138. }
  139. }
  140. }
  141. /**
  142. * loads or generates the chunk at the chunk location specified
  143. */
  144. public Chunk loadChunk(int par1, int par2)
  145. {
  146. return provideChunk(par1, par2);
  147. }
  148. /**
  149. * Will return back a chunk, if it doesn't exist and its not a MP client it will generates all the blocks for the
  150. * specified chunk from the map seed and chunk seed
  151. */
  152. public Chunk provideChunk(int par1, int par2)
  153. {
  154. endRNG.setSeed((long)par1 * 0x4f9939f508L + (long)par2 * 0x1ef1565bd5L);
  155. byte abyte0[] = new byte[32768];
  156. biomesForGeneration = endWorld.getWorldChunkManager().loadBlockGeneratorData(biomesForGeneration, par1 * 16, par2 * 16, 16, 16);
  157. func_40380_a(par1, par2, abyte0, biomesForGeneration);
  158. func_40381_b(par1, par2, abyte0, biomesForGeneration);
  159. Chunk chunk = new Chunk(endWorld, abyte0, par1, par2);
  160. byte abyte1[] = chunk.getBiomeArray();
  161. for (int i = 0; i < abyte1.length; i++)
  162. {
  163. abyte1[i] = (byte)biomesForGeneration[i].biomeID;
  164. }
  165. chunk.generateSkylightMap();
  166. return chunk;
  167. }
  168. private double[] func_40379_a(double par1ArrayOfDouble[], int par2, int par3, int par4, int par5, int par6, int par7)
  169. {
  170. if (par1ArrayOfDouble == null)
  171. {
  172. par1ArrayOfDouble = new double[par5 * par6 * par7];
  173. }
  174. double d = 684.41200000000003D;
  175. double d1 = 684.41200000000003D;
  176. noiseData4 = noiseGen4.generateNoiseOctaves(noiseData4, par2, par4, par5, par7, 1.121D, 1.121D, 0.5D);
  177. noiseData5 = noiseGen5.generateNoiseOctaves(noiseData5, par2, par4, par5, par7, 200D, 200D, 0.5D);
  178. d *= 2D;
  179. noiseData1 = noiseGen3.generateNoiseOctaves(noiseData1, par2, par3, par4, par5, par6, par7, d / 80D, d1 / 160D, d / 80D);
  180. noiseData2 = noiseGen1.generateNoiseOctaves(noiseData2, par2, par3, par4, par5, par6, par7, d, d1, d);
  181. noiseData3 = noiseGen2.generateNoiseOctaves(noiseData3, par2, par3, par4, par5, par6, par7, d, d1, d);
  182. int i = 0;
  183. int j = 0;
  184. for (int k = 0; k < par5; k++)
  185. {
  186. for (int l = 0; l < par7; l++)
  187. {
  188. double d2 = (noiseData4[j] + 256D) / 512D;
  189. if (d2 > 1.0D)
  190. {
  191. d2 = 1.0D;
  192. }
  193. double d3 = noiseData5[j] / 8000D;
  194. if (d3 < 0.0D)
  195. {
  196. d3 = -d3 * 0.29999999999999999D;
  197. }
  198. d3 = d3 * 3D - 2D;
  199. float f = (float)((k + par2) - 0) / 1.0F;
  200. float f1 = (float)((l + par4) - 0) / 1.0F;
  201. float f2 = 100F - MathHelper.sqrt_float(f * f + f1 * f1) * 8F;
  202. if (f2 > 80F)
  203. {
  204. f2 = 80F;
  205. }
  206. if (f2 < -100F)
  207. {
  208. f2 = -100F;
  209. }
  210. if (d3 > 1.0D)
  211. {
  212. d3 = 1.0D;
  213. }
  214. d3 /= 8D;
  215. d3 = 0.0D;
  216. if (d2 < 0.0D)
  217. {
  218. d2 = 0.0D;
  219. }
  220. d2 += 0.5D;
  221. d3 = (d3 * (double)par6) / 16D;
  222. j++;
  223. double d4 = (double)par6 / 2D;
  224. for (int i1 = 0; i1 < par6; i1++)
  225. {
  226. double d5 = 0.0D;
  227. double d6 = (((double)i1 - d4) * 8D) / d2;
  228. if (d6 < 0.0D)
  229. {
  230. d6 *= -1D;
  231. }
  232. double d7 = noiseData2[i] / 512D;
  233. double d8 = noiseData3[i] / 512D;
  234. double d9 = (noiseData1[i] / 10D + 1.0D) / 2D;
  235. if (d9 < 0.0D)
  236. {
  237. d5 = d7;
  238. }
  239. else if (d9 > 1.0D)
  240. {
  241. d5 = d8;
  242. }
  243. else
  244. {
  245. d5 = d7 + (d8 - d7) * d9;
  246. }
  247. d5 -= 8D;
  248. d5 += f2;
  249. int j1 = 2;
  250. if (i1 > par6 / 2 - j1)
  251. {
  252. double d10 = (float)(i1 - (par6 / 2 - j1)) / 64F;
  253. if (d10 < 0.0D)
  254. {
  255. d10 = 0.0D;
  256. }
  257. if (d10 > 1.0D)
  258. {
  259. d10 = 1.0D;
  260. }
  261. d5 = d5 * (1.0D - d10) + -3000D * d10;
  262. }
  263. j1 = 8;
  264. if (i1 < j1)
  265. {
  266. double d11 = (float)(j1 - i1) / ((float)j1 - 1.0F);
  267. d5 = d5 * (1.0D - d11) + -30D * d11;
  268. }
  269. par1ArrayOfDouble[i] = d5;
  270. i++;
  271. }
  272. }
  273. }
  274. return par1ArrayOfDouble;
  275. }
  276. /**
  277. * Checks to see if a chunk exists at x, y
  278. */
  279. public boolean chunkExists(int par1, int par2)
  280. {
  281. return true;
  282. }
  283. /**
  284. * Populates chunk with ores etc etc
  285. */
  286. public void populate(IChunkProvider par1IChunkProvider, int par2, int par3)
  287. {
  288. BlockSand.fallInstantly = true;
  289. int i = par2 * 16;
  290. int j = par3 * 16;
  291. BiomeGenBase biomegenbase = endWorld.getBiomeGenForCoords(i + 16, j + 16);
  292. biomegenbase.decorate(endWorld, endWorld.rand, i, j);
  293. BlockSand.fallInstantly = false;
  294. }
  295. /**
  296. * Two modes of operation: if passed true, save all Chunks in one go. If passed false, save up to two chunks.
  297. * Return true if all chunks have been saved.
  298. */
  299. public boolean saveChunks(boolean par1, IProgressUpdate par2IProgressUpdate)
  300. {
  301. return true;
  302. }
  303. /**
  304. * Unloads the 100 oldest chunks from memory, due to a bug with chunkSet.add() never being called it thinks the list
  305. * is always empty and will not remove any chunks.
  306. */
  307. public boolean unload100OldestChunks()
  308. {
  309. return false;
  310. }
  311. /**
  312. * Returns if the IChunkProvider supports saving.
  313. */
  314. public boolean canSave()
  315. {
  316. return true;
  317. }
  318. /**
  319. * Converts the instance data to a readable string.
  320. */
  321. public String makeString()
  322. {
  323. return "RandomLevelSource";
  324. }
  325. /**
  326. * Returns a list of creatures of the specified type that can spawn at the given location.
  327. */
  328. public List getPossibleCreatures(EnumCreatureType par1EnumCreatureType, int par2, int par3, int par4)
  329. {
  330. BiomeGenBase biomegenbase = endWorld.getBiomeGenForCoords(par2, par4);
  331. if (biomegenbase == null)
  332. {
  333. return null;
  334. }
  335. else
  336. {
  337. return biomegenbase.getSpawnableList(par1EnumCreatureType);
  338. }
  339. }
  340. /**
  341. * Returns the location of the closest structure of the specified type. If not found returns null.
  342. */
  343. public ChunkPosition findClosestStructure(World par1World, String par2Str, int par3, int i, int j)
  344. {
  345. return null;
  346. }
  347. }