From d4f080bd9660cad4272e4afab15a5bd876ad4106 Mon Sep 17 00:00:00 2001 From: GizmoTheMoonPig <67468252+GizmoTheMoonPig@users.noreply.github.com> Date: Thu, 26 Dec 2024 12:52:53 -0700 Subject: [PATCH] fix #2273 --- .../client/event/ColorHandler.java | 215 +++--------------- 1 file changed, 33 insertions(+), 182 deletions(-) diff --git a/src/main/java/twilightforest/client/event/ColorHandler.java b/src/main/java/twilightforest/client/event/ColorHandler.java index 85c267dd1a..840b6c5ce2 100644 --- a/src/main/java/twilightforest/client/event/ColorHandler.java +++ b/src/main/java/twilightforest/client/event/ColorHandler.java @@ -23,16 +23,17 @@ import twilightforest.util.ColorUtil; import twilightforest.util.SimplexNoiseHelper; +import java.util.function.Function; + public class ColorHandler { - public static final int WHITE = 0xFFFFFFFF; + public static final Function CANOPY_COLORIZER = color -> 0xFF000000 | (((color & 0xFEFEFE) + 0x469A66) / 2); + public static final Function MANGROVE_COLORIZER = color -> 0xFF000000 | (((color & 0xFEFEFE) + 0xC0E694) / 2); protected static void registerBlockColors(RegisterColorHandlersEvent.Block event) { BlockColors blockColors = event.getBlockColors(); - event.register((state, getter, pos, tintIndex) -> tintIndex > 15 ? WHITE : 0xFF000000 | ColorUtil.hsvToRGB(getter == null ? 0.45F : SimplexNoiseHelper.rippleFractalNoise(2, 128.0f, pos != null ? pos.above(128) : new BlockPos(0, 0, 0), 0.37f, 0.67f, 1.5f), 1.0f, 1.0f), TFBlocks.AURORA_BLOCK.get()); + event.register((state, getter, pos, tintIndex) -> 0xFF000000 | ColorUtil.hsvToRGB(getter == null ? 0.45F : SimplexNoiseHelper.rippleFractalNoise(2, 128.0f, pos != null ? pos.above(128) : new BlockPos(0, 0, 0), 0.37f, 0.67f, 1.5f), 1.0f, 1.0f), TFBlocks.AURORA_BLOCK.get()); event.register((state, getter, pos, tintIndex) -> { - if (tintIndex > 15) return WHITE; - int normalColor = blockColors.getColor(TFBlocks.AURORA_BLOCK.get().defaultBlockState(), getter, pos, tintIndex); int red = (normalColor >> 16) & 255; @@ -43,33 +44,9 @@ protected static void registerBlockColors(RegisterColorHandlersEvent.Block event return 0xFF000000 | ColorUtil.hsvToRGB(hsb[0], hsb[1] * 0.5F, Math.min(hsb[2] + 0.4F, 0.9F)); }, TFBlocks.AURORA_PILLAR.get(), TFBlocks.AURORA_SLAB.get(), TFBlocks.AURORALIZED_GLASS.get()); - event.register((state, getter, pos, tintIndex) -> { - if (tintIndex > 15) return WHITE; - - if (getter == null || pos == null) { - return FoliageColor.getDefaultColor(); - } - - int red = 0; - int grn = 0; - int blu = 0; - - for (int dz = -1; dz <= 1; ++dz) { - for (int dx = -1; dx <= 1; ++dx) { - int i2 = BiomeColors.getAverageFoliageColor(getter, pos.offset(dx, 0, dz)); - red += (i2 & 16711680) >> 16; - grn += (i2 & 65280) >> 8; - blu += i2 & 255; - } - } - - return 0xFF000000 | (red / 9 & 255) << 16 | (grn / 9 & 255) << 8 | blu / 9 & 255; - }, TFBlocks.DARK_LEAVES.get(), TFBlocks.HARDENED_DARK_LEAVES.get(), TFBlocks.GIANT_LEAVES.get()); - event.register((state, getter, pos, tintIndex) -> tintIndex > 15 ? WHITE : blockColors.getColor(Blocks.SHORT_GRASS.defaultBlockState(), getter, pos, tintIndex), TFBlocks.SMOKER.get(), TFBlocks.FIRE_JET.get()); + event.register((state, getter, pos, tintIndex) -> blockColors.getColor(Blocks.SHORT_GRASS.defaultBlockState(), getter, pos, tintIndex), TFBlocks.SMOKER.get(), TFBlocks.FIRE_JET.get()); event.register((state, getter, pos, tintIndex) -> getter != null && pos != null ? 0xFF000000 | 2129968 : 0xFF000000 | 7455580, TFBlocks.HUGE_LILY_PAD.get()); event.register((state, getter, pos, tintIndex) -> { - if (tintIndex > 15) return WHITE; - if (getter == null || pos == null) { return 0xFF000000 | 106 << 16 | 156 << 8 | 23; } else { @@ -92,8 +69,6 @@ protected static void registerBlockColors(RegisterColorHandlersEvent.Block event } }, TFBlocks.TIME_LEAVES.get()); event.register((state, getter, pos, tintIndex) -> { - if (tintIndex > 15) return WHITE; - if (getter == null || pos == null) { return 0xFF000000 | 108 << 16 | 204 << 8 | 234; } else { @@ -116,8 +91,6 @@ protected static void registerBlockColors(RegisterColorHandlersEvent.Block event } }, TFBlocks.TRANSFORMATION_LEAVES.get()); event.register((state, getter, pos, tintIndex) -> { - if (tintIndex > 15) return WHITE; - if (getter == null || pos == null) { return 0xFF000000 | 252 << 16 | 241 << 8 | 68; } else { @@ -140,8 +113,6 @@ protected static void registerBlockColors(RegisterColorHandlersEvent.Block event } }, TFBlocks.MINING_LEAVES.get()); event.register((state, getter, pos, tintIndex) -> { - if (tintIndex > 15) return WHITE; - if (getter == null || pos == null) { return 0xFF000000 | 54 << 16 | 76 << 8 | 3; } else { @@ -160,167 +131,62 @@ protected static void registerBlockColors(RegisterColorHandlersEvent.Block event green = (int) (spring * 76 + fall * 199); blue = (int) (spring * 3 + fall * 43); - return 0xFF000000 | red << 16 | green << 8 | blue; + return 0xFF000000 | red << 16 | green << 8 | blue; } }, TFBlocks.SORTING_LEAVES.get()); event.register((state, getter, pos, tintIndex) -> { - if (tintIndex > 15) return WHITE; - if (getter == null || pos == null) { return -1; } else { float f = SimplexNoiseHelper.rippleFractalNoise(2, 32.0f, pos, 0.4f, 1.0f, 2f); - return 0xFF000000 | ColorUtil.hsvToRGB(0.1f, 1f - f, (f + 2f) / 3f); + return 0xFF000000 | ColorUtil.hsvToRGB(0.1f, 1f - f, (f + 2f) / 3f); } }, TFBlocks.TOWERWOOD.get(), TFBlocks.CRACKED_TOWERWOOD.get(), TFBlocks.INFESTED_TOWERWOOD.get(), TFBlocks.MOSSY_TOWERWOOD.get()); - event.register((state, world, pos, tintIndex) -> { - if (tintIndex > 15) return WHITE; - - if (world == null || pos == null) { - return 0xFF48B518; - } else { - int red = 0; - int green = 0; - int blue = 0; - - for (int dz = -1; dz <= 1; ++dz) { - for (int dx = -1; dx <= 1; ++dx) { - int color = BiomeColors.getAverageFoliageColor(world, pos); - red += (color & 16711680) >> 16; - green += (color & 65280) >> 8; - blue += color & 255; - } - } - - return 0xFF000000 | ((red / 9 & 0xFF) << 16 | (green / 9 & 0xFF) << 8 | blue / 9 & 0xFF); - } - }, TFBlocks.TWILIGHT_OAK_LEAVES.get()); - event.register((state, world, pos, tintIndex) -> { - if (tintIndex > 15) return WHITE; - - if (world == null || pos == null) { - return 0xFF609860; - } else { - int red = 0; - int green = 0; - int blue = 0; - - for (int dz = -1; dz <= 1; ++dz) { - for (int dx = -1; dx <= 1; ++dx) { - int color = BiomeColors.getAverageFoliageColor(world, pos); - red += (color & 16711680) >> 16; - green += (color & 65280) >> 8; - blue += color & 255; - } - } - - int normalColor = (red / 9 & 0xFF) << 16 | (green / 9 & 0xFF) << 8 | blue / 9 & 0xFF; - // canopy colorizer - return 0xFF000000 | (((normalColor & 0xFEFEFE) + 0x469A66) / 2); - } - }, TFBlocks.CANOPY_LEAVES.get()); - event.register((state, world, pos, tintIndex) -> { - if (tintIndex > 15) return WHITE; - - if (world == null || pos == null) { - return 0xFF80A755; - } else { - int red = 0; - int green = 0; - int blue = 0; - - for (int dz = -1; dz <= 1; ++dz) { - for (int dx = -1; dx <= 1; ++dx) { - int color = BiomeColors.getAverageFoliageColor(world, pos); - red += (color & 16711680) >> 16; - green += (color & 65280) >> 8; - blue += color & 255; - } - } - - int normalColor = (red / 9 & 0xFF) << 16 | (green / 9 & 0xFF) << 8 | blue / 9 & 0xFF; - // mangrove colors - return 0xFF000000 | (((normalColor & 0xFEFEFE) + 0xC0E694) / 2); - } - }, TFBlocks.MANGROVE_LEAVES.get()); + event.register((state, getter, pos, tintIndex) -> getter != null && pos != null ? BiomeColors.getAverageFoliageColor(getter, pos) : FoliageColor.getDefaultColor(), TFBlocks.TWILIGHT_OAK_LEAVES.get(), TFBlocks.DARK_LEAVES.get(), TFBlocks.HARDENED_DARK_LEAVES.get(), TFBlocks.GIANT_LEAVES.get(), TFBlocks.FALLEN_LEAVES.get()); + event.register((state, getter, pos, tintIndex) -> getter != null && pos != null ? CANOPY_COLORIZER.apply(BiomeColors.getAverageFoliageColor(getter, pos)) : FoliageColor.getEvergreenColor(), TFBlocks.CANOPY_LEAVES.get()); + event.register((state, getter, pos, tintIndex) -> getter != null && pos != null ? MANGROVE_COLORIZER.apply(BiomeColors.getAverageFoliageColor(getter, pos)) : FoliageColor.getBirchColor(), TFBlocks.MANGROVE_LEAVES.get()); event.register((state, getter, pos, tintIndex) -> { - if (tintIndex > 15) return WHITE; - if (getter == null || pos == null) { - return 0xFF48B518; + return FoliageColor.getDefaultColor(); } else { - int red = 0; - int green = 0; - int blue = 0; - - for (int dz = -1; dz <= 1; ++dz) { - for (int dx = -1; dx <= 1; ++dx) { - int color = BiomeColors.getAverageFoliageColor(getter, pos); - red += (color & 0xFF0000) >> 16; - green += (color & 0xFF00) >> 8; - blue += color & 0xFF; - } - } - // RAINBOW! - red = pos.getX() * 32 + pos.getY() * 16; + int red = pos.getX() * 32 + pos.getY() * 16; if ((red & 256) != 0) { red = 255 - (red & 255); } red &= 255; - green = pos.getY() * 32 + pos.getZ() * 16; + int green = pos.getY() * 32 + pos.getZ() * 16; if ((green & 256) != 0) { green = 255 - (green & 255); } green ^= 255; - blue = pos.getX() * 16 + pos.getZ() * 32; + int blue = pos.getX() * 16 + pos.getZ() * 32; if ((blue & 256) != 0) { blue = 255 - (blue & 255); } blue &= 255; - return 0xFF000000 | red << 16 | green << 8 | blue; + return 0xFF000000 | red << 16 | green << 8 | blue; } }, TFBlocks.RAINBOW_OAK_LEAVES.get()); event.register((state, getter, pos, tintIndex) -> FoliageColor.getEvergreenColor(), TFBlocks.BEANSTALK_LEAVES.get(), TFBlocks.THORN_LEAVES.get()); event.register((state, getter, pos, tintIndex) -> { if (tintIndex != 0) { - return WHITE; + return getter != null && pos != null ? BiomeColors.getAverageGrassColor(getter, pos) : GrassColor.getDefaultColor(); } else { - if (getter != null && pos != null) { - return BiomeColors.getAverageFoliageColor(getter, pos); - } else { - return FoliageColor.getDefaultColor(); - } - } - }, TFBlocks.FALLEN_LEAVES.get()); - event.register((state, getter, pos, tintIndex) -> { - if ((tintIndex & 1) == 1) { - return WHITE; - } else { - if (getter != null && pos != null) { - return BiomeColors.getAverageGrassColor(getter, pos); - } else { - return GrassColor.get(0.5D, 1.0D); - } + return -1; } - }, TFBlocks.FIDDLEHEAD.get(), TFBlocks.POTTED_FIDDLEHEAD.get()); - event.register((state, getter, pos, tintIndex) -> { - if ((tintIndex & 1) == 0) { - return WHITE; - } else { - return GrassColor.get(0.5D, 1.0D); - } - }, TFBlocks.HOLLOW_OAK_LOG_HORIZONTAL.get(), TFBlocks.HOLLOW_SPRUCE_LOG_HORIZONTAL.get(), TFBlocks.HOLLOW_BIRCH_LOG_HORIZONTAL.get(), TFBlocks.HOLLOW_JUNGLE_LOG_HORIZONTAL.get(), + }, TFBlocks.FIDDLEHEAD.get(), TFBlocks.POTTED_FIDDLEHEAD.get(), + TFBlocks.HOLLOW_OAK_LOG_HORIZONTAL.get(), TFBlocks.HOLLOW_SPRUCE_LOG_HORIZONTAL.get(), TFBlocks.HOLLOW_BIRCH_LOG_HORIZONTAL.get(), TFBlocks.HOLLOW_JUNGLE_LOG_HORIZONTAL.get(), TFBlocks.HOLLOW_ACACIA_LOG_HORIZONTAL.get(), TFBlocks.HOLLOW_DARK_OAK_LOG_HORIZONTAL.get(), TFBlocks.HOLLOW_CRIMSON_STEM_HORIZONTAL.get(), TFBlocks.HOLLOW_WARPED_STEM_HORIZONTAL.get(), TFBlocks.HOLLOW_VANGROVE_LOG_HORIZONTAL.get(), TFBlocks.HOLLOW_CHERRY_LOG_HORIZONTAL.get(), TFBlocks.HOLLOW_TWILIGHT_OAK_LOG_HORIZONTAL.get(), TFBlocks.HOLLOW_CANOPY_LOG_HORIZONTAL.get(), TFBlocks.HOLLOW_MANGROVE_LOG_HORIZONTAL.get(), TFBlocks.HOLLOW_DARK_LOG_HORIZONTAL.get(), TFBlocks.HOLLOW_TIME_LOG_HORIZONTAL.get(), TFBlocks.HOLLOW_TRANSFORMATION_LOG_HORIZONTAL.get(), TFBlocks.HOLLOW_MINING_LOG_HORIZONTAL.get(), TFBlocks.HOLLOW_SORTING_LOG_HORIZONTAL.get()); event.register((state, getter, pos, tintIndex) -> { - if (state.getValue(ClimbableHollowLogBlock.VARIANT) != HollowLogVariants.Climbable.VINE || (tintIndex & 1) == 0) { - return WHITE; + if (state.getValue(ClimbableHollowLogBlock.VARIANT) != HollowLogVariants.Climbable.VINE || tintIndex != 0) { + return -1; } else { if (getter != null && pos != null) { return BiomeColors.getAverageFoliageColor(getter, pos); @@ -332,39 +198,24 @@ protected static void registerBlockColors(RegisterColorHandlersEvent.Block event TFBlocks.HOLLOW_ACACIA_LOG_CLIMBABLE.get(), TFBlocks.HOLLOW_DARK_OAK_LOG_CLIMBABLE.get(), TFBlocks.HOLLOW_CRIMSON_STEM_CLIMBABLE.get(), TFBlocks.HOLLOW_WARPED_STEM_CLIMBABLE.get(), TFBlocks.HOLLOW_VANGROVE_LOG_CLIMBABLE.get(), TFBlocks.HOLLOW_TWILIGHT_OAK_LOG_CLIMBABLE.get(), TFBlocks.HOLLOW_CANOPY_LOG_CLIMBABLE.get(), TFBlocks.HOLLOW_MANGROVE_LOG_CLIMBABLE.get(), TFBlocks.HOLLOW_DARK_LOG_CLIMBABLE.get(), TFBlocks.HOLLOW_TIME_LOG_CLIMBABLE.get(), TFBlocks.HOLLOW_TRANSFORMATION_LOG_CLIMBABLE.get(), TFBlocks.HOLLOW_MINING_LOG_CLIMBABLE.get(), TFBlocks.HOLLOW_SORTING_LOG_CLIMBABLE.get()); - event.register((state, getter, pos, tintIndex) -> GrassColor.get(0.5D, 1.0D), + event.register((state, getter, pos, tintIndex) -> GrassColor.getDefaultColor(), TFBlocks.TWILIGHT_PORTAL_MINIATURE_STRUCTURE.get(), /*TFBlocks.HEDGE_MAZE_MINIATURE_STRUCTURE.get(), TFBlocks.HOLLOW_HILL_MINIATURE_STRUCTURE.get(), TFBlocks.QUEST_GROVE_MINIATURE_STRUCTURE.get(), TFBlocks.MUSHROOM_TOWER_MINIATURE_STRUCTURE.get(),*/ TFBlocks.NAGA_COURTYARD_MINIATURE_STRUCTURE.get(), TFBlocks.LICH_TOWER_MINIATURE_STRUCTURE.get() //TFBlocks.MINOTAUR_LABYRINTH_MINIATURE_STRUCTURE.get(), /*TFBlocks.HYDRA_LAIR_MINIATURE_STRUCTURE.get(), TFBlocks.GOBLIN_STRONGHOLD_MINIATURE_STRUCTURE.get(), TFBlocks.DARK_TOWER_MINIATURE_STRUCTURE.get(), TFBlocks.YETI_CAVE_MINIATURE_STRUCTURE.get(), TFBlocks.AURORA_PALACE_MINIATURE_STRUCTURE.get(), TFBlocks.TROLL_CAVE_COTTAGE_MINIATURE_STRUCTURE.get(), TFBlocks.FINAL_CASTLE_MINIATURE_STRUCTURE.get()*/); - event.register((state, getter, pos, tintIndex) -> tintIndex > 15 ? WHITE : 0xFFFF00FF, TFBlocks.PINK_CASTLE_RUNE_BRICK.get(), TFBlocks.PINK_CASTLE_DOOR.get()); - event.register((state, getter, pos, tintIndex) -> tintIndex > 15 ? WHITE : 0xFF00FFFF, TFBlocks.BLUE_CASTLE_RUNE_BRICK.get(), TFBlocks.BLUE_CASTLE_DOOR.get()); - event.register((state, getter, pos, tintIndex) -> tintIndex > 15 ? WHITE : 0xFFFFFF00, TFBlocks.YELLOW_CASTLE_RUNE_BRICK.get(), TFBlocks.YELLOW_CASTLE_DOOR.get()); - event.register((state, getter, pos, tintIndex) -> tintIndex > 15 ? WHITE : 0xFF4B0082, TFBlocks.VIOLET_CASTLE_RUNE_BRICK.get(), TFBlocks.VIOLET_CASTLE_DOOR.get()); - event.register((state, getter, pos, tintIndex) -> { - if (tintIndex > 15) return WHITE; - return 0xFF5C1074; - }, TFBlocks.VIOLET_FORCE_FIELD.get()); - event.register((state, getter, pos, tintIndex) -> { - if (tintIndex > 15) return WHITE; - return 0xFFFA057E; - }, TFBlocks.PINK_FORCE_FIELD.get()); - event.register((state, getter, pos, tintIndex) -> { - if (tintIndex > 15) return WHITE; - return 0xFFFF5B02; - }, TFBlocks.ORANGE_FORCE_FIELD.get()); - event.register((state, getter, pos, tintIndex) -> { - if (tintIndex > 15) return WHITE; - return 0xFF89E701; - }, TFBlocks.GREEN_FORCE_FIELD.get()); - event.register((state, getter, pos, tintIndex) -> { - if (tintIndex > 15) return WHITE; - return 0xFF0DDEFF; - }, TFBlocks.BLUE_FORCE_FIELD.get()); + event.register((state, getter, pos, tintIndex) -> 0xFFFF00FF, TFBlocks.PINK_CASTLE_RUNE_BRICK.get(), TFBlocks.PINK_CASTLE_DOOR.get()); + event.register((state, getter, pos, tintIndex) -> 0xFF00FFFF, TFBlocks.BLUE_CASTLE_RUNE_BRICK.get(), TFBlocks.BLUE_CASTLE_DOOR.get()); + event.register((state, getter, pos, tintIndex) -> 0xFFFFFF00, TFBlocks.YELLOW_CASTLE_RUNE_BRICK.get(), TFBlocks.YELLOW_CASTLE_DOOR.get()); + event.register((state, getter, pos, tintIndex) -> 0xFF4B0082, TFBlocks.VIOLET_CASTLE_RUNE_BRICK.get(), TFBlocks.VIOLET_CASTLE_DOOR.get()); + event.register((state, getter, pos, tintIndex) -> 0xFF5C1074, TFBlocks.VIOLET_FORCE_FIELD.get()); + event.register((state, getter, pos, tintIndex) -> 0xFFFA057E, TFBlocks.PINK_FORCE_FIELD.get()); + event.register((state, getter, pos, tintIndex) -> 0xFFFF5B02, TFBlocks.ORANGE_FORCE_FIELD.get()); + event.register((state, getter, pos, tintIndex) -> 0xFF89E701, TFBlocks.GREEN_FORCE_FIELD.get()); + event.register((state, getter, pos, tintIndex) -> 0xFF0DDEFF, TFBlocks.BLUE_FORCE_FIELD.get()); } protected static void registerItemColors(RegisterColorHandlersEvent.Item event) { BlockColors blockColors = event.getBlockColors(); - event.register((stack, tintIndex) -> stack.getItem() instanceof BlockItem blocc ? blockColors.getColor(blocc.getBlock().defaultBlockState(), null, null, tintIndex) : WHITE, + event.register((stack, tintIndex) -> stack.getItem() instanceof BlockItem blocc ? blockColors.getColor(blocc.getBlock().defaultBlockState(), null, null, tintIndex) : -1, TFBlocks.AURORA_BLOCK.get(), TFBlocks.AURORA_PILLAR.get(), TFBlocks.AURORA_SLAB.get(), TFBlocks.AURORALIZED_GLASS.get(), TFBlocks.DARK_LEAVES.get(), TFBlocks.GIANT_LEAVES.get(), TFBlocks.SMOKER.get(), TFBlocks.FIRE_JET.get(), TFBlocks.TIME_LEAVES.get(), TFBlocks.TRANSFORMATION_LEAVES.get(), TFBlocks.MINING_LEAVES.get(), TFBlocks.SORTING_LEAVES.get(), TFBlocks.TWILIGHT_OAK_LEAVES.get(), TFBlocks.CANOPY_LEAVES.get(), TFBlocks.MANGROVE_LEAVES.get(), TFBlocks.RAINBOW_OAK_LEAVES.get(), TFBlocks.THORN_LEAVES.get(), TFBlocks.BEANSTALK_LEAVES.get(), TFBlocks.FALLEN_LEAVES.get(), TFBlocks.FIDDLEHEAD.get(), TFBlocks.POTTED_FIDDLEHEAD.get(), TFBlocks.PINK_CASTLE_RUNE_BRICK.get(), TFBlocks.BLUE_CASTLE_RUNE_BRICK.get(), TFBlocks.YELLOW_CASTLE_RUNE_BRICK.get(), TFBlocks.VIOLET_CASTLE_RUNE_BRICK.get(),