jayhillx

[dreamlands] client block tints

Apr 16th, 2026
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.43 KB | None | 0 0
  1. package com.dreamlands.init;
  2.  
  3. import com.dreamlands.Dreamlands;
  4. import com.dreamlands.client.renderer.DreamBiomeColors;
  5. import net.minecraft.client.renderer.BiomeColors;
  6. import net.minecraft.core.BlockPos;
  7. import net.minecraft.world.level.BlockAndTintGetter;
  8. import net.minecraft.world.level.FoliageColor;
  9. import net.minecraft.world.level.GrassColor;
  10. import net.neoforged.api.distmarker.Dist;
  11. import net.neoforged.bus.api.SubscribeEvent;
  12. import net.neoforged.fml.common.EventBusSubscriber;
  13. import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent;
  14.  
  15. @EventBusSubscriber(modid = Dreamlands.modId, value = Dist.CLIENT)
  16. public class DreamClient {
  17.  
  18.     @SubscribeEvent
  19.     public static void registerBlockColors(RegisterColorHandlersEvent.Block event) {
  20.         event.register((state, level, pos, tintIndex) -> {
  21.             if (tintIndex == 0) return getGrassColor(level, pos);
  22.             if (tintIndex == 1) return DreamBiomeColors.getDefaultDirtColor();
  23.             return -1;
  24.             }, DreamBlocks.DREAMY_GRASS_BLOCK.get()
  25.         );
  26.  
  27.         event.register((state, level, pos, tintIndex) -> tintIndex == 1 ? DreamBiomeColors.getDefaultDirtColor() : -1,
  28.                 DreamBlocks.DREAMY_DIRT.get(),
  29.                 DreamBlocks.DREAMY_DIRT_PATH.get()
  30.         );
  31.  
  32.         event.register((state, level, pos, tintIndex) -> getFoliageColor(level, pos),
  33.                 DreamBlocks.DREAMY_GRASS.get(),
  34.                 DreamBlocks.TALL_DREAMY_GRASS.get(),
  35.                 DreamBlocks.DREAMY_FERN.get(),
  36.                 DreamBlocks.TALL_DREAMY_FERN.get(),
  37.                 DreamBlocks.FOREST_GRASS.get(),
  38.                 DreamBlocks.TALL_FOREST_GRASS.get()
  39.         );
  40.     }
  41.  
  42.     private static int getFoliageColor(BlockAndTintGetter level, BlockPos pos) {
  43.         return level != null && pos != null
  44.                 ? BiomeColors.getAverageFoliageColor(level, pos)
  45.                 : FoliageColor.getDefaultColor();
  46.     }
  47.  
  48.     private static int getGrassColor(BlockAndTintGetter level, BlockPos pos) {
  49.         return level != null && pos != null
  50.                 ? BiomeColors.getAverageGrassColor(level, pos)
  51.                 : GrassColor.getDefaultColor();
  52.     }
  53.  
  54.     private static int getDirtColor(BlockAndTintGetter level, BlockPos pos) {
  55.         return level != null && pos != null
  56.                 ? level.getBlockTint(pos, DreamBiomeColors.DIRT_COLOR_RESOLVER)
  57.                 : DreamBiomeColors.getDefaultDirtColor();
  58.     }
  59.  
  60.     @SubscribeEvent
  61.     public static void registerItemColors(RegisterColorHandlersEvent.Item event) {
  62.         event.register((stack, tintIndex) -> {
  63.             if (tintIndex == 0) return DreamBiomeColors.getDefaultGrassColor();
  64.             if (tintIndex == 1) return DreamBiomeColors.getDefaultDirtColor();
  65.             return -1;
  66.             }, DreamBlocks.DREAMY_GRASS_BLOCK.get());
  67.  
  68.         event.register((stack, tintIndex) -> DreamBiomeColors.getDefaultDirtColor(),
  69.                 DreamBlocks.DREAMY_DIRT.get(),
  70.                 DreamBlocks.DREAMY_DIRT_PATH.get()
  71.         );
  72.  
  73.         event.register((stack, tintIndex) -> DreamBiomeColors.getDefaultGrassColor(),
  74.                 DreamBlocks.DREAMY_GRASS.get(),
  75.                 DreamBlocks.TALL_DREAMY_GRASS.get(),
  76.                 DreamBlocks.DREAMY_FERN.get(),
  77.                 DreamBlocks.TALL_DREAMY_FERN.get(),
  78.                 DreamBlocks.FOREST_GRASS.get(),
  79.                 DreamBlocks.TALL_FOREST_GRASS.get()
  80.         );
  81.     }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment