PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/newcode/src/com/prupe/mcpatcher/cc/ColorMap.java

https://bitbucket.org/SevenBits/mcpatcher
Java | 726 lines | 605 code | 121 blank | 0 comment | 89 complexity | bfb5bc0cf672223f778284b901eb9180 MD5 | raw file
  1. package com.prupe.mcpatcher.cc;
  2. import com.prupe.mcpatcher.*;
  3. import com.prupe.mcpatcher.mal.biome.BiomeAPI;
  4. import com.prupe.mcpatcher.mal.resource.ResourceList;
  5. import net.minecraft.src.BiomeGenBase;
  6. import net.minecraft.src.IBlockAccess;
  7. import net.minecraft.src.ResourceLocation;
  8. import java.awt.image.BufferedImage;
  9. import java.util.*;
  10. abstract class ColorMap implements IColorMap {
  11. private static final MCLogger logger = MCLogger.getLogger(MCPatcherUtils.CUSTOM_COLORS);
  12. private static final int FIXED = 0;
  13. private static final int TEMPERATURE_HUMIDITY = 1;
  14. private static final int BIOME_HEIGHT = 2;
  15. private static final int COLORMAP_WIDTH = 256;
  16. private static final int COLORMAP_HEIGHT = 256;
  17. static final String BLOCK_COLORMAP_DIR = TexturePackAPI.MCPATCHER_SUBDIR + "colormap/blocks";
  18. static final List<ResourceLocation> unusedPNGs = new ArrayList<ResourceLocation>();
  19. private static final String VANILLA_TYPE = "_vanillaType";
  20. private static final String ALT_SOURCE = "_altSource";
  21. private static int defaultColorMapFormat;
  22. private static boolean defaultFlipY;
  23. private static float defaultYVariance;
  24. protected final ResourceLocation resource;
  25. protected final int[] map;
  26. protected final int width;
  27. protected final int height;
  28. protected final float maxX;
  29. protected final float maxY;
  30. private final float[] xy = new float[2];
  31. private final float[] lastColor = new float[3];
  32. static IColorMap loadVanillaColorMap(ResourceLocation vanillaImage, ResourceLocation swampImage) {
  33. Properties properties = new Properties();
  34. properties.setProperty("format", "1");
  35. properties.setProperty("source", vanillaImage.toString());
  36. if (!TexturePackAPI.hasCustomResource(vanillaImage)) {
  37. if (vanillaImage.getPath().contains("grass")) {
  38. properties.setProperty(VANILLA_TYPE, "grass");
  39. } else if (vanillaImage.getPath().contains("foliage")) {
  40. properties.setProperty(VANILLA_TYPE, "foliage");
  41. }
  42. }
  43. if (swampImage != null) {
  44. properties.setProperty(ALT_SOURCE, swampImage.toString());
  45. }
  46. return loadColorMap(true, vanillaImage, properties);
  47. }
  48. static IColorMap loadFixedColorMap(boolean useCustom, ResourceLocation resource) {
  49. return loadColorMap(useCustom, resource, null);
  50. }
  51. static IColorMap loadColorMap(boolean useCustom, ResourceLocation resource, Properties properties) {
  52. IColorMap map = loadColorMap1(useCustom, resource, properties);
  53. if (map != null) {
  54. map.claimResources(unusedPNGs);
  55. }
  56. return map;
  57. }
  58. private static IColorMap loadColorMap1(boolean useCustom, ResourceLocation resource, Properties properties) {
  59. if (!useCustom || resource == null) {
  60. return null;
  61. }
  62. ResourceLocation propertiesResource;
  63. ResourceLocation imageResource;
  64. if (resource.toString().endsWith(".png")) {
  65. propertiesResource = TexturePackAPI.transformResourceLocation(resource, ".png", ".properties");
  66. imageResource = resource;
  67. } else if (resource.toString().endsWith(".properties")) {
  68. propertiesResource = resource;
  69. imageResource = TexturePackAPI.transformResourceLocation(resource, ".properties", ".png");
  70. } else {
  71. return null;
  72. }
  73. if (properties == null) {
  74. properties = TexturePackAPI.getProperties(propertiesResource);
  75. if (properties == null) {
  76. properties = new Properties();
  77. }
  78. }
  79. int format = parseFormat(MCPatcherUtils.getStringProperty(properties, "format", ""));
  80. if (format == FIXED) {
  81. int color = MCPatcherUtils.getHexProperty(properties, "color", 0xffffff);
  82. return new Fixed(color);
  83. }
  84. String path = MCPatcherUtils.getStringProperty(properties, "source", "");
  85. if (!MCPatcherUtils.isNullOrEmpty(path)) {
  86. imageResource = TexturePackAPI.parseResourceLocation(resource, path);
  87. }
  88. BufferedImage image = TexturePackAPI.getImage(imageResource);
  89. if (image == null) {
  90. return null;
  91. }
  92. switch (format) {
  93. case TEMPERATURE_HUMIDITY:
  94. String vanillaSource = MCPatcherUtils.getStringProperty(properties, VANILLA_TYPE, "");
  95. IColorMap defaultMap;
  96. if ("grass".equals(vanillaSource)) {
  97. defaultMap = new Grass(image);
  98. } else if ("foliage".equals(vanillaSource)) {
  99. defaultMap = new Foliage(image);
  100. } else {
  101. defaultMap = new TempHumidity(imageResource, properties, image);
  102. }
  103. path = MCPatcherUtils.getStringProperty(properties, ALT_SOURCE, "");
  104. if (Colorizer.useSwampColors && !MCPatcherUtils.isNullOrEmpty(path)) {
  105. ResourceLocation swampResource = TexturePackAPI.parseResourceLocation(resource, path);
  106. image = TexturePackAPI.getImage(swampResource);
  107. if (image != null) {
  108. IColorMap swampMap = new TempHumidity(swampResource, properties, image);
  109. return new Swamp(defaultMap, swampMap);
  110. }
  111. }
  112. return defaultMap;
  113. case BIOME_HEIGHT:
  114. Grid grid = new Grid(imageResource, properties, image);
  115. if (grid.isInteger()) {
  116. return new IntegerGrid(grid);
  117. } else {
  118. return grid;
  119. }
  120. default:
  121. logger.error("%s: unknown format %d", resource, format);
  122. return null;
  123. }
  124. }
  125. static void reset() {
  126. unusedPNGs.clear();
  127. defaultColorMapFormat = TEMPERATURE_HUMIDITY;
  128. defaultFlipY = false;
  129. defaultYVariance = Config.getInt(MCPatcherUtils.CUSTOM_COLORS, "yVariance", 0);
  130. }
  131. static void reloadColorMapSettings(Properties properties) {
  132. unusedPNGs.addAll(ResourceList.getInstance().listResources(BLOCK_COLORMAP_DIR, ".png", false));
  133. defaultColorMapFormat = parseFormat(MCPatcherUtils.getStringProperty(properties, "palette.format", ""));
  134. defaultFlipY = MCPatcherUtils.getBooleanProperty(properties, "palette.flipY", false);
  135. defaultYVariance = MCPatcherUtils.getFloatProperty(properties, "palette.yVariance", 0.0f);
  136. }
  137. private static int parseFormat(String value) {
  138. if (MCPatcherUtils.isNullOrEmpty(value)) {
  139. return defaultColorMapFormat;
  140. }
  141. value = value.toLowerCase();
  142. if (value.matches("^\\d+$")) {
  143. try {
  144. return Integer.parseInt(value);
  145. } catch (NumberFormatException e) {
  146. e.printStackTrace();
  147. }
  148. } else if (value.equals("fixed")) {
  149. return FIXED;
  150. } else if (value.equals("temperature+humidity") || value.equals("t+h") || value.equals("vanilla")) {
  151. return TEMPERATURE_HUMIDITY;
  152. } else if (value.equals("biome+height") || value.equals("b+h") || value.equals("grid")) {
  153. return BIOME_HEIGHT;
  154. }
  155. return defaultColorMapFormat;
  156. }
  157. ColorMap(ResourceLocation resource, Properties properties, BufferedImage image) {
  158. this(resource, MCPatcherUtils.getImageRGB(image), image.getWidth(), image.getHeight());
  159. }
  160. ColorMap(ResourceLocation resource, int[] map, int width, int height) {
  161. this.resource = resource;
  162. this.map = map;
  163. this.width = width;
  164. this.height = height;
  165. for (int i = 0; i < map.length; i++) {
  166. map[i] &= 0xffffff;
  167. }
  168. maxX = width - 1.0f;
  169. maxY = height - 1.0f;
  170. }
  171. abstract protected void computeXY(BiomeGenBase biome, int i, int j, int k, float[] f);
  172. @Override
  173. public String toString() {
  174. return getClass().getSimpleName() + "{" + resource + "}";
  175. }
  176. @Override
  177. public final int getColorMultiplier(IBlockAccess blockAccess, int i, int j, int k) {
  178. computeXY(BiomeAPI.getBiomeGenAt(blockAccess, i, j, k), i, j, k, xy);
  179. return getRGB(xy[0], xy[1]);
  180. }
  181. @Override
  182. public final float[] getColorMultiplierF(IBlockAccess blockAccess, int i, int j, int k) {
  183. int rgb = getColorMultiplier(blockAccess, i, j, k);
  184. Colorizer.intToFloat3(rgb, lastColor);
  185. return lastColor;
  186. }
  187. @Override
  188. public void claimResources(Collection<ResourceLocation> resources) {
  189. resources.remove(resource);
  190. }
  191. protected int getRGB(float x, float y) {
  192. x = clamp(x, 0.0f, maxX);
  193. y = clamp(y, 0.0f, maxY);
  194. int x0 = (int) x;
  195. int dx = (int) (256.0f * (x - (float) x0));
  196. int x1 = x0 + 1;
  197. int y0 = (int) y;
  198. int dy = (int) (256.0f * (y - (float) y0));
  199. int y1 = y0 + 1;
  200. if (dx == 0 && dy == 0) {
  201. return getRGB(x0, y0);
  202. } else if (dx == 0) {
  203. return interpolate(x0, y0, x0, y1, dy);
  204. } else if (dy == 0) {
  205. return interpolate(x0, y0, x1, y0, dx);
  206. } else {
  207. return interpolate(
  208. interpolate(x0, y0, x1, y0, dx),
  209. interpolate(x0, y1, x1, y1, dx),
  210. dy
  211. );
  212. }
  213. }
  214. private int getRGB(int x, int y) {
  215. return map[x + width * y];
  216. }
  217. private int interpolate(int x1, int y1, int x2, int y2, int a2) {
  218. return interpolate(getRGB(x1, y1), getRGB(x2, y2), a2);
  219. }
  220. private static int interpolate(int rgb1, int rgb2, int a2) {
  221. int a1 = 256 - a2;
  222. int r1 = (rgb1 >> 16) & 0xff;
  223. int g1 = (rgb1 >> 8) & 0xff;
  224. int b1 = rgb1 & 0xff;
  225. int r2 = (rgb2 >> 16) & 0xff;
  226. int g2 = (rgb2 >> 8) & 0xff;
  227. int b2 = rgb2 & 0xff;
  228. int r = (a1 * r1 + a2 * r2) >> 8;
  229. int g = (a1 * g1 + a2 * g2) >> 8;
  230. int b = (a1 * b1 + a2 * b2) >> 8;
  231. return (r << 16) | (g << 8) | b;
  232. }
  233. protected static float noise0to1(int i, int j, int k, int l) {
  234. int hash = (int) WeightedIndex.hash128To64(i, j, k, l) & Integer.MAX_VALUE;
  235. return (float) ((double) hash / (double) Integer.MAX_VALUE);
  236. }
  237. protected static float noiseMinus1to1(int i, int j, int k, int l) {
  238. int hash = (int) WeightedIndex.hash128To64(i, j, k, l);
  239. return (float) ((double) hash / (double) Integer.MIN_VALUE);
  240. }
  241. protected static float clamp(float i, float min, float max) {
  242. if (i < min) {
  243. return min;
  244. } else if (i > max) {
  245. return max;
  246. } else {
  247. return i;
  248. }
  249. }
  250. protected static int clamp(int i, int min, int max) {
  251. if (i < min) {
  252. return min;
  253. } else if (i > max) {
  254. return max;
  255. } else {
  256. return i;
  257. }
  258. }
  259. static final class Fixed implements IColorMap {
  260. private final int colorI;
  261. private final float[] colorF = new float[3];
  262. Fixed(int color) {
  263. colorI = color;
  264. Colorizer.intToFloat3(colorI, colorF);
  265. }
  266. @Override
  267. public String toString() {
  268. return String.format("Fixed{%06x}", colorI);
  269. }
  270. @Override
  271. public boolean isHeightDependent() {
  272. return false;
  273. }
  274. @Override
  275. public int getColorMultiplier() {
  276. return colorI;
  277. }
  278. @Override
  279. public int getColorMultiplier(IBlockAccess blockAccess, int i, int j, int k) {
  280. return colorI;
  281. }
  282. @Override
  283. public float[] getColorMultiplierF(IBlockAccess blockAccess, int i, int j, int k) {
  284. return colorF;
  285. }
  286. @Override
  287. public void claimResources(Collection<ResourceLocation> resources) {
  288. }
  289. @Override
  290. public IColorMap copy() {
  291. return this;
  292. }
  293. }
  294. static final class Water implements IColorMap {
  295. private final float[] lastColor = new float[3];
  296. @Override
  297. public String toString() {
  298. return String.format("Water{%06x}", getColorMultiplier());
  299. }
  300. @Override
  301. public boolean isHeightDependent() {
  302. return false;
  303. }
  304. @Override
  305. public int getColorMultiplier() {
  306. return BiomeAPI.getWaterColorMultiplier(BiomeAPI.findBiomeByName("Ocean"));
  307. }
  308. @Override
  309. public int getColorMultiplier(IBlockAccess blockAccess, int i, int j, int k) {
  310. return BiomeAPI.getWaterColorMultiplier(BiomeAPI.getBiomeGenAt(blockAccess, i, j, k));
  311. }
  312. @Override
  313. public float[] getColorMultiplierF(IBlockAccess blockAccess, int i, int j, int k) {
  314. Colorizer.intToFloat3(getColorMultiplier(blockAccess, i, j, k), lastColor);
  315. return lastColor;
  316. }
  317. @Override
  318. public void claimResources(Collection<ResourceLocation> resources) {
  319. }
  320. @Override
  321. public IColorMap copy() {
  322. return new Water();
  323. }
  324. }
  325. abstract static class Vanilla implements IColorMap {
  326. protected final int defaultColor;
  327. protected final float[] lastColor = new float[3];
  328. Vanilla(BufferedImage image) {
  329. this(image.getRGB(127, 127));
  330. }
  331. Vanilla(int defaultColor) {
  332. this.defaultColor = defaultColor & 0xffffff;
  333. }
  334. @Override
  335. public String toString() {
  336. return String.format("%s{%06x}", getClass().getSimpleName(), defaultColor);
  337. }
  338. @Override
  339. final public boolean isHeightDependent() {
  340. return BiomeAPI.isColorHeightDependent;
  341. }
  342. @Override
  343. final public int getColorMultiplier() {
  344. return defaultColor;
  345. }
  346. @Override
  347. final public int getColorMultiplier(IBlockAccess blockAccess, int i, int j, int k) {
  348. return getColorMultiplier(BiomeAPI.getBiomeGenAt(blockAccess, i, j, k), i, j, k);
  349. }
  350. @Override
  351. final public float[] getColorMultiplierF(IBlockAccess blockAccess, int i, int j, int k) {
  352. Colorizer.intToFloat3(getColorMultiplier(blockAccess, i, j, k), lastColor);
  353. return lastColor;
  354. }
  355. @Override
  356. final public void claimResources(Collection<ResourceLocation> resources) {
  357. }
  358. abstract int getColorMultiplier(BiomeGenBase biome, int i, int j, int k);
  359. }
  360. static final class Grass extends Vanilla {
  361. Grass(BufferedImage image) {
  362. super(image);
  363. }
  364. Grass(int defaultColor) {
  365. super(defaultColor);
  366. }
  367. @Override
  368. public IColorMap copy() {
  369. return new Grass(defaultColor);
  370. }
  371. @Override
  372. int getColorMultiplier(BiomeGenBase biome, int i, int j, int k) {
  373. return BiomeAPI.getGrassColor(biome, i, j, k);
  374. }
  375. }
  376. static final class Foliage extends Vanilla {
  377. Foliage(BufferedImage image) {
  378. super(image);
  379. }
  380. Foliage(int defaultColor) {
  381. super(defaultColor);
  382. }
  383. @Override
  384. public IColorMap copy() {
  385. return new Foliage(defaultColor);
  386. }
  387. @Override
  388. int getColorMultiplier(BiomeGenBase biome, int i, int j, int k) {
  389. return BiomeAPI.getFoliageColor(biome, i, j, k);
  390. }
  391. }
  392. static final class Swamp implements IColorMap {
  393. private final IColorMap defaultMap;
  394. private final IColorMap swampMap;
  395. private final BiomeGenBase swampBiome;
  396. Swamp(IColorMap defaultMap, IColorMap swampMap) {
  397. this.defaultMap = defaultMap;
  398. this.swampMap = swampMap;
  399. swampBiome = BiomeAPI.findBiomeByName("Swampland");
  400. }
  401. @Override
  402. public String toString() {
  403. return defaultMap.toString();
  404. }
  405. @Override
  406. public boolean isHeightDependent() {
  407. return defaultMap.isHeightDependent() || swampMap.isHeightDependent();
  408. }
  409. @Override
  410. public int getColorMultiplier() {
  411. return defaultMap.getColorMultiplier();
  412. }
  413. @Override
  414. public int getColorMultiplier(IBlockAccess blockAccess, int i, int j, int k) {
  415. IColorMap map = BiomeAPI.getBiomeGenAt(blockAccess, i, j, k) == swampBiome ? swampMap : defaultMap;
  416. return map.getColorMultiplier(blockAccess, i, j, k);
  417. }
  418. @Override
  419. public float[] getColorMultiplierF(IBlockAccess blockAccess, int i, int j, int k) {
  420. IColorMap map = BiomeAPI.getBiomeGenAt(blockAccess, i, j, k) == swampBiome ? swampMap : defaultMap;
  421. return map.getColorMultiplierF(blockAccess, i, j, k);
  422. }
  423. @Override
  424. public void claimResources(Collection<ResourceLocation> resources) {
  425. defaultMap.claimResources(resources);
  426. swampMap.claimResources(resources);
  427. }
  428. @Override
  429. public IColorMap copy() {
  430. return new Swamp(defaultMap.copy(), swampMap.copy());
  431. }
  432. }
  433. static final class TempHumidity extends ColorMap {
  434. private final int defaultColor;
  435. private TempHumidity(ResourceLocation resource, Properties properties, BufferedImage image) {
  436. super(resource, properties, image);
  437. defaultColor = MCPatcherUtils.getHexProperty(properties, "color", getRGB(maxX * 0.5f, maxY * 0.5f));
  438. }
  439. private TempHumidity(ResourceLocation resource, int[] map, int width, int height, int defaultColor) {
  440. super(resource, map, width, height);
  441. this.defaultColor = defaultColor;
  442. }
  443. @Override
  444. public boolean isHeightDependent() {
  445. return BiomeAPI.isColorHeightDependent;
  446. }
  447. @Override
  448. public int getColorMultiplier() {
  449. return defaultColor;
  450. }
  451. @Override
  452. public IColorMap copy() {
  453. return new TempHumidity(resource, map, width, height, defaultColor);
  454. }
  455. @Override
  456. protected void computeXY(BiomeGenBase biome, int i, int j, int k, float[] f) {
  457. float temperature = Colorizer.clamp(BiomeAPI.getTemperature(biome, i, j, k));
  458. float rainfall = Colorizer.clamp(BiomeAPI.getRainfall(biome, i, j, k));
  459. f[0] = maxX * (1.0f - temperature);
  460. f[1] = maxY * (1.0f - temperature * rainfall);
  461. }
  462. }
  463. static final class Grid extends ColorMap {
  464. private final float[] biomeX = new float[BiomeGenBase.biomeList.length];
  465. private final float yVariance;
  466. private final float yOffset;
  467. private final int defaultColor;
  468. private Grid(ResourceLocation resource, Properties properties, BufferedImage image) {
  469. super(resource, properties, image);
  470. if (MCPatcherUtils.getBooleanProperty(properties, "flipY", defaultFlipY)) {
  471. int[] temp = new int[width];
  472. for (int i = 0; i < map.length / 2; i += width) {
  473. int j = map.length - width - i;
  474. System.arraycopy(map, i, temp, 0, width);
  475. System.arraycopy(map, j, map, i, width);
  476. System.arraycopy(temp, 0, map, j, width);
  477. }
  478. }
  479. yVariance = Math.max(MCPatcherUtils.getFloatProperty(properties, "yVariance", defaultYVariance), 0.0f);
  480. yOffset = MCPatcherUtils.getFloatProperty(properties, "yOffset", 0.0f);
  481. for (int i = 0; i < biomeX.length; i++) {
  482. biomeX[i] = i % width;
  483. }
  484. for (Map.Entry<Object, Object> entry : properties.entrySet()) {
  485. String key = (String) entry.getKey();
  486. String value = (String) entry.getValue();
  487. if (key.endsWith(".x") && !MCPatcherUtils.isNullOrEmpty(value)) {
  488. key = key.substring(0, key.length() - 2);
  489. BiomeGenBase biome = BiomeAPI.findBiomeByName(key);
  490. if (biome != null && biome.biomeID >= 0 && biome.biomeID < BiomeGenBase.biomeList.length) {
  491. try {
  492. biomeX[biome.biomeID] = Float.parseFloat(value);
  493. } catch (NumberFormatException e) {
  494. e.printStackTrace();
  495. }
  496. }
  497. }
  498. }
  499. defaultColor = MCPatcherUtils.getHexProperty(properties, "color", getRGB(biomeX[1], getY(ColorMapBase.DEFAULT_HEIGHT)));
  500. }
  501. private Grid(ResourceLocation resource, int[] map, int width, int height, float[] biomeX, float yVariance, float yOffset, int defaultColor) {
  502. super(resource, map, width, height);
  503. System.arraycopy(biomeX, 0, this.biomeX, 0, biomeX.length);
  504. this.yVariance = yVariance;
  505. this.yOffset = yOffset;
  506. this.defaultColor = defaultColor;
  507. }
  508. boolean isInteger() {
  509. if (yVariance != 0.0f || Math.floor(yOffset) != yOffset) {
  510. return false;
  511. }
  512. for (int i = 0; i < biomeX.length; i++) {
  513. if (biomeX[i] != i % width) {
  514. return false;
  515. }
  516. }
  517. return true;
  518. }
  519. @Override
  520. public boolean isHeightDependent() {
  521. return true;
  522. }
  523. @Override
  524. public int getColorMultiplier() {
  525. return defaultColor;
  526. }
  527. @Override
  528. public IColorMap copy() {
  529. return new Grid(resource, map, width, height, biomeX, yVariance, yOffset, defaultColor);
  530. }
  531. @Override
  532. protected void computeXY(BiomeGenBase biome, int i, int j, int k, float[] f) {
  533. f[0] = getX(biome, i, j, k);
  534. f[1] = getY(biome, i, j, k);
  535. }
  536. private float getX(BiomeGenBase biome, int i, int j, int k) {
  537. return biomeX[biome.biomeID];
  538. }
  539. private float getY(int j) {
  540. return (float) j - yOffset;
  541. }
  542. private float getY(BiomeGenBase biome, int i, int j, int k) {
  543. float y = getY(j);
  544. if (yVariance != 0.0f) {
  545. y += yVariance * noiseMinus1to1(k, -j, i, ~biome.biomeID);
  546. }
  547. return y;
  548. }
  549. }
  550. static final class IntegerGrid implements IColorMap {
  551. private final ResourceLocation resource;
  552. private final int[] map;
  553. private final int width;
  554. private final int maxHeight;
  555. private final int yOffset;
  556. private final int defaultColor;
  557. private final float[] lastColor = new float[3];
  558. IntegerGrid(Grid grid) {
  559. this(grid.resource, grid.map, grid.width, grid.height - 1, (int) grid.yOffset, grid.defaultColor);
  560. }
  561. IntegerGrid(ResourceLocation resource, int[] map, int width, int maxHeight, int yOffset, int defaultColor) {
  562. this.resource = resource;
  563. this.map = map;
  564. this.width = width;
  565. this.maxHeight = maxHeight;
  566. this.yOffset = yOffset;
  567. this.defaultColor = defaultColor;
  568. }
  569. @Override
  570. public String toString() {
  571. return getClass().getSimpleName() + "{" + resource + "}";
  572. }
  573. @Override
  574. public boolean isHeightDependent() {
  575. return true;
  576. }
  577. @Override
  578. public int getColorMultiplier() {
  579. return defaultColor;
  580. }
  581. @Override
  582. public int getColorMultiplier(IBlockAccess blockAccess, int i, int j, int k) {
  583. return getRGB(BiomeAPI.getBiomeIDAt(blockAccess, i, j, k), j);
  584. }
  585. @Override
  586. public float[] getColorMultiplierF(IBlockAccess blockAccess, int i, int j, int k) {
  587. int rgb = getColorMultiplier(blockAccess, i, j, k);
  588. Colorizer.intToFloat3(rgb, lastColor);
  589. return lastColor;
  590. }
  591. @Override
  592. public void claimResources(Collection<ResourceLocation> resources) {
  593. resources.remove(resource);
  594. }
  595. @Override
  596. public IColorMap copy() {
  597. return new IntegerGrid(resource, map, width, maxHeight, yOffset, defaultColor);
  598. }
  599. private int getRGB(int x, int y) {
  600. x = clamp(x, 0, COLORMAP_WIDTH - 1) % width;
  601. y = clamp(y - yOffset, 0, maxHeight);
  602. return map[y * width + x];
  603. }
  604. }
  605. }