fixed color changer crashing on white blocks, and not working with stained glass

closes #304
This commit is contained in:
Ell 2023-06-27 10:59:05 +02:00
parent 8bbc14652c
commit f87ef01caa

View file

@ -3,11 +3,11 @@ package de.ellpeck.naturesaura.misc;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.DyeColor;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Comparator;
import java.util.List; import java.util.List;
public final class ColoredBlockHelper { public final class ColoredBlockHelper {
@ -17,15 +17,18 @@ public final class ColoredBlockHelper {
public static final List<Block> CONCRETE_POWDER = ColoredBlockHelper.collectBlocks("concrete_powder"); public static final List<Block> CONCRETE_POWDER = ColoredBlockHelper.collectBlocks("concrete_powder");
public static final List<Block> CONCRETE = ColoredBlockHelper.collectBlocks("concrete"); public static final List<Block> CONCRETE = ColoredBlockHelper.collectBlocks("concrete");
public static final List<Block> GLASS = ColoredBlockHelper.collectBlocks("stained_glass"); public static final List<Block> GLASS = ColoredBlockHelper.collectBlocks("stained_glass");
public static final List<Block> GLASS_PANE = ColoredBlockHelper.collectBlocks("glass_pane"); public static final List<Block> GLASS_PANE = ColoredBlockHelper.collectBlocks("stained_glass_pane");
public static final List<Block> CARPET = ColoredBlockHelper.collectBlocks("carpet"); public static final List<Block> CARPET = ColoredBlockHelper.collectBlocks("carpet");
public static final List<List<Block>> LISTS = Arrays.asList(ColoredBlockHelper.WOOL, ColoredBlockHelper.TERRACOTTA, ColoredBlockHelper.CONCRETE_POWDER, ColoredBlockHelper.CONCRETE, ColoredBlockHelper.GLASS, ColoredBlockHelper.GLASS_PANE, ColoredBlockHelper.CARPET); public static final List<List<Block>> LISTS = Arrays.asList(ColoredBlockHelper.WOOL, ColoredBlockHelper.TERRACOTTA, ColoredBlockHelper.CONCRETE_POWDER, ColoredBlockHelper.CONCRETE, ColoredBlockHelper.GLASS, ColoredBlockHelper.GLASS_PANE, ColoredBlockHelper.CARPET);
private static List<Block> collectBlocks(String name) { private static List<Block> collectBlocks(String name) {
List<Block> blocks = new ArrayList<>(); return Arrays.stream(DyeColor.values()).sorted(Comparator.comparingInt(DyeColor::getId)).map(c -> {
for (var color : DyeColor.values()) var loc = new ResourceLocation(c.getName() + '_' + name);
blocks.add(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(color.getName() + '_' + name))); var block = ForgeRegistries.BLOCKS.getValue(loc);
return Collections.unmodifiableList(blocks); if (block == null || block == Blocks.AIR)
throw new IllegalStateException("Couldn't find block with name " + loc);
return block;
}).toList();
} }
public static List<Block> getBlocksContaining(Block block) { public static List<Block> getBlocksContaining(Block block) {