Guest User

Untitled

a guest
Oct 20th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.68 KB | None | 0 0
  1. package net.minecraft.src;
  2.  
  3. import java.util.Random;
  4.  
  5. public class ChunkProviderDesert implements IChunkProvider
  6. {
  7.  
  8. public ChunkProviderDesert(World world)
  9. {
  10. worldObj = world;
  11. rand = new Random();
  12. octave2 = new NoiseGeneratorOctaves(rand, 16); //Initialize the noise arrays
  13. octave3 = new NoiseGeneratorOctaves(rand, 8);
  14. octave4 = new NoiseGeneratorOctaves(rand, 10);
  15. octave5 = new NoiseGeneratorOctaves(rand, 16);
  16. }
  17.  
  18.  
  19. public boolean chunkExists(int i, int j) {
  20.  
  21. return true;
  22. }
  23.  
  24.  
  25. public Chunk provideChunk(int i, int j) { //Call all the methods you want to execute from here
  26.  
  27.  
  28. byte abyte0[] = new byte[32768]; //Make the chunk block array
  29. biomesForGeneration = worldObj.getWorldChunkManager().loadBlockGeneratorData(biomesForGeneration, i * 16, j * 16, 16, 16); //Load the biome map
  30. generateTerrain(i, j, abyte0);
  31. generatetop(abyte0);
  32. Chunk chunk = new Chunk(worldObj, abyte0, i, j); //Make the chunk
  33. chunk.func_1024_c(); //No Idea, but leave it
  34. return chunk;
  35. }
  36.  
  37. public void generatetop(byte[] abyte0) //Generate Sand/Grass/Snow
  38. {
  39. for(int k = 0; k < 16; k++)
  40. {
  41. for(int l = 0; l < 16; l++)
  42. {
  43. int j1 = 0;
  44.  
  45. for(int k1 = 127; k1 >= 0; k1--)
  46. {
  47. int l1 = (l * 16 + k) * 128 + k1;
  48. byte byte2 = abyte0[l1];
  49.  
  50. if(byte2 != Block.stone.blockID)
  51. {
  52. j1 = 0;
  53. continue;
  54. }
  55.  
  56.  
  57.  
  58. if(j1 < 3)
  59. {
  60. abyte0[l1] = (byte)Block.sand.blockID;;
  61. }
  62. if( j1 == 3)
  63. {
  64. abyte0[l1] = (byte)Block.sandStone.blockID;;
  65. }
  66. if(k1 == 0)
  67. {
  68. abyte0[l1] = (byte)Block.bedrock.blockID;
  69. }
  70.  
  71.  
  72.  
  73. j1++;
  74. }
  75. }
  76. }
  77. }
  78. public void generateTerrain(int i, int j, byte abyte0[]) //Generates the base terrain
  79. {
  80. byte byte0 = 4; //Determines the size of the noise array/amount of interpolation, leave it at this for efficiency
  81. int k = byte0 + 1; //Used in noise
  82. byte byte2 = 17; //Used In Noise
  83. int l = byte0 + 1; //Used in noise
  84. noise = getNoise(noise, i * byte0, 0, j * byte0, k, byte2, l); //Gets the noise array
  85. for(int i1 = 0; i1 < byte0; i1++) //Loops for interpolation
  86. {
  87. for(int j1 = 0; j1 < byte0; j1++)
  88. {
  89. for(int k1 = 0; k1 < 16; k1++)
  90. {
  91. double d = 0.125D; //Modifiers for density
  92. double d1 = noise[((i1 + 0) * l + (j1 + 0)) * byte2 + (k1 + 0)]; //Gets the correct noise for the spot, don't change
  93. double d2 = noise[((i1 + 0) * l + (j1 + 1)) * byte2 + (k1 + 0)];
  94. double d3 = noise[((i1 + 1) * l + (j1 + 0)) * byte2 + (k1 + 0)];
  95. double d4 = noise[((i1 + 1) * l + (j1 + 1)) * byte2 + (k1 + 0)];
  96. double d5 = (noise[((i1 + 0) * l + (j1 + 0)) * byte2 + (k1 + 1)] - d1) * d;
  97. double d6 = (noise[((i1 + 0) * l + (j1 + 1)) * byte2 + (k1 + 1)] - d2) * d;
  98. double d7 = (noise[((i1 + 1) * l + (j1 + 0)) * byte2 + (k1 + 1)] - d3) * d;
  99. double d8 = (noise[((i1 + 1) * l + (j1 + 1)) * byte2 + (k1 + 1)] - d4) * d;
  100. for(int l1 = 0; l1 < 8; l1++)
  101. {
  102. double d9 = 0.25D; //Modifiers for density
  103. double d10 = d1;
  104. double d11 = d2;
  105. double d12 = (d3 - d1) * d9;
  106. double d13 = (d4 - d2) * d9;
  107. for(int i2 = 0; i2 < 4; i2++)
  108. {
  109. int j2 = i2 + i1 * 4 << 11 | 0 + j1 * 4 << 7 | k1 * 8 + l1; //Gets the correct spot in the chunk
  110. char c = '\200'; //For use in chunk data, keep this
  111. double d14 = 0.25D; //Modifiers for density
  112. double d15 = d10;
  113. double d16 = (d11 - d10) * d14;
  114. for(int k2 = 0; k2 < 4; k2++)
  115. {
  116. int l2 = 0;
  117. if(d15 > 0.0D) //If d15(density) is above 0, it's stone, alse, it's air
  118. {
  119. l2 = Block.stone.blockID;
  120. }
  121. abyte0[j2] = (byte)l2; //Set the chunk data
  122. j2 += c; //Find the next spot in chunk to set, keep this
  123. d15 += d16; //Increments the density by (d1 - d2) * d14
  124. }
  125.  
  126. d10 += d12; //Keep all this
  127. d11 += d13;
  128. }
  129.  
  130. d1 += d5;
  131. d2 += d6;
  132. d3 += d7;
  133. d4 += d8;
  134. }
  135.  
  136. }
  137.  
  138. }
  139.  
  140. }
  141.  
  142. }
  143.  
  144. public Chunk prepareChunk(int i, int j) {
  145. return provideChunk(i, j);
  146. }
  147.  
  148.  
  149. public void populate(IChunkProvider ichunkprovider, int i, int j) { //Where you call other smaller generators
  150. i *= 16;
  151. j *= 16;
  152. for(int i2 = 0; i2 < 15; i2++)
  153. {
  154. int x = i + rand.nextInt(16) + 8;
  155. int y = rand.nextInt(30) + 56;
  156. int z = j + rand.nextInt(16) + 8;
  157. (new WorldGenDeadBush(Block.deadBush.blockID)).generate(worldObj, rand, x, y, z);
  158. }
  159. for(int i3 = 0; i3 < 20; i3++)
  160. {
  161. int x = i + rand.nextInt(16) + 8;
  162. int y = rand.nextInt(30) + 56;
  163. int z = j + rand.nextInt(16) + 8;
  164. (new WorldGenCactus()).generate(worldObj, rand, x, y, z);
  165. }
  166.  
  167. }
  168. private double[] getNoise(double ad[], int i, int j, int k, int l, int i1, int j1) //Generates the noise array used
  169. {
  170. if(ad == null)
  171. {
  172. ad = new double[l * i1 * j1];
  173. }
  174. int HeightModifier = 10;
  175. noise2 = octave2.func_4109_a(noise2, i, k, l, j1, 150D, 150D, 0.5D); //Generates 2D noise Height map
  176. noise3 = octave3.generateNoiseOctaves(noise3, i, j, k, l, i1, j1, 40D, 200D, 20D); //3D noises
  177. noise4 = octave4.generateNoiseOctaves(noise4, i, j, k, l, i1, j1, 60D, 500D, 60D);
  178. noise5 = octave5.generateNoiseOctaves(noise5, i, j, k, l, i1, j1, 86D, 350D, 86D);
  179. int k1 = 0;
  180. int l1 = 0;
  181. for(int j2 = 0; j2 < l; j2++)
  182. {
  183. for(int l2 = 0; l2 < j1; l2++)
  184. {
  185. double d6 = noise2[l1] / 8000D; //Gets the height map
  186. if(d6 < 0.0D) //Makes sure it's not below 0
  187. {
  188. d6 = -d6 * 0.29999999999999999D; //Makes it positive if it is
  189. }
  190. d6 = d6 * 3D - 2D;
  191. if(d6 < 0.0D) //Checks for below 0 again
  192. {
  193. d6 /= 2D;
  194. if(d6 < -1D)
  195. {
  196. d6 = -1D;
  197. }
  198. d6 /= 1.3999999999999999D;
  199. d6 /= 2D;
  200. } else
  201. {
  202. if(d6 > 1.0D) //Checks for above 1
  203. {
  204. d6 = 1.0D;
  205. }
  206. d6 /= 8D;
  207. }
  208. d6 = (d6 * (double)HeightModifier) / 16D;
  209. double d7 = (double)HeightModifier / 2D + d6 * 4D;
  210. l1++;
  211. for(int j3 = 0; j3 < i1; j3++)
  212. {
  213. double d8 = 0.0D;
  214. double d9 = (((double)j3 - d7) * 12D);
  215. if(d9 < 0.0D)
  216. {
  217. d9 *= 4D;
  218. }
  219. double d10 = noise4[k1] / 512D;
  220. double d11 = noise5[k1] / 512D;
  221. double d12 = (noise3[k1] / 10D + 1.0D) / 2D;
  222. if(d12 < 0.0D)
  223. {
  224. d8 = d10;
  225. } else
  226. if(d12 > 1.0D)
  227. {
  228. d8 = d11;
  229. } else
  230. {
  231. d8 = d10 + (d11 - d10) * d12;
  232. }
  233. d8 -= d9;
  234. if(j3 > i1 - 4)
  235. {
  236. double d13 = (float)(j3 - (i1 - 4)) / 3F;
  237. d8 = d8 * (1.0D - d13) + -10D * d13;
  238. }
  239. ad[k1] = d8;
  240. k1++;
  241. }
  242.  
  243. }
  244.  
  245. }
  246.  
  247. return ad;
  248. }
  249. public boolean saveChunks(boolean flag, IProgressUpdate iprogressupdate) {
  250.  
  251. return true;
  252. }
  253.  
  254.  
  255. public boolean unload100OldestChunks() {
  256. return false;
  257. }
  258.  
  259.  
  260. public boolean canSave() {
  261. return true;
  262. }
  263.  
  264.  
  265. public String makeString() {
  266. return "RandomLevelSource";
  267. }
  268. private Random rand;
  269.  
  270. private NoiseGeneratorOctaves octave2;
  271. private NoiseGeneratorOctaves octave3;
  272. public NoiseGeneratorOctaves octave4;
  273. public NoiseGeneratorOctaves octave5;
  274. public NoiseGeneratorOctaves mobSpawnerNoise;
  275. private BiomeGenBase biomesForGeneration[];
  276. private World worldObj;
  277. private double noise[];
  278. double noise2[];
  279. double noise3[];
  280. double noise4[];
  281. double noise5[];
  282. }
Add Comment
Please, Sign In to add comment