/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.serialization.Codec */ package net.minecraft.world.item.component; import com.mojang.serialization.Codec; import java.util.Optional; import java.util.function.Consumer; import net.minecraft.ChatFormatting; import net.minecraft.core.Holder; import net.minecraft.core.HolderLookup; import net.minecraft.core.component.DataComponentGetter; import net.minecraft.core.registries.Registries; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.ComponentUtils; import net.minecraft.network.chat.Style; import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.ResourceKey; import net.minecraft.world.item.EitherHolder; import net.minecraft.world.item.Instrument; import net.minecraft.world.item.Item; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.component.TooltipProvider; public record InstrumentComponent(EitherHolder instrument) implements TooltipProvider { public static final Codec CODEC = EitherHolder.codec(Registries.INSTRUMENT, Instrument.CODEC).xmap(InstrumentComponent::new, InstrumentComponent::instrument); public static final StreamCodec STREAM_CODEC = EitherHolder.streamCodec(Registries.INSTRUMENT, Instrument.STREAM_CODEC).map(InstrumentComponent::new, InstrumentComponent::instrument); public InstrumentComponent(Holder instrument) { this(new EitherHolder(instrument)); } @Deprecated public InstrumentComponent(ResourceKey instrument) { this(new EitherHolder(instrument)); } @Override public void addToTooltip(Item.TooltipContext context, Consumer consumer, TooltipFlag flag, DataComponentGetter components) { HolderLookup.Provider registries = context.registries(); if (registries == null) { return; } this.unwrap(registries).ifPresent(instrument -> { Component description = ComponentUtils.mergeStyles(((Instrument)instrument.value()).description(), Style.EMPTY.withColor(ChatFormatting.GRAY)); consumer.accept(description); }); } public Optional> unwrap(HolderLookup.Provider registries) { return this.instrument.unwrap(registries); } }