2025-11-24 22:52:51 +03:00

60 lines
2.4 KiB
Java

/*
* 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> instrument) implements TooltipProvider
{
public static final Codec<InstrumentComponent> CODEC = EitherHolder.codec(Registries.INSTRUMENT, Instrument.CODEC).xmap(InstrumentComponent::new, InstrumentComponent::instrument);
public static final StreamCodec<RegistryFriendlyByteBuf, InstrumentComponent> STREAM_CODEC = EitherHolder.streamCodec(Registries.INSTRUMENT, Instrument.STREAM_CODEC).map(InstrumentComponent::new, InstrumentComponent::instrument);
public InstrumentComponent(Holder<Instrument> instrument) {
this(new EitherHolder<Instrument>(instrument));
}
@Deprecated
public InstrumentComponent(ResourceKey<Instrument> instrument) {
this(new EitherHolder<Instrument>(instrument));
}
@Override
public void addToTooltip(Item.TooltipContext context, Consumer<Component> 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<Holder<Instrument>> unwrap(HolderLookup.Provider registries) {
return this.instrument.unwrap(registries);
}
}