/newcode/src/com/pclewis/mcpatcher/mod/BiomeHelper.java

https://github.com/pclewis/mcpatcher · Java · 141 lines · 111 code · 30 blank · 0 comment · 11 complexity · f79c6ba42a02ccf62f170d5ac10331bb MD5 · raw file

  1. package com.pclewis.mcpatcher.mod;
  2. import com.pclewis.mcpatcher.MCLogger;
  3. import com.pclewis.mcpatcher.MCPatcherUtils;
  4. import net.minecraft.src.BiomeGenBase;
  5. import net.minecraft.src.IBlockAccess;
  6. import net.minecraft.src.WorldChunkManager;
  7. abstract class BiomeHelper {
  8. private static final MCLogger logger = MCLogger.getLogger(MCPatcherUtils.CUSTOM_COLORS);
  9. static BiomeHelper instance;
  10. IBlockAccess blockAccess;
  11. static String getBiomeNameAt(int i, int j, int k) {
  12. if (instance == null) {
  13. return null;
  14. } else {
  15. BiomeGenBase biome = instance.getBiomeGenAt(i, j, k);
  16. return biome == null ? null : biome.biomeName;
  17. }
  18. }
  19. BiomeHelper(IBlockAccess blockAccess) {
  20. this.blockAccess = blockAccess;
  21. }
  22. boolean useBlockBlending() {
  23. return false;
  24. }
  25. abstract BiomeGenBase getBiomeGenAt(int i, int j, int k);
  26. abstract float getTemperature(int i, int j, int k);
  27. abstract float getRainfall(int i, int j, int k);
  28. abstract int getWaterColorMultiplier(int i, int j, int k);
  29. static class Stub extends BiomeHelper {
  30. Stub() {
  31. super(null);
  32. }
  33. @Override
  34. BiomeGenBase getBiomeGenAt(int i, int j, int k) {
  35. return null;
  36. }
  37. @Override
  38. float getTemperature(int i, int j, int k) {
  39. return 0.5f;
  40. }
  41. @Override
  42. float getRainfall(int i, int j, int k) {
  43. return 1.0f;
  44. }
  45. @Override
  46. int getWaterColorMultiplier(int i, int j, int k) {
  47. return 0xffffff;
  48. }
  49. }
  50. static class Old extends BiomeHelper {
  51. WorldChunkManager chunkManager;
  52. Old(IBlockAccess blockAccess) {
  53. super(blockAccess);
  54. chunkManager = blockAccess.getWorldChunkManager();
  55. }
  56. @Override
  57. BiomeGenBase getBiomeGenAt(int i, int j, int k) {
  58. return chunkManager.getBiomeGenAt(i, k);
  59. }
  60. @Override
  61. float getTemperature(int i, int j, int k) {
  62. return chunkManager.getTemperature(i, j, k);
  63. }
  64. @Override
  65. float getRainfall(int i, int j, int k) {
  66. return chunkManager.getRainfall(i, k);
  67. }
  68. @Override
  69. int getWaterColorMultiplier(int i, int j, int k) {
  70. return getBiomeGenAt(i, j, k).waterColorMultiplier;
  71. }
  72. }
  73. static class New extends BiomeHelper {
  74. private static boolean logged;
  75. private BiomeGenBase lastBiome;
  76. private int lastI;
  77. private int lastK;
  78. New(IBlockAccess blockAccess) {
  79. super(blockAccess);
  80. if (!logged) {
  81. logged = true;
  82. logger.config("biomes v1.2 detected");
  83. }
  84. }
  85. @Override
  86. boolean useBlockBlending() {
  87. return true;
  88. }
  89. @Override
  90. BiomeGenBase getBiomeGenAt(int i, int j, int k) {
  91. if (lastBiome == null || i != lastI || k != lastK) {
  92. lastI = i;
  93. lastK = k;
  94. lastBiome = blockAccess.getBiomeGenAt(i, k);
  95. }
  96. return lastBiome;
  97. }
  98. @Override
  99. float getTemperature(int i, int j, int k) {
  100. return getBiomeGenAt(i, j, k).getTemperaturef();
  101. }
  102. @Override
  103. float getRainfall(int i, int j, int k) {
  104. return getBiomeGenAt(i, j, k).getRainfallf();
  105. }
  106. @Override
  107. int getWaterColorMultiplier(int i, int j, int k) {
  108. return getBiomeGenAt(i, j, k).waterColorMultiplier;
  109. }
  110. }
  111. }