Guest User

Untitled

a guest
Nov 29th, 2015
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.77 KB | None | 0 0
  1. package com.halestormxv.worldALT;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Random;
  6.  
  7. import com.halestormxv.worldALT.genlayer.LightForestGenLayer;
  8.  
  9. import net.minecraft.crash.CrashReport;
  10. import net.minecraft.crash.CrashReportCategory;
  11. import net.minecraft.util.ReportedException;
  12. import net.minecraft.world.ChunkPosition;
  13. import net.minecraft.world.World;
  14. import net.minecraft.world.WorldType;
  15. import net.minecraft.world.biome.BiomeCache;
  16. import net.minecraft.world.biome.BiomeGenBase;
  17. import net.minecraft.world.biome.WorldChunkManager;
  18. import net.minecraft.world.gen.layer.GenLayer;
  19. import net.minecraft.world.gen.layer.IntCache;
  20. import cpw.mods.fml.relauncher.Side;
  21. import cpw.mods.fml.relauncher.SideOnly;
  22.  
  23. public class WorldChunkManagerForest extends WorldChunkManager {
  24.  
  25. private GenLayer genBiomes;
  26. /** A GenLayer containing the indices into BiomeGenBase.biomeList[] */
  27. private GenLayer biomeIndexLayer;
  28. /** The BiomeCache object for this world. */
  29. private BiomeCache biomeCache;
  30. /** A list of biomes that the player can spawn in. */
  31. private List<BiomeGenBase> biomesToSpawnIn;
  32.  
  33. @SuppressWarnings({ "unchecked", "rawtypes" })
  34. public WorldChunkManagerForest()
  35. {
  36. this.biomeCache = new BiomeCache(this);
  37. this.biomesToSpawnIn = new ArrayList();
  38. this.biomesToSpawnIn.addAll(allowedBiomes);
  39. }
  40.  
  41. public WorldChunkManagerForest(long seed, WorldType worldType)
  42. {
  43. this();
  44. // i changed this to my GenLayerTutorial
  45. GenLayer[] agenlayer = LightForestGenLayer.makeTheWorld(seed, worldType);
  46. agenlayer = getModdedBiomeGenerators(worldType, seed, agenlayer);
  47. this.genBiomes = agenlayer[0];
  48. this.biomeIndexLayer = agenlayer[1];
  49. }
  50.  
  51. public WorldChunkManagerForest(World world)
  52. {
  53. this(world.getSeed(), world.getWorldInfo().getTerrainType());
  54. }
  55.  
  56. /**
  57. * Gets the list of valid biomes for the player to spawn in.
  58. */
  59. @Override
  60. public List<BiomeGenBase> getBiomesToSpawnIn()
  61. {
  62. return this.biomesToSpawnIn;
  63. }
  64.  
  65. /**
  66. * Returns the BiomeGenBase related to the x, z position on the world.
  67. */
  68. @Override
  69. public BiomeGenBase getBiomeGenAt(int x, int z)
  70. {
  71. return this.biomeCache.getBiomeGenAt(x, z);
  72. }
  73.  
  74. /**
  75. * Returns a list of rainfall values for the specified blocks. Args: listToReuse, x, z, width, length.
  76. */
  77. @Override
  78. public float[] getRainfall(float[] listToReuse, int x, int z, int width, int length)
  79. {
  80. IntCache.resetIntCache();
  81.  
  82. if (listToReuse == null || listToReuse.length < width * length)
  83. {
  84. listToReuse = new float[width * length];
  85. }
  86.  
  87. int[] aint = this.biomeIndexLayer.getInts(x, z, width, length);
  88.  
  89. for (int i1 = 0; i1 < width * length; ++i1)
  90. {
  91. try
  92. {
  93. float f = (float)BiomeGenBase.getBiome(aint[i1]).getIntRainfall() / 65536.0F;
  94.  
  95. if (f > 1.0F)
  96. {
  97. f = 1.0F;
  98. }
  99.  
  100. listToReuse[i1] = f;
  101. }
  102. catch (Throwable throwable)
  103. {
  104. CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Invalid Biome id");
  105. CrashReportCategory crashreportcategory = crashreport.makeCategory("DownfallBlock");
  106. crashreportcategory.addCrashSection("biome id", Integer.valueOf(i1));
  107. crashreportcategory.addCrashSection("downfalls[] size", Integer.valueOf(listToReuse.length));
  108. crashreportcategory.addCrashSection("x", Integer.valueOf(x));
  109. crashreportcategory.addCrashSection("z", Integer.valueOf(z));
  110. crashreportcategory.addCrashSection("w", Integer.valueOf(width));
  111. crashreportcategory.addCrashSection("h", Integer.valueOf(length));
  112. throw new ReportedException(crashreport);
  113. }
  114. }
  115.  
  116. return listToReuse;
  117. }
  118.  
  119. /**
  120. * Return an adjusted version of a given temperature based on the y height
  121. */
  122. @Override
  123. @SideOnly(Side.CLIENT)
  124. public float getTemperatureAtHeight(float par1, int par2)
  125. {
  126. return par1;
  127. }
  128.  
  129. /**
  130. * Returns an array of biomes for the location input.
  131. */
  132. @Override
  133. public BiomeGenBase[] getBiomesForGeneration(BiomeGenBase[] par1ArrayOfBiomeGenBase, int par2, int par3, int par4, int par5)
  134. {
  135. IntCache.resetIntCache();
  136.  
  137. if (par1ArrayOfBiomeGenBase == null || par1ArrayOfBiomeGenBase.length < par4 * par5)
  138. {
  139. par1ArrayOfBiomeGenBase = new BiomeGenBase[par4 * par5];
  140. }
  141.  
  142. int[] aint = this.genBiomes.getInts(par2, par3, par4, par5);
  143.  
  144. try
  145. {
  146. for (int i = 0; i < par4 * par5; ++i)
  147. {
  148. par1ArrayOfBiomeGenBase[i] = BiomeGenBase.getBiome(aint[i]);
  149. }
  150.  
  151. return par1ArrayOfBiomeGenBase;
  152. }
  153. catch (Throwable throwable)
  154. {
  155. CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Invalid Biome id");
  156. CrashReportCategory crashreportcategory = crashreport.makeCategory("RawBiomeBlock");
  157. crashreportcategory.addCrashSection("biomes[] size", Integer.valueOf(par1ArrayOfBiomeGenBase.length));
  158. crashreportcategory.addCrashSection("x", Integer.valueOf(par2));
  159. crashreportcategory.addCrashSection("z", Integer.valueOf(par3));
  160. crashreportcategory.addCrashSection("w", Integer.valueOf(par4));
  161. crashreportcategory.addCrashSection("h", Integer.valueOf(par5));
  162. throw new ReportedException(crashreport);
  163. }
  164. }
  165.  
  166. /**
  167. * Returns biomes to use for the blocks and loads the other data like temperature and humidity onto the
  168. * WorldChunkManager Args: oldBiomeList, x, z, width, depth
  169. */
  170. @Override
  171. public BiomeGenBase[] loadBlockGeneratorData(BiomeGenBase[] oldBiomeList, int x, int z, int width, int depth)
  172. {
  173. return this.getBiomeGenAt(oldBiomeList, x, z, width, depth, true);
  174. }
  175.  
  176. /**
  177. * Return a list of biomes for the specified blocks. Args: listToReuse, x, y, width, length, cacheFlag (if false,
  178. * don't check biomeCache to avoid infinite loop in BiomeCacheBlock)
  179. */
  180. @Override
  181. public BiomeGenBase[] getBiomeGenAt(BiomeGenBase[] listToReuse, int x, int y, int width, int length, boolean cacheFlag)
  182. {
  183. IntCache.resetIntCache();
  184.  
  185. if (listToReuse == null || listToReuse.length < width * length)
  186. {
  187. listToReuse = new BiomeGenBase[width * length];
  188. }
  189.  
  190. if (cacheFlag && width == 16 && length == 16 && (x & 15) == 0 && (y & 15) == 0)
  191. {
  192. BiomeGenBase[] abiomegenbase1 = this.biomeCache.getCachedBiomes(x, y);
  193. System.arraycopy(abiomegenbase1, 0, listToReuse, 0, width * length);
  194. return listToReuse;
  195. }
  196. else
  197. {
  198. int[] aint = this.biomeIndexLayer.getInts(x, y, width, length);
  199.  
  200. for (int i = 0; i < width * length; ++i)
  201. {
  202. listToReuse[i] = BiomeGenBase.getBiome(aint[i]);
  203. }
  204. return listToReuse;
  205. }
  206. }
  207.  
  208. /**
  209. * checks given Chunk's Biomes against List of allowed ones
  210. */
  211. @Override
  212. @SuppressWarnings("rawtypes")
  213. public boolean areBiomesViable(int x, int y, int z, List par4List)
  214. {
  215. IntCache.resetIntCache();
  216. int l = x - z >> 2;
  217. int i1 = y - z >> 2;
  218. int j1 = x + z >> 2;
  219. int k1 = y + z >> 2;
  220. int l1 = j1 - l + 1;
  221. int i2 = k1 - i1 + 1;
  222. int[] aint = this.genBiomes.getInts(l, i1, l1, i2);
  223.  
  224. try
  225. {
  226. for (int j2 = 0; j2 < l1 * i2; ++j2)
  227. {
  228. BiomeGenBase biomegenbase = BiomeGenBase.getBiome(aint[j2]);
  229.  
  230. if (!par4List.contains(biomegenbase))
  231. {
  232. return false;
  233. }
  234. }
  235.  
  236. return true;
  237. }
  238. catch (Throwable throwable)
  239. {
  240. CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Invalid Biome id");
  241. CrashReportCategory crashreportcategory = crashreport.makeCategory("Layer");
  242. crashreportcategory.addCrashSection("Layer", this.genBiomes.toString());
  243. crashreportcategory.addCrashSection("x", Integer.valueOf(x));
  244. crashreportcategory.addCrashSection("z", Integer.valueOf(y));
  245. crashreportcategory.addCrashSection("radius", Integer.valueOf(z));
  246. crashreportcategory.addCrashSection("allowed", par4List);
  247. throw new ReportedException(crashreport);
  248. }
  249. }
  250.  
  251. /**
  252. * Finds a valid position within a range, that is in one of the listed
  253. * biomes. Searches {par1,par2} +-par3 blocks. Strongly favors positive y
  254. * positions.
  255. */
  256. @Override
  257. @SuppressWarnings("rawtypes")
  258. public ChunkPosition findBiomePosition(int x, int y, int z, List par4List, Random random)
  259. {
  260. IntCache.resetIntCache();
  261. int l = x - z >> 2;
  262. int i1 = y - z >> 2;
  263. int j1 = x + z >> 2;
  264. int k1 = y + z >> 2;
  265. int l1 = j1 - l + 1;
  266. int i2 = k1 - i1 + 1;
  267. int[] aint = this.genBiomes.getInts(l, i1, l1, i2);
  268. ChunkPosition chunkposition = null;
  269. int j2 = 0;
  270.  
  271. for (int k2 = 0; k2 < l1 * i2; ++k2)
  272. {
  273. int l2 = l + k2 % l1 << 2;
  274. int i3 = i1 + k2 / l1 << 2;
  275. BiomeGenBase biomegenbase = BiomeGenBase.getBiome(aint[k2]);
  276.  
  277. if (par4List.contains(biomegenbase) && (chunkposition == null || random.nextInt(j2 + 1) == 0))
  278. {
  279. chunkposition = new ChunkPosition(l2, 0, i3);
  280. ++j2;
  281. }
  282. }
  283.  
  284. return chunkposition;
  285. }
  286.  
  287. /**
  288. * Calls the WorldChunkManager's biomeCache.cleanupCache()
  289. */
  290. @Override
  291. public void cleanupCache()
  292. {
  293. this.biomeCache.cleanupCache();
  294. }
  295. }
Advertisement
Add Comment
Please, Sign In to add comment