MrDood_Modding

Untitled

Mar 12th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.76 KB | None | 0 0
  1. package minestrapteam.caveapi.world.gen;
  2.  
  3. import java.util.Random;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.init.Blocks;
  7. import net.minecraft.util.MathHelper;
  8. import net.minecraft.world.World;
  9. import net.minecraft.world.biome.BiomeGenBase;
  10.  
  11. public class CGenCaves extends CMapGenBase
  12. {
  13. @Override
  14. protected void generate(World world, int x, int z, int xSeed, int ySeed, Block[] blocks, byte[] metadata)
  15. {
  16. int i1 = this.rand.nextInt(this.rand.nextInt(this.rand.nextInt(15) + 1) + 1);
  17.  
  18. if (this.rand.nextInt(7) != 0)
  19. {
  20. i1 = 0;
  21. }
  22.  
  23. for (int j1 = 0; j1 < i1; ++j1)
  24. {
  25. double d0 = x * 16 + this.rand.nextInt(16);
  26. double d1 = this.rand.nextInt(this.rand.nextInt(120) + 8);
  27. double d2 = z * 16 + this.rand.nextInt(16);
  28. int k1 = 1;
  29.  
  30. if (this.rand.nextInt(4) == 0)
  31. {
  32. this.generate(this.rand.nextLong(), xSeed, ySeed, blocks, d0, d1, d2);
  33. k1 += this.rand.nextInt(4);
  34. }
  35.  
  36. for (int l1 = 0; l1 < k1; ++l1)
  37. {
  38. float f = this.rand.nextFloat() * 3.141593F * 2.0F;
  39. float f1 = (this.rand.nextFloat() - 0.5F) * 0.25F;
  40. float f2 = this.rand.nextFloat() * 2.0F + this.rand.nextFloat();
  41.  
  42. if (this.rand.nextInt(10) == 0)
  43. {
  44. f2 *= (this.rand.nextFloat() * this.rand.nextFloat() * 3.0F + 1.0F);
  45. }
  46.  
  47. this.generate(this.rand.nextLong(), xSeed, ySeed, blocks, d0, d1, d2, f2, f, f1, 0, 0, 1.0D);
  48. }
  49. }
  50. }
  51.  
  52. protected void generate(long seed, int x, int z, Block[] blocks, double dx, double dy, double dz)
  53. {
  54. generate(seed, x, z, blocks, dx, dy, dz, 1.0F + this.rand.nextFloat() * 6.0F, 0.0F, 0.0F, -1, -1, 0.5D);
  55. }
  56.  
  57. protected void generate(long seed, int x, int z, Block[] blocks, double dx, double dy, double dz, float f1, float f2, float f3, int r1, int r2, double d)
  58. {
  59. double d4 = x * 16 + 8;
  60. double d5 = z * 16 + 8;
  61. float f4 = 0.0F;
  62. float f5 = 0.0F;
  63. Random random = new Random(seed);
  64.  
  65. if (r2 <= 0)
  66. {
  67. int j1 = this.range * 16 - 16;
  68. r2 = j1 - random.nextInt(j1 / 4);
  69. }
  70.  
  71. boolean flag2 = false;
  72.  
  73. if (r1 == -1)
  74. {
  75. r1 = r2 / 2;
  76. flag2 = true;
  77. }
  78.  
  79. int k1 = random.nextInt(r2 / 2) + r2 / 4;
  80.  
  81. for (boolean flag = random.nextInt(6) == 0; r1 < r2; ++r1)
  82. {
  83. double d6 = 1.5D + MathHelper.sin(r1 * 3.141593F / r2) * f1 * 1.0F;
  84. double d7 = d6 * d;
  85. float f6 = MathHelper.cos(f3);
  86. float f7 = MathHelper.sin(f3);
  87. dx += MathHelper.cos(f2) * f6;
  88. dy += f7;
  89. dz += MathHelper.sin(f2) * f6;
  90.  
  91. if (flag)
  92. {
  93. f3 *= 0.92F;
  94. }
  95. else
  96. {
  97. f3 *= 0.7F;
  98. }
  99.  
  100. f3 += f5 * 0.1F;
  101. f2 += f4 * 0.1F;
  102. f5 *= 0.9F;
  103. f4 *= 0.75F;
  104. f5 += (random.nextFloat() - random.nextFloat()) * random.nextFloat() * 2.0F;
  105. f4 += (random.nextFloat() - random.nextFloat()) * random.nextFloat() * 4.0F;
  106.  
  107. if (!flag2 && (r1 == k1) && (f1 > 1.0F) && (r2 > 0))
  108. {
  109. generate(random.nextLong(), x, z, blocks, dx, dy, dz, random.nextFloat() * 0.5F + 0.5F, f2 - 1.570796F, f3 / 3.0F, r1, r2, 1.0D);
  110. generate(random.nextLong(), x, z, blocks, dx, dy, dz, random.nextFloat() * 0.5F + 0.5F, f2 + 1.570796F, f3 / 3.0F, r1, r2, 1.0D);
  111. return;
  112. }
  113.  
  114. if (!flag2 && (random.nextInt(4) == 0))
  115. continue;
  116. double d8 = dx - d4;
  117. double d9 = dz - d5;
  118. double d10 = r2 - r1;
  119. double d11 = f1 + 2.0F + 16.0F;
  120.  
  121. if (d8 * d8 + d9 * d9 - (d10 * d10) > d11 * d11)
  122. {
  123. return;
  124. }
  125.  
  126. if ((dx < d4 - 16.0D - (d6 * 2.0D)) || (dz < d5 - 16.0D - (d6 * 2.0D)) || (dx > d4 + 16.0D + d6 * 2.0D) || (dz > d5 + 16.0D + d6 * 2.0D))
  127. continue;
  128. int i4 = MathHelper.floor_double(dx - d6) - (x * 16) - 1;
  129. int l1 = MathHelper.floor_double(dx + d6) - (x * 16) + 1;
  130. int j4 = MathHelper.floor_double(dy - d7) - 1;
  131. int i5 = MathHelper.floor_double(dy + d7) + 1;
  132. int k4 = MathHelper.floor_double(dz - d6) - (z * 16) - 1;
  133. int j2 = MathHelper.floor_double(dz + d6) - (z * 16) + 1;
  134.  
  135. if (i4 < 0)
  136. {
  137. i4 = 0;
  138. }
  139.  
  140. if (l1 > 16)
  141. {
  142. l1 = 16;
  143. }
  144.  
  145. if (j4 < 1)
  146. {
  147. j4 = 1;
  148. }
  149.  
  150. if (i5 > 248)
  151. {
  152. i5 = 248;
  153. }
  154.  
  155. if (k4 < 0)
  156. {
  157. k4 = 0;
  158. }
  159.  
  160. if (j2 > 16)
  161. {
  162. j2 = 16;
  163. }
  164.  
  165. boolean flag3 = false;
  166.  
  167. for (int k2 = i4; !flag3 && k2 < l1; ++k2)
  168. {
  169. for (int l2 = k4; !flag3 && l2 < j2; ++l2)
  170. {
  171. for (int i3 = i5 + 1; !flag3 && i3 >= j4 - 1; --i3)
  172. {
  173. int j3 = (k2 * 16 + l2) * 256 + i3;
  174.  
  175. if (i3 >= 0 && i3 < 256)
  176. {
  177. if (this.isOceanBlock(blocks, j3, k2, i3, l2, x, z))
  178. {
  179. flag3 = true;
  180. }
  181. if (i3 == j4 - 1 || k2 == i4 || k2 == l1 - 1 || l2 == k4 || l2 == j2 - 1)
  182. continue;
  183. i3 = j4;
  184. }
  185. }
  186. }
  187. }
  188.  
  189. if (!flag3)
  190. {
  191. for (int k2 = i4; k2 < l1; ++k2)
  192. {
  193. double d13 = (k2 + x * 16 + 0.5D - dx) / d6;
  194.  
  195. for (int j3 = k4; j3 < j2; ++j3)
  196. {
  197. double d14 = (j3 + z * 16 + 0.5D - dz) / d6;
  198. int k3 = (k2 * 16 + j3) * 256 + i5;
  199. boolean flag1 = false;
  200.  
  201. if (d13 * d13 + d14 * d14 < 1.0D)
  202. {
  203. for (int l3 = i5 - 1; l3 >= j4; --l3)
  204. {
  205. double d12 = (l3 + 0.5D - dy) / d7;
  206.  
  207. if ((d12 > -0.7D) && (d13 * d13 + d12 * d12 + d14 * d14 < 1.0D))
  208. {
  209. if (isTopBlock(blocks, k3, k2, l3, j3, x, z))
  210. {
  211. flag1 = true;
  212. }
  213. digBlock(blocks, k3, k2, l3, j3, x, z, flag1);
  214. }
  215.  
  216. --k3;
  217. }
  218. }
  219. }
  220. }
  221.  
  222. if (flag2)
  223. return;
  224. }
  225. }
  226. }
  227.  
  228. protected boolean isOceanBlock(Block[] data, int index, int x, int y, int z, int chunkX, int chunkZ)
  229. {
  230. return ((data[index] == Blocks.flowing_water) || (data[index] == Blocks.water));
  231. }
  232.  
  233. private static boolean isExceptionBiome(BiomeGenBase biome)
  234. {
  235. if (biome == BiomeGenBase.mushroomIsland)
  236. return true;
  237. if (biome == BiomeGenBase.beach)
  238. return true;
  239. return (biome == BiomeGenBase.desert);
  240. }
  241.  
  242. private boolean isTopBlock(Block[] data, int index, int x, int y, int z, int chunkX, int chunkZ)
  243. {
  244. return (data[index] == Blocks.grass);
  245. }
  246.  
  247. protected void digBlock(Block[] data, int index, int x, int y, int z, int chunkX, int chunkZ, boolean foundTop)
  248. {
  249. BiomeGenBase biome = this.worldObj.getBiomeGenForCoords(x + chunkX * 16, z + chunkZ * 16);
  250. Block top = isExceptionBiome(biome) ? Blocks.grass : biome.topBlock;
  251. Block filler = isExceptionBiome(biome) ? Blocks.dirt : biome.fillerBlock;
  252. Block block = data[index];
  253.  
  254. if (block == Blocks.stone || block == filler || block == top)
  255. {
  256. if (y < 10)
  257. {
  258. data[index] = Blocks.lava;
  259. }
  260. else
  261. {
  262. data[index] = null;
  263.  
  264. if (foundTop && data[index - 1] == filler)
  265. {
  266. data[index - 1] = top;
  267. }
  268. }
  269. }
  270. }
  271. }
Advertisement
Add Comment
Please, Sign In to add comment