Advertisement
Guest User

brendan

a guest
Nov 21st, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.48 KB | None | 0 0
  1. package net.essence.dimension.frozen;
  2.  
  3. import java.util.List;
  4. import java.util.Random;
  5.  
  6. import net.essence.EssenceBlocks;
  7. import net.essence.dimension.boil.gen.MapGenBoilingCaves;
  8. import net.minecraft.block.Block;
  9. import net.minecraft.block.material.Material;
  10. import net.minecraft.entity.EnumCreatureType;
  11. import net.minecraft.init.Blocks;
  12. import net.minecraft.util.IProgressUpdate;
  13. import net.minecraft.util.MathHelper;
  14. import net.minecraft.world.ChunkPosition;
  15. import net.minecraft.world.World;
  16. import net.minecraft.world.WorldType;
  17. import net.minecraft.world.biome.BiomeGenBase;
  18. import net.minecraft.world.chunk.Chunk;
  19. import net.minecraft.world.chunk.IChunkProvider;
  20. import net.minecraft.world.gen.MapGenBase;
  21. import net.minecraft.world.gen.NoiseGenerator;
  22. import net.minecraft.world.gen.NoiseGeneratorOctaves;
  23. import net.minecraft.world.gen.NoiseGeneratorPerlin;
  24. import net.minecraftforge.event.terraingen.TerrainGen;
  25.  
  26. public class ChunkProviderFrozenLands implements IChunkProvider {
  27.  
  28. private Block grass = EssenceBlocks.eucaGrass, dirt = EssenceBlocks.eucaDirt;
  29.  
  30. private Random rand;
  31. private NoiseGeneratorOctaves noiseGen1, noiseGen2, noiseGen3, noiseGen5, noiseGen6;
  32. private NoiseGeneratorPerlin noiseGen4;
  33. private World worldObj;
  34. private WorldType type;
  35. private final double[] da;
  36. private final float[] parabolicField;
  37. private double[] stoneNoise = new double[256];
  38. private MapGenBase caveGenerator = new MapGenBoilingCaves();
  39. private BiomeGenBase[] biomesForGeneration;
  40. private double[] gen1, gen2, gen3, gen4;
  41. private int[][] ia = new int[32][32];
  42. private boolean canSpawn = true;
  43.  
  44. public ChunkProviderFrozenLands(World par1World, long par2) {
  45. this.worldObj = par1World;
  46. this.type = par1World.getWorldInfo().getTerrainType();
  47. this.rand = new Random(par2);
  48.  
  49. this.noiseGen1 = new NoiseGeneratorOctaves(this.rand, 16);
  50. this.noiseGen2 = new NoiseGeneratorOctaves(this.rand, 16);
  51. this.noiseGen3 = new NoiseGeneratorOctaves(this.rand, 8);
  52. this.noiseGen4 = new NoiseGeneratorPerlin(this.rand, 4);
  53. this.noiseGen5 = new NoiseGeneratorOctaves(this.rand, 10);
  54. this.noiseGen6 = new NoiseGeneratorOctaves(this.rand, 16);
  55. this.da = new double[825];
  56. this.parabolicField = new float[25];
  57. for(int j = -2; j <= 2; ++j) {
  58. for(int k = -2; k <= 2; ++k) {
  59. float f = 10.0F / MathHelper.sqrt_float((float)(j * j + k * k) + 0.2F);
  60. this.parabolicField[j + 2 + (k + 2) * 5] = f;
  61. }
  62. }
  63.  
  64. NoiseGenerator[] noiseGens = {noiseGen1, noiseGen2, noiseGen3, noiseGen4, noiseGen5, noiseGen6};
  65. noiseGens = TerrainGen.getModdedNoiseGenerators(par1World, this.rand, noiseGens);
  66. this.noiseGen1 = (NoiseGeneratorOctaves)noiseGens[0];
  67. this.noiseGen2 = (NoiseGeneratorOctaves)noiseGens[1];
  68. this.noiseGen3 = (NoiseGeneratorOctaves)noiseGens[2];
  69. this.noiseGen4 = (NoiseGeneratorPerlin)noiseGens[3];
  70. this.noiseGen5 = (NoiseGeneratorOctaves)noiseGens[4];
  71. this.noiseGen6 = (NoiseGeneratorOctaves)noiseGens[5];
  72. }
  73.  
  74. public void generate(int i, int j, Block[] b) {
  75. byte b0 = 4;
  76. this.biomesForGeneration = this.worldObj.getWorldChunkManager().getBiomesForGeneration(this.biomesForGeneration, i * 4 - 2, j * 4 - 2, 10, 10);
  77. this.generate(i * 4, 0, j * 4);
  78.  
  79. for(int k = 0; k < 4; ++k) {
  80. int l = k * 5;
  81. int i1 = (k + 1) * 5;
  82.  
  83. for(int j1 = 0; j1 < 4; ++j1) {
  84. int k1 = (l + j1) * 33;
  85. int l1 = (l + j1 + 1) * 33;
  86. int i2 = (i1 + j1) * 33;
  87. int j2 = (i1 + j1 + 1) * 33;
  88.  
  89. for(int k2 = 0; k2 < 32; ++k2) {
  90. double d0 = 0.125D;
  91. double d1 = this.da[k1 + k2];
  92. double d2 = this.da[l1 + k2];
  93. double d3 = this.da[i2 + k2];
  94. double d4 = this.da[j2 + k2];
  95. double d5 = (this.da[k1 + k2 + 1] - d1) * d0;
  96. double d6 = (this.da[l1 + k2 + 1] - d2) * d0;
  97. double d7 = (this.da[i2 + k2 + 1] - d3) * d0;
  98. double d8 = (this.da[j2 + k2 + 1] - d4) * d0;
  99.  
  100. for(int l2 = 0; l2 < 8; ++l2) {
  101. double d9 = 0.25D;
  102. double d10 = d1;
  103. double d11 = d2;
  104. double d12 = (d3 - d1) * d9;
  105. double d13 = (d4 - d2) * d9;
  106.  
  107. for(int i3 = 0; i3 < 4; ++i3) {
  108. int j3 = i3 + k * 4 << 12 | 0 + j1 * 4 << 8 | k2 * 8 + l2;
  109. short short1 = 256;
  110. j3 -= short1;
  111. double d14 = 0.25D;
  112. double d16 = (d11 - d10) * d14;
  113. double d15 = d10 - d16;
  114.  
  115. for(int k3 = 0; k3 < 4; ++k3) {
  116. if((d15 += d16) > 0.0D) b[j3 += short1] = dirt;
  117. else if(k2 * 8 + l2 < 20) b[j3 += short1] = grass;
  118. else if(k2 * 8 + l2 < b0) b[j3 += short1] = grass;
  119. else b[j3 += short1] = null;
  120. }
  121. d10 += d12;
  122. d11 += d13;
  123. }
  124. d1 += d5;
  125. d2 += d6;
  126. d3 += d7;
  127. d4 += d8;
  128. }
  129. }
  130. }
  131. }
  132. }
  133.  
  134. public void replaceBlocksForBiome(int i, int j, Block[] ba, byte[] by, BiomeGenBase[] b) {
  135. double d0 = 0.03125D;
  136. this.stoneNoise = this.noiseGen4.func_151599_a(this.stoneNoise, (double)(i * 16), (double)(j * 16), 16, 16, d0 * 2.0D, d0 * 2.0D, 1.0D);
  137.  
  138. for(int k = 0; k < 16; ++k) {
  139. for(int l = 0; l < 16; ++l) {
  140. BiomeGenBase biomegenbase = b[l + k * 16];
  141. genBiomeTerrain(this.worldObj, this.rand, ba, by, i * 16 + k, j * 16 + l, this.stoneNoise[l + k * 16], biomegenbase);
  142. }
  143. }
  144. }
  145.  
  146. public final void genBiomeTerrain(World w, Random rand, Block[] blocks, byte[] bytes, int i, int j, double d, BiomeGenBase b) {
  147. boolean flag = true;
  148. Block block = b.topBlock;
  149. byte b0 = (byte)(b.field_150604_aj & 255);
  150. Block block1 = b.fillerBlock;
  151. int k = -1;
  152. int l = (int)(d / 3.0D + 3.0D + rand.nextDouble() * 0.25D);
  153. int i1 = i & 15;
  154. int j1 = j & 15;
  155. int k1 = blocks.length / 256;
  156.  
  157. for(int l1 = 255; l1 >= 0; --l1) {
  158. int i2 = (j1 * 16 + i1) * k1 + l1;
  159. if(l1 <= 0 + rand.nextInt(5)) {
  160. blocks[i2] = Blocks.bedrock;
  161. } else {
  162. Block block2 = blocks[i2];
  163. if(block2 != null && block2.getMaterial() != Material.air) {
  164. if(block2 == dirt) {
  165. if(k == -1) {
  166. if(l <= 0) {
  167. block = null;
  168. b0 = 0;
  169. block1 = dirt;
  170. }
  171. else if(l1 >= 59 && l1 <= 64) {
  172. block = b.topBlock;
  173. b0 = (byte)(b.field_150604_aj & 255);
  174. block1 = b.fillerBlock;
  175. }
  176.  
  177. if(l1 < 4 && (block == null || block.getMaterial() == Material.air)) {
  178. if(b.getFloatTemperature(i, l1, j) < 0.15F) {
  179. block = Blocks.ice;
  180. b0 = 0;
  181. } else {
  182. block = dirt;
  183. b0 = 0;
  184. }
  185. }
  186. k = l;
  187. if(l1 >= 20) {
  188. blocks[i2] = block;
  189. bytes[i2] = b0;
  190. }
  191. else if(l1 < 56 - l) {
  192. block = null;
  193. block1 = dirt;
  194. blocks[i2] = dirt;
  195. } else {
  196. blocks[i2] = block1;
  197. }
  198. }
  199. else if(k > 0) {
  200. --k;
  201. blocks[i2] = block1;
  202. if(k == 0 && block1 == dirt){
  203. k = rand.nextInt(4) + Math.max(0, l1 - 4);
  204. block1 = dirt;
  205. }
  206. }
  207. }
  208. } else {
  209. k = -1;
  210. }
  211. }
  212. }
  213. }
  214.  
  215. @Override
  216. public Chunk loadChunk(int par1, int par2) {
  217. return this.provideChunk(par1, par2);
  218. }
  219.  
  220. @Override
  221. public Chunk provideChunk(int par1, int par2) {
  222. this.rand.setSeed((long)par1 * 341873128712L + (long)par2 * 132897987541L);
  223. Block[] ablock = new Block[65536];
  224. byte[] abyte = new byte[65536];
  225. this.generate(par1, par2, ablock);
  226. this.biomesForGeneration = this.worldObj.getWorldChunkManager().loadBlockGeneratorData(this.biomesForGeneration, par1 * 16, par2 * 16, 16, 16);
  227. this.replaceBlocksForBiome(par1, par2, ablock, abyte, this.biomesForGeneration);
  228. this.caveGenerator.func_151539_a(this, this.worldObj, par1, par2, ablock);
  229. Chunk chunk = new Chunk(this.worldObj, ablock, abyte, par1, par2);
  230. byte[] abyte1 = chunk.getBiomeArray();
  231. for(int k = 0; k < abyte1.length; ++k) abyte1[k] = (byte)this.biomesForGeneration[k].biomeID;
  232. chunk.generateSkylightMap();
  233. return chunk;
  234. }
  235.  
  236. private void generate(int x, int y, int z) {
  237. this.gen4 = this.noiseGen6.generateNoiseOctaves(this.gen4, x, z, 5, 5, 200.0D, 200.0D, 0.5D);
  238. this.gen1 = this.noiseGen3.generateNoiseOctaves(this.gen1, x, y, z, 5, 33, 5, 8.555150000000001D, 4.277575000000001D, 8.555150000000001D);
  239. this.gen2 = this.noiseGen1.generateNoiseOctaves(this.gen2, x, y, z, 5, 33, 5, 684.412D, 684.412D, 684.412D);
  240. this.gen3 = this.noiseGen2.generateNoiseOctaves(this.gen3, x, y, z, 5, 33, 5, 684.412D, 684.412D, 684.412D);
  241. boolean flag1 = false;
  242. boolean flag = false;
  243. int l = 0;
  244. int i1 = 0;
  245. double d4 = 8.5D;
  246. for(int j1 = 0; j1 < 5; ++j1) {
  247. for(int k1 = 0; k1 < 5; ++k1) {
  248. float f = 0.0F;
  249. float f1 = 0.0F;
  250. float f2 = 0.0F;
  251. byte b0 = 2;
  252. BiomeGenBase biomegenbase = this.biomesForGeneration[j1 + 2 + (k1 + 2) * 10];
  253.  
  254. for(int l1 = -b0; l1 <= b0; ++l1) {
  255. for(int i2 = -b0; i2 <= b0; ++i2) {
  256. BiomeGenBase biomegenbase1 = this.biomesForGeneration[j1 + l1 + 2 + (k1 + i2 + 2) * 10];
  257. float f3 = biomegenbase1.rootHeight;
  258. float f4 = biomegenbase1.heightVariation;
  259.  
  260. f3 = 0.0F;
  261. f4 = -1.0F;
  262.  
  263. float f5 = this.parabolicField[l1 + 2 + (i2 + 2) * 5] / (f3 + 2.0F);
  264. if(biomegenbase1.rootHeight > biomegenbase.rootHeight)
  265. f5 /= 2.0F;
  266. f += f4 * f5;
  267. f1 += f3 * f5;
  268. f2 += f5;
  269. }
  270. }
  271.  
  272. f /= f2;
  273. f1 /= f2;
  274. f = f * 0.9F + 0.1F;
  275. f1 = (f1 * 4.0F - 1.0F) / 8.0F;
  276. double d12 = this.gen4[i1] / 8000.0D;
  277.  
  278. if(d12 < 0.0D) {
  279. d12 = -d12 * 0.3D;
  280. }
  281.  
  282. d12 = d12 * 3.0D - 2.0D;
  283.  
  284. if(d12 < 0.0D) {
  285. d12 /= 2.0D;
  286.  
  287. if(d12 < -1.0D)
  288. d12 = -1.0D;
  289.  
  290. d12 /= 1.4D;
  291. d12 /= 2.0D;
  292. } else {
  293. if(d12 > 1.0D)
  294. d12 = 1.0D;
  295.  
  296. d12 /= 8.0D;
  297. }
  298.  
  299. ++i1;
  300. double d13 = (double)f1;
  301. double d14 = (double)f;
  302. d13 += d12 * 0.2D;
  303. d13 = d13 * 8.5D / 8.0D;
  304. double d5 = 8.5D + d13 * 4.0D;
  305.  
  306. for(int j2 = 0; j2 < 33; ++j2) {
  307. double d6 = ((double)j2 - d5) * 12.0D * 128.0D / 256.0D / d14;
  308.  
  309. if(d6 < 0.0D)
  310. d6 *= 4.0D;
  311.  
  312.  
  313. double d7 = this.gen2[l] / 512.0D;
  314. double d8 = this.gen3[l] / 512.0D;
  315. double d9 = (this.gen1[l] / 10.0D + 1.0D) / 2.0D;
  316. double d10 = MathHelper.denormalizeClamp(d7, d8, d9) - d6;
  317.  
  318. if(j2 > 29) {
  319. double d11 = (double)((float)(j2 - 29) / 3.0F);
  320. d10 = d10 * (1.0D - d11) + -10.0D * d11;
  321. }
  322.  
  323. this.da[l] = d10;
  324. ++l;
  325. }
  326. }
  327. }
  328. }
  329.  
  330. @Override
  331. public boolean chunkExists(int par1, int par2) {
  332. return true;
  333. }
  334.  
  335. @Override
  336. public void populate(IChunkProvider par1IChunkProvider, int chunkX, int chunkZ) {
  337. int x1 = chunkX * 16;
  338. int z1 = chunkZ * 16;
  339. int x, y, z, times;
  340. x = x1 + this.rand.nextInt(16) + 8;
  341. z = z1 + this.rand.nextInt(16) + 8;
  342.  
  343. }
  344.  
  345. @Override
  346. public boolean saveChunks(boolean par1, IProgressUpdate par2IProgressUpdate) {
  347. return true;
  348. }
  349.  
  350. @Override
  351. public void saveExtraData() { }
  352.  
  353. @Override
  354. public boolean unloadQueuedChunks() {
  355. return false;
  356. }
  357.  
  358. @Override
  359. public boolean canSave() {
  360. return true;
  361. }
  362.  
  363. @Override
  364. public String makeString() {
  365. return "Frozen Lands";
  366. }
  367.  
  368. @Override
  369. public List getPossibleCreatures(EnumCreatureType c, int x, int y, int z) {
  370. BiomeGenBase biomegenbase = this.worldObj.getBiomeGenForCoords(x, z);
  371. return biomegenbase.getSpawnableList(c);
  372. }
  373.  
  374. @Override
  375. public ChunkPosition func_147416_a(World w, String s, int x, int y, int z) {
  376. return null;
  377. }
  378.  
  379. @Override
  380. public int getLoadedChunkCount() {
  381. return 0;
  382. }
  383.  
  384. @Override
  385. public void recreateStructures(int par1, int par2) {
  386. }
  387. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement