package net.minecraft.world.item.armortrim; import java.util.Map; import java.util.Optional; import net.minecraft.Util; import net.minecraft.core.Holder; import net.minecraft.core.HolderLookup; import net.minecraft.core.registries.Registries; import net.minecraft.data.worldgen.BootstrapContext; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Style; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ArmorMaterial; import net.minecraft.world.item.ArmorMaterials; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; public class TrimMaterials { public static final ResourceKey QUARTZ = registryKey("quartz"); public static final ResourceKey IRON = registryKey("iron"); public static final ResourceKey NETHERITE = registryKey("netherite"); public static final ResourceKey REDSTONE = registryKey("redstone"); public static final ResourceKey COPPER = registryKey("copper"); public static final ResourceKey GOLD = registryKey("gold"); public static final ResourceKey EMERALD = registryKey("emerald"); public static final ResourceKey DIAMOND = registryKey("diamond"); public static final ResourceKey LAPIS = registryKey("lapis"); public static final ResourceKey AMETHYST = registryKey("amethyst"); public static void bootstrap(BootstrapContext context) { register(context, QUARTZ, Items.QUARTZ, Style.EMPTY.withColor(14931140), 0.1F); register(context, IRON, Items.IRON_INGOT, Style.EMPTY.withColor(15527148), 0.2F, Map.of(ArmorMaterials.IRON, "iron_darker")); register(context, NETHERITE, Items.NETHERITE_INGOT, Style.EMPTY.withColor(6445145), 0.3F, Map.of(ArmorMaterials.NETHERITE, "netherite_darker")); register(context, REDSTONE, Items.REDSTONE, Style.EMPTY.withColor(9901575), 0.4F); register(context, COPPER, Items.COPPER_INGOT, Style.EMPTY.withColor(11823181), 0.5F); register(context, GOLD, Items.GOLD_INGOT, Style.EMPTY.withColor(14594349), 0.6F, Map.of(ArmorMaterials.GOLD, "gold_darker")); register(context, EMERALD, Items.EMERALD, Style.EMPTY.withColor(1155126), 0.7F); register(context, DIAMOND, Items.DIAMOND, Style.EMPTY.withColor(7269586), 0.8F, Map.of(ArmorMaterials.DIAMOND, "diamond_darker")); register(context, LAPIS, Items.LAPIS_LAZULI, Style.EMPTY.withColor(4288151), 0.9F); register(context, AMETHYST, Items.AMETHYST_SHARD, Style.EMPTY.withColor(10116294), 1.0F); } public static Optional> getFromIngredient(HolderLookup.Provider regustries, ItemStack ingredient) { return regustries.lookupOrThrow(Registries.TRIM_MATERIAL) .listElements() .filter(reference -> ingredient.is(((TrimMaterial)reference.value()).ingredient())) .findFirst(); } private static void register(BootstrapContext context, ResourceKey materialKey, Item ingredient, Style style, float itemModelIndex) { register(context, materialKey, ingredient, style, itemModelIndex, Map.of()); } private static void register( BootstrapContext context, ResourceKey materialKey, Item ingredient, Style style, float itemModelIndex, Map, String> overrideArmorMaterials ) { TrimMaterial trimMaterial = TrimMaterial.create( materialKey.location().getPath(), ingredient, itemModelIndex, Component.translatable(Util.makeDescriptionId("trim_material", materialKey.location())).withStyle(style), overrideArmorMaterials ); context.register(materialKey, trimMaterial); } private static ResourceKey registryKey(String key) { return ResourceKey.create(Registries.TRIM_MATERIAL, ResourceLocation.withDefaultNamespace(key)); } }