package de.ellpeck.naturesaura.misc; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.DyeColor; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import java.util.Arrays; import java.util.Comparator; import java.util.List; public final class ColoredBlockHelper { public static final List WOOL = ColoredBlockHelper.collectBlocks("wool"); public static final List TERRACOTTA = ColoredBlockHelper.collectBlocks("terracotta"); public static final List CONCRETE_POWDER = ColoredBlockHelper.collectBlocks("concrete_powder"); public static final List CONCRETE = ColoredBlockHelper.collectBlocks("concrete"); public static final List GLASS = ColoredBlockHelper.collectBlocks("stained_glass"); public static final List GLASS_PANE = ColoredBlockHelper.collectBlocks("stained_glass_pane"); public static final List CARPET = ColoredBlockHelper.collectBlocks("carpet"); public static final List> LISTS = Arrays.asList(ColoredBlockHelper.WOOL, ColoredBlockHelper.TERRACOTTA, ColoredBlockHelper.CONCRETE_POWDER, ColoredBlockHelper.CONCRETE, ColoredBlockHelper.GLASS, ColoredBlockHelper.GLASS_PANE, ColoredBlockHelper.CARPET); private static List collectBlocks(String name) { return Arrays.stream(DyeColor.values()).sorted(Comparator.comparingInt(DyeColor::getId)).map(c -> { var loc = new ResourceLocation(c.getName() + '_' + name); var block = BuiltInRegistries.BLOCK.get(loc); if (block == null || block == Blocks.AIR) throw new IllegalStateException("Couldn't find block with name " + loc); return block; }).toList(); } public static List getBlocksContaining(Block block) { for (var list : ColoredBlockHelper.LISTS) { if (list.contains(block)) return list; } return null; } }