PageRenderTime 97ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/prupe/mcpatcher
Java | 579 lines | 501 code | 65 blank | 13 comment | 89 complexity | 9dd493e03be224f38fe12e6d6c63e713 MD5 | raw file
  1. package com.prupe.mcpatcher.cc;
  2. import com.prupe.mcpatcher.Config;
  3. import com.prupe.mcpatcher.MCLogger;
  4. import com.prupe.mcpatcher.MCPatcherUtils;
  5. import com.prupe.mcpatcher.mal.biome.*;
  6. import com.prupe.mcpatcher.mal.block.BlockAPI;
  7. import com.prupe.mcpatcher.mal.block.BlockStateMatcher;
  8. import com.prupe.mcpatcher.mal.block.RenderBlocksUtils;
  9. import com.prupe.mcpatcher.mal.resource.GLAPI;
  10. import com.prupe.mcpatcher.mal.resource.PropertiesFile;
  11. import com.prupe.mcpatcher.mal.resource.ResourceList;
  12. import com.prupe.mcpatcher.mal.resource.TexturePackAPI;
  13. import net.minecraft.src.Block;
  14. import net.minecraft.src.IBlockAccess;
  15. import net.minecraft.src.RenderBlocks;
  16. import net.minecraft.src.ResourceLocation;
  17. import java.util.*;
  18. public class ColorizeBlock {
  19. private static final MCLogger logger = MCLogger.getLogger(MCPatcherUtils.CUSTOM_COLORS);
  20. private static final boolean useWaterColors = Config.getBoolean(MCPatcherUtils.CUSTOM_COLORS, "water", true);
  21. private static final boolean useTreeColors = Config.getBoolean(MCPatcherUtils.CUSTOM_COLORS, "tree", true);
  22. private static final boolean useRedstoneColors = Config.getBoolean(MCPatcherUtils.CUSTOM_COLORS, "redstone", true);
  23. private static final boolean useStemColors = Config.getBoolean(MCPatcherUtils.CUSTOM_COLORS, "stem", true);
  24. private static final boolean useBlockColors = Config.getBoolean(MCPatcherUtils.CUSTOM_COLORS, "otherBlocks", true);
  25. static final boolean enableSmoothBiomes = Config.getBoolean(MCPatcherUtils.CUSTOM_COLORS, "smoothBiomes", true);
  26. static final boolean enableTestColorSmoothing = Config.getBoolean(MCPatcherUtils.CUSTOM_COLORS, "testColorSmoothing", false);
  27. private static final ResourceLocation REDSTONE_COLORS = TexturePackAPI.newMCPatcherResourceLocation("/misc/redstonecolor.png", "colormap/redstone.png");
  28. private static final ResourceLocation STEM_COLORS = TexturePackAPI.newMCPatcherResourceLocation("/misc/stemcolor.png", "colormap/stem.png");
  29. private static final ResourceLocation PUMPKIN_STEM_COLORS = TexturePackAPI.newMCPatcherResourceLocation("/misc/pumpkinstemcolor.png", "colormap/pumpkinstem.png");
  30. private static final ResourceLocation MELON_STEM_COLORS = TexturePackAPI.newMCPatcherResourceLocation("/misc/melonstemcolor.png", "colormap/melonstem.png");
  31. private static final ResourceLocation SWAMPGRASSCOLOR = TexturePackAPI.newMCPatcherResourceLocation("/misc/swampgrasscolor.png", "colormap/swampgrass.png");
  32. private static final ResourceLocation SWAMPFOLIAGECOLOR = TexturePackAPI.newMCPatcherResourceLocation("/misc/swampfoliagecolor.png", "colormap/swampfoliage.png");
  33. private static final ResourceLocation DEFAULT_GRASSCOLOR = new ResourceLocation(TexturePackAPI.select("/misc/grasscolor.png", "minecraft:textures/colormap/grass.png"));
  34. private static final ResourceLocation DEFAULT_FOLIAGECOLOR = new ResourceLocation(TexturePackAPI.select("/misc/foliagecolor.png", "minecraft:textures/colormap/foliage.png"));
  35. private static final ResourceLocation PINECOLOR = TexturePackAPI.newMCPatcherResourceLocation("/misc/pinecolor.png", "colormap/pine.png");
  36. private static final ResourceLocation BIRCHCOLOR = TexturePackAPI.newMCPatcherResourceLocation("/misc/birchcolor.png", "colormap/birch.png");
  37. private static final ResourceLocation WATERCOLOR = TexturePackAPI.newMCPatcherResourceLocation("/misc/watercolorX.png", "colormap/water.png");
  38. private static final String PALETTE_BLOCK_KEY = "palette.block.";
  39. private static Block waterBlock;
  40. private static Block staticWaterBlock;
  41. private static final Map<Block, List<BlockStateMatcher>> blockColorMaps = new IdentityHashMap<Block, List<BlockStateMatcher>>(); // bitmaps from palette.block.*
  42. private static IColorMap waterColorMap;
  43. private static float[][] redstoneColor; // colormap/redstone.png
  44. private static final int blockBlendRadius = Config.getInt(MCPatcherUtils.CUSTOM_COLORS, "blockBlendRadius2", 4);
  45. public static int blockColor;
  46. public static boolean isSmooth;
  47. public static float colorRedTopLeft;
  48. public static float colorRedBottomLeft;
  49. public static float colorRedBottomRight;
  50. public static float colorRedTopRight;
  51. public static float colorGreenTopLeft;
  52. public static float colorGreenBottomLeft;
  53. public static float colorGreenBottomRight;
  54. public static float colorGreenTopRight;
  55. public static float colorBlueTopLeft;
  56. public static float colorBlueBottomLeft;
  57. public static float colorBlueBottomRight;
  58. public static float colorBlueTopRight;
  59. private static final int[][][] FACE_VERTICES = new int[][][]{
  60. // bottom face (y=0)
  61. {
  62. {0, 0, 1}, // top left
  63. {0, 0, 0}, // bottom left
  64. {1, 0, 0}, // bottom right
  65. {1, 0, 1}, // top right
  66. },
  67. // top face (y=1)
  68. {
  69. {1, 1, 1},
  70. {1, 1, 0},
  71. {0, 1, 0},
  72. {0, 1, 1},
  73. },
  74. // north face (z=0)
  75. {
  76. {0, 1, 0},
  77. {1, 1, 0},
  78. {1, 0, 0},
  79. {0, 0, 0},
  80. },
  81. // south face (z=1)
  82. {
  83. {0, 1, 1},
  84. {0, 0, 1},
  85. {1, 0, 1},
  86. {1, 1, 1},
  87. },
  88. // west face (x=0)
  89. {
  90. {0, 1, 1},
  91. {0, 1, 0},
  92. {0, 0, 0},
  93. {0, 0, 1},
  94. },
  95. // east face (x=1)
  96. {
  97. {1, 0, 1},
  98. {1, 0, 0},
  99. {1, 1, 0},
  100. {1, 1, 1},
  101. },
  102. // bottom face, water (y=0)
  103. {
  104. {0, 0, 1}, // top left
  105. {0, 0, 0}, // bottom left
  106. {1, 0, 0}, // bottom right
  107. {1, 0, 1}, // top right
  108. },
  109. // top face, water (y=1) cycle by 2
  110. {
  111. {0, 1, 0},
  112. {0, 1, 1},
  113. {1, 1, 1},
  114. {1, 1, 0},
  115. },
  116. // north face, water (z=0)
  117. {
  118. {0, 1, 0},
  119. {1, 1, 0},
  120. {1, 0, 0},
  121. {0, 0, 0},
  122. },
  123. // south face, water (z=1) cycle by 1
  124. {
  125. {1, 1, 1},
  126. {0, 1, 1},
  127. {0, 0, 1},
  128. {1, 0, 1},
  129. },
  130. // west face, water (x=0)
  131. {
  132. {0, 1, 1},
  133. {0, 1, 0},
  134. {0, 0, 0},
  135. {0, 0, 1},
  136. },
  137. // east face, water (x=1) cycle by 2
  138. {
  139. {1, 1, 0},
  140. {1, 1, 1},
  141. {1, 0, 1},
  142. {1, 0, 0},
  143. },
  144. };
  145. static {
  146. try {
  147. reset();
  148. } catch (Throwable e) {
  149. e.printStackTrace();
  150. }
  151. }
  152. static void reset() {
  153. waterBlock = BlockAPI.getFixedBlock("minecraft:flowing_water");
  154. staticWaterBlock = BlockAPI.getFixedBlock("minecraft:water");
  155. blockColorMaps.clear();
  156. waterColorMap = null;
  157. resetVertexColors();
  158. redstoneColor = null;
  159. }
  160. static void reloadAll(PropertiesFile properties) {
  161. if (useBlockColors) {
  162. reloadBlockColors(properties);
  163. }
  164. if (useTreeColors) {
  165. reloadFoliageColors(properties);
  166. }
  167. if (useWaterColors) {
  168. reloadWaterColors(properties);
  169. }
  170. if (ColorMap.useSwampColors) {
  171. reloadSwampColors(properties);
  172. }
  173. if (useRedstoneColors) {
  174. reloadRedstoneColors(properties);
  175. }
  176. if (useStemColors) {
  177. reloadStemColors(properties);
  178. }
  179. }
  180. private static void reloadFoliageColors(PropertiesFile properties) {
  181. IColorMap colorMap = ColorMap.loadVanillaColorMap(DEFAULT_GRASSCOLOR, SWAMPGRASSCOLOR);
  182. registerColorMap(colorMap, DEFAULT_GRASSCOLOR, "minecraft:grass:snowy=false minecraft:tallgrass:1,2:type=tall_grass,fern minecraft:double_plant:2,3:variant=double_grass,double_fern");
  183. colorMap = ColorMap.loadVanillaColorMap(DEFAULT_FOLIAGECOLOR, SWAMPFOLIAGECOLOR);
  184. registerColorMap(colorMap, DEFAULT_FOLIAGECOLOR, "minecraft:leaves:0,4,8,12:variant=oak minecraft:vine");
  185. registerColorMap(PINECOLOR, "minecraft:leaves:1,5,9,13:variant=spruce");
  186. registerColorMap(BIRCHCOLOR, "minecraft:leaves:2,6,10,14:variant=birch");
  187. }
  188. private static IColorMap wrapBlockMap(IColorMap map) {
  189. if (map == null) {
  190. return null;
  191. } else {
  192. if (blockBlendRadius > 0) {
  193. map = new ColorMapBase.Blended(map, blockBlendRadius);
  194. }
  195. map = new ColorMapBase.Chunked(map);
  196. map = new ColorMapBase.Outer(map);
  197. return map;
  198. }
  199. }
  200. private static void reloadWaterColors(PropertiesFile properties) {
  201. waterColorMap = registerColorMap(WATERCOLOR, "minecraft:flowing_water minecraft:water");
  202. if (waterColorMap == null) {
  203. waterColorMap = new ColorMap.Water();
  204. registerColorMap(waterColorMap, null, "minecraft:flowing_water minecraft:water");
  205. }
  206. }
  207. private static void reloadSwampColors(PropertiesFile properties) {
  208. int[] lilypadColor = new int[]{0x020830};
  209. if (Colorizer.loadIntColor("lilypad", lilypadColor, 0)) {
  210. IColorMap colorMap = new ColorMap.Fixed(lilypadColor[0]);
  211. registerColorMap(colorMap, Colorizer.COLOR_PROPERTIES, "minecraft:waterlily");
  212. }
  213. }
  214. private static void reloadBlockColors(PropertiesFile properties) {
  215. for (Map.Entry<String, String> entry : properties.entrySet()) {
  216. String key = entry.getKey();
  217. String value = entry.getValue();
  218. if (!key.startsWith(PALETTE_BLOCK_KEY)) {
  219. continue;
  220. }
  221. key = key.substring(PALETTE_BLOCK_KEY.length()).trim();
  222. ResourceLocation resource = TexturePackAPI.parseResourceLocation(Colorizer.COLOR_PROPERTIES, key);
  223. if (resource == null) {
  224. continue;
  225. }
  226. registerColorMap(resource, value);
  227. }
  228. for (ResourceLocation resource : ResourceList.getInstance().listResources(ColorMap.BLOCK_COLORMAP_DIR, ".properties", false)) {
  229. Properties properties1 = TexturePackAPI.getProperties(resource);
  230. IColorMap colorMap = ColorMap.loadColorMap(true, resource, properties1);
  231. registerColorMap(colorMap, resource, MCPatcherUtils.getStringProperty(properties1, "blocks", getDefaultBlockName(resource)));
  232. }
  233. List<ResourceLocation> unusedPNGs = new ArrayList<ResourceLocation>(ColorMap.unusedPNGs);
  234. for (ResourceLocation resource : unusedPNGs) {
  235. Properties properties1 = new Properties();
  236. IColorMap colorMap = ColorMap.loadColorMap(true, resource, properties1);
  237. registerColorMap(colorMap, resource, getDefaultBlockName(resource));
  238. }
  239. }
  240. private static String getDefaultBlockName(ResourceLocation resource) {
  241. return resource.getNamespace() + ":" + resource.getPath().replaceFirst(".*/", "").replaceFirst("\\.[^.]*$", "");
  242. }
  243. private static IColorMap registerColorMap(ResourceLocation resource, String idList) {
  244. IColorMap colorMap = ColorMap.loadColorMap(true, resource, null);
  245. return registerColorMap(colorMap, resource, idList);
  246. }
  247. private static IColorMap registerColorMap(IColorMap colorMap, ResourceLocation resource, String idList) {
  248. if (colorMap == null) {
  249. return null;
  250. }
  251. colorMap = wrapBlockMap(colorMap);
  252. for (String idString : idList.split("\\s+")) {
  253. BlockStateMatcher blockMatcher = BlockAPI.createMatcher(new PropertiesFile(logger, resource), idString);
  254. if (blockMatcher != null) {
  255. List<BlockStateMatcher> maps = blockColorMaps.get(blockMatcher.getBlock());
  256. if (maps == null) {
  257. maps = new ArrayList<BlockStateMatcher>();
  258. blockColorMaps.put(blockMatcher.getBlock(), maps);
  259. }
  260. blockMatcher.setData(colorMap);
  261. maps.add(blockMatcher);
  262. if (resource != null) {
  263. logger.fine("using %s for block %s, default color %06x",
  264. colorMap, blockMatcher, colorMap.getColorMultiplier()
  265. );
  266. }
  267. }
  268. }
  269. return colorMap;
  270. }
  271. private static void reloadRedstoneColors(PropertiesFile properties) {
  272. int[] rgb = MCPatcherUtils.getImageRGB(TexturePackAPI.getImage(REDSTONE_COLORS));
  273. if (rgb != null && rgb.length >= 16) {
  274. redstoneColor = new float[16][];
  275. for (int i = 0; i < 16; i++) {
  276. float[] f = new float[3];
  277. ColorUtils.intToFloat3(rgb[i], f);
  278. redstoneColor[i] = f;
  279. }
  280. }
  281. }
  282. private static void reloadStemColors(PropertiesFile properties) {
  283. ResourceLocation resource = TexturePackAPI.hasResource(PUMPKIN_STEM_COLORS) ? PUMPKIN_STEM_COLORS : STEM_COLORS;
  284. registerMetadataRGB("minecraft:pumpkin_stem", resource, "age", 8);
  285. resource = TexturePackAPI.hasResource(MELON_STEM_COLORS) ? MELON_STEM_COLORS : STEM_COLORS;
  286. registerMetadataRGB("minecraft:melon_stem", resource, "age", 8);
  287. }
  288. private static void registerMetadataRGB(String blockName, ResourceLocation resource, String property, int length) {
  289. int[] rgb = MCPatcherUtils.getImageRGB(TexturePackAPI.getImage(resource));
  290. if (rgb == null || rgb.length < length) {
  291. return;
  292. }
  293. for (int i = 0; i < length; i++) {
  294. IColorMap colorMap = new ColorMap.Fixed(rgb[i] & 0xffffff);
  295. String idList = String.format("%s:%d,%d:%s=%d", blockName, i, (i + length) & 0xf, property, i);
  296. registerColorMap(colorMap, resource, idList);
  297. }
  298. }
  299. static List<BlockStateMatcher> findColorMaps(Block block) {
  300. return blockColorMaps.get(block);
  301. }
  302. static IColorMap getThreadLocal(BlockStateMatcher matcher) {
  303. IColorMap newMap = (IColorMap) matcher.getThreadData();
  304. if (newMap == null) {
  305. IColorMap oldMap = (IColorMap) matcher.getData();
  306. newMap = oldMap.copy();
  307. matcher.setThreadData(newMap);
  308. }
  309. return newMap;
  310. }
  311. private static IColorMap findColorMap(Block block, int metadata) {
  312. List<BlockStateMatcher> maps = findColorMaps(block);
  313. if (maps != null) {
  314. for (BlockStateMatcher matcher : maps) {
  315. if (matcher.match(block, metadata)) {
  316. return getThreadLocal(matcher);
  317. }
  318. }
  319. }
  320. return null;
  321. }
  322. private static IColorMap findColorMap(Block block, IBlockAccess blockAccess, int i, int j, int k) {
  323. List<BlockStateMatcher> maps = findColorMaps(block);
  324. if (maps != null) {
  325. for (BlockStateMatcher matcher : maps) {
  326. if (matcher.match(blockAccess, i, j, k)) {
  327. return getThreadLocal(matcher);
  328. }
  329. }
  330. }
  331. return null;
  332. }
  333. public static boolean colorizeBlock(Block block) {
  334. return colorizeBlock(block, 16);
  335. }
  336. public static boolean colorizeBlock(Block block, int metadata) {
  337. IColorMap colorMap = findColorMap(block, metadata);
  338. if (colorMap == null) {
  339. RenderBlocksUtils.setupColorMultiplier(block, metadata, false);
  340. return false;
  341. } else {
  342. RenderBlocksUtils.setupColorMultiplier(block, metadata, true);
  343. blockColor = colorMap.getColorMultiplier();
  344. return true;
  345. }
  346. }
  347. public static boolean colorizeBlock(Block block, IBlockAccess blockAccess, int i, int j, int k) {
  348. IColorMap colorMap = findColorMap(block, blockAccess, i, j, k);
  349. return colorizeBlock(block, blockAccess, colorMap, i, j, k);
  350. }
  351. private static boolean colorizeBlock(Block block, IBlockAccess blockAccess, IColorMap colorMap, int i, int j, int k) {
  352. if (colorMap == null) {
  353. return false;
  354. } else {
  355. blockColor = colorMap.getColorMultiplier(blockAccess, i, j, k);
  356. return true;
  357. }
  358. }
  359. public static void computeWaterColor() {
  360. if (waterColorMap != null) {
  361. Colorizer.setColorF(waterColorMap.getColorMultiplier());
  362. }
  363. }
  364. public static boolean computeWaterColor(boolean includeBaseColor, int i, int j, int k) {
  365. if (waterColorMap == null) {
  366. return false;
  367. } else {
  368. Colorizer.setColorF(waterColorMap.getColorMultiplierF(BiomeAPI.getWorld(), i, j, k));
  369. if (includeBaseColor) {
  370. Colorizer.setColor[0] *= ColorizeEntity.waterBaseColor[0];
  371. Colorizer.setColor[1] *= ColorizeEntity.waterBaseColor[1];
  372. Colorizer.setColor[2] *= ColorizeEntity.waterBaseColor[2];
  373. }
  374. return true;
  375. }
  376. }
  377. public static void colorizeWaterBlockGL(Block block) {
  378. if (block == waterBlock || block == staticWaterBlock) {
  379. float[] waterColor;
  380. if (waterColorMap == null) {
  381. waterColor = ColorizeEntity.waterBaseColor;
  382. } else {
  383. waterColor = new float[3];
  384. ColorUtils.intToFloat3(waterColorMap.getColorMultiplier(), waterColor);
  385. }
  386. GLAPI.glColor4f(waterColor[0], waterColor[1], waterColor[2], 1.0f);
  387. }
  388. }
  389. public static boolean computeRedstoneWireColor(int current) {
  390. if (redstoneColor == null) {
  391. return false;
  392. } else {
  393. System.arraycopy(redstoneColor[current & 0xf], 0, Colorizer.setColor, 0, 3);
  394. return true;
  395. }
  396. }
  397. public static int colorizeRedstoneWire(IBlockAccess blockAccess, int i, int j, int k, int defaultColor) {
  398. if (redstoneColor == null) {
  399. return defaultColor;
  400. } else {
  401. int metadata = Math.max(Math.min(BlockAPI.getMetadataAt(blockAccess, i, j, k), 15), 0);
  402. return ColorUtils.float3ToInt(redstoneColor[metadata]);
  403. }
  404. }
  405. private static float[] getVertexColor(IBlockAccess blockAccess, IColorMap colorMap, int i, int j, int k, int[] offsets) {
  406. if (enableTestColorSmoothing) {
  407. int rgb = 0;
  408. if ((i + offsets[0]) % 2 == 0) {
  409. rgb |= 0xff0000;
  410. }
  411. if ((j + offsets[1]) % 2 == 0) {
  412. rgb |= 0x00ff00;
  413. }
  414. if ((k + offsets[2]) % 2 == 0) {
  415. rgb |= 0x0000ff;
  416. }
  417. ColorUtils.intToFloat3(rgb, Colorizer.setColor);
  418. return Colorizer.setColor;
  419. } else {
  420. return colorMap.getColorMultiplierF(blockAccess, i + offsets[0], j + offsets[1], k + offsets[2]);
  421. }
  422. }
  423. public static boolean setupBlockSmoothing(RenderBlocks renderBlocks, Block block, IBlockAccess blockAccess,
  424. int i, int j, int k, int face,
  425. float topLeft, float bottomLeft, float bottomRight, float topRight) {
  426. return RenderBlocksUtils.useColorMultiplier(face) &&
  427. setupBiomeSmoothing(renderBlocks, block, blockAccess, i, j, k, face, true, topLeft, bottomLeft, bottomRight, topRight);
  428. }
  429. // TODO: remove
  430. @Deprecated
  431. public static boolean setupBlockSmoothingGrassSide(RenderBlocks renderBlocks, Block block, IBlockAccess blockAccess,
  432. int i, int j, int k, int face,
  433. float topLeft, float bottomLeft, float bottomRight, float topRight) {
  434. return checkBiomeSmoothing(block, face) &&
  435. setupBiomeSmoothing(renderBlocks, block, blockAccess, i, j, k, face, true, topLeft, bottomLeft, bottomRight, topRight);
  436. }
  437. public static boolean setupBlockSmoothing(RenderBlocks renderBlocks, Block block, IBlockAccess blockAccess,
  438. int i, int j, int k, int face) {
  439. return checkBiomeSmoothing(block, face) &&
  440. setupBiomeSmoothing(renderBlocks, block, blockAccess, i, j, k, face, true, 1.0f, 1.0f, 1.0f, 1.0f);
  441. }
  442. private static boolean checkBiomeSmoothing(Block block, int face) {
  443. return enableSmoothBiomes && face >= 0 && RenderBlocksUtils.isAmbientOcclusionEnabled() && BlockAPI.getBlockLightValue(block) == 0;
  444. }
  445. private static boolean setupBiomeSmoothing(RenderBlocks renderBlocks, Block block, IBlockAccess blockAccess,
  446. int i, int j, int k, int face,
  447. boolean useAO, float topLeft, float bottomLeft, float bottomRight, float topRight) {
  448. if (!setupBlockSmoothing(block, blockAccess, i, j, k, face)) {
  449. return false;
  450. }
  451. if (useAO) {
  452. float aoBase = RenderBlocksUtils.AO_BASE[face % 6];
  453. topLeft *= aoBase;
  454. bottomLeft *= aoBase;
  455. bottomRight *= aoBase;
  456. topRight *= aoBase;
  457. }
  458. renderBlocks.colorRedTopLeft = topLeft * colorRedTopLeft;
  459. renderBlocks.colorGreenTopLeft = topLeft * colorGreenTopLeft;
  460. renderBlocks.colorBlueTopLeft = topLeft * colorBlueTopLeft;
  461. renderBlocks.colorRedBottomLeft = bottomLeft * colorRedBottomLeft;
  462. renderBlocks.colorGreenBottomLeft = bottomLeft * colorGreenBottomLeft;
  463. renderBlocks.colorBlueBottomLeft = bottomLeft * colorBlueBottomLeft;
  464. renderBlocks.colorRedBottomRight = bottomRight * colorRedBottomRight;
  465. renderBlocks.colorGreenBottomRight = bottomRight * colorGreenBottomRight;
  466. renderBlocks.colorBlueBottomRight = bottomRight * colorBlueBottomRight;
  467. renderBlocks.colorRedTopRight = topRight * colorRedTopRight;
  468. renderBlocks.colorGreenTopRight = topRight * colorGreenTopRight;
  469. renderBlocks.colorBlueTopRight = topRight * colorBlueTopRight;
  470. return true;
  471. }
  472. public static void setupBlockSmoothing(Block block, IBlockAccess blockAccess, int i, int j, int k, int face,
  473. float r, float g, float b) {
  474. if (!setupBlockSmoothing(block, blockAccess, i, j, k, face)) {
  475. setVertexColors(r, g, b);
  476. }
  477. }
  478. private static boolean setupBlockSmoothing(Block block, IBlockAccess blockAccess, int i, int j, int k, int face) {
  479. if (!checkBiomeSmoothing(block, face)) {
  480. return false;
  481. }
  482. IColorMap colorMap = findColorMap(block, blockAccess, i, j, k);
  483. if (colorMap == null) {
  484. return false;
  485. }
  486. int[][] offsets = FACE_VERTICES[face];
  487. float[] color;
  488. color = getVertexColor(blockAccess, colorMap, i, j, k, offsets[0]);
  489. colorRedTopLeft = color[0];
  490. colorGreenTopLeft = color[1];
  491. colorBlueTopLeft = color[2];
  492. color = getVertexColor(blockAccess, colorMap, i, j, k, offsets[1]);
  493. colorRedBottomLeft = color[0];
  494. colorGreenBottomLeft = color[1];
  495. colorBlueBottomLeft = color[2];
  496. color = getVertexColor(blockAccess, colorMap, i, j, k, offsets[2]);
  497. colorRedBottomRight = color[0];
  498. colorGreenBottomRight = color[1];
  499. colorBlueBottomRight = color[2];
  500. color = getVertexColor(blockAccess, colorMap, i, j, k, offsets[3]);
  501. colorRedTopRight = color[0];
  502. colorGreenTopRight = color[1];
  503. colorBlueTopRight = color[2];
  504. return true;
  505. }
  506. private static void resetVertexColors() {
  507. setVertexColors(1.0f, 1.0f, 1.0f);
  508. }
  509. private static void setVertexColors(float r, float g, float b) {
  510. colorRedTopLeft = colorRedBottomLeft = colorRedBottomRight = colorRedTopRight = r;
  511. colorGreenTopLeft = colorGreenBottomLeft = colorGreenBottomRight = colorGreenTopRight = g;
  512. colorBlueTopLeft = colorBlueBottomLeft = colorBlueBottomRight = colorBlueTopRight = b;
  513. }
  514. }