package net.minecraft.world.item.equipment.trim; 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.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.equipment.EquipmentModels; 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 bootstrapContext) { register(bootstrapContext, QUARTZ, Items.QUARTZ, Style.EMPTY.withColor(14931140), 0.1F); register(bootstrapContext, IRON, Items.IRON_INGOT, Style.EMPTY.withColor(15527148), 0.2F, Map.of(EquipmentModels.IRON, "iron_darker")); register(bootstrapContext, NETHERITE, Items.NETHERITE_INGOT, Style.EMPTY.withColor(6445145), 0.3F, Map.of(EquipmentModels.NETHERITE, "netherite_darker")); register(bootstrapContext, REDSTONE, Items.REDSTONE, Style.EMPTY.withColor(9901575), 0.4F); register(bootstrapContext, COPPER, Items.COPPER_INGOT, Style.EMPTY.withColor(11823181), 0.5F); register(bootstrapContext, GOLD, Items.GOLD_INGOT, Style.EMPTY.withColor(14594349), 0.6F, Map.of(EquipmentModels.GOLD, "gold_darker")); register(bootstrapContext, EMERALD, Items.EMERALD, Style.EMPTY.withColor(1155126), 0.7F); register(bootstrapContext, DIAMOND, Items.DIAMOND, Style.EMPTY.withColor(7269586), 0.8F, Map.of(EquipmentModels.DIAMOND, "diamond_darker")); register(bootstrapContext, LAPIS, Items.LAPIS_LAZULI, Style.EMPTY.withColor(4288151), 0.9F); register(bootstrapContext, AMETHYST, Items.AMETHYST_SHARD, Style.EMPTY.withColor(10116294), 1.0F); } public static Optional> getFromIngredient(HolderLookup.Provider provider, ItemStack itemStack) { return provider.lookupOrThrow(Registries.TRIM_MATERIAL) .listElements() .filter(reference -> itemStack.is(((TrimMaterial)reference.value()).ingredient())) .findFirst(); } private static void register(BootstrapContext bootstrapContext, ResourceKey resourceKey, Item item, Style style, float f) { register(bootstrapContext, resourceKey, item, style, f, Map.of()); } private static void register( BootstrapContext bootstrapContext, ResourceKey resourceKey, Item item, Style style, float f, Map map ) { TrimMaterial trimMaterial = TrimMaterial.create( resourceKey.location().getPath(), item, f, Component.translatable(Util.makeDescriptionId("trim_material", resourceKey.location())).withStyle(style), map ); bootstrapContext.register(resourceKey, trimMaterial); } private static ResourceKey registryKey(String string) { return ResourceKey.create(Registries.TRIM_MATERIAL, ResourceLocation.withDefaultNamespace(string)); } }