/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.datafixers.kinds.App * com.mojang.datafixers.kinds.Applicative * com.mojang.serialization.Codec * com.mojang.serialization.codecs.RecordCodecBuilder */ package net.minecraft.world.item.component; import com.mojang.datafixers.kinds.App; import com.mojang.datafixers.kinds.Applicative; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; import net.minecraft.core.Holder; import net.minecraft.core.component.DataComponentGetter; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; import net.minecraft.util.Util; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.alchemy.PotionContents; import net.minecraft.world.item.component.Consumable; import net.minecraft.world.item.component.ConsumableListener; import net.minecraft.world.item.component.TooltipProvider; import net.minecraft.world.level.Level; public record SuspiciousStewEffects(List effects) implements ConsumableListener, TooltipProvider { public static final SuspiciousStewEffects EMPTY = new SuspiciousStewEffects(List.of()); public static final int DEFAULT_DURATION = 160; public static final Codec CODEC = Entry.CODEC.listOf().xmap(SuspiciousStewEffects::new, SuspiciousStewEffects::effects); public static final StreamCodec STREAM_CODEC = Entry.STREAM_CODEC.apply(ByteBufCodecs.list()).map(SuspiciousStewEffects::new, SuspiciousStewEffects::effects); public SuspiciousStewEffects withEffectAdded(Entry entry) { return new SuspiciousStewEffects(Util.copyAndAdd(this.effects, entry)); } @Override public void onConsume(Level level, LivingEntity user, ItemStack stack, Consumable consumable) { for (Entry effect : this.effects) { user.addEffect(effect.createEffectInstance()); } } @Override public void addToTooltip(Item.TooltipContext context, Consumer consumer, TooltipFlag flag, DataComponentGetter components) { if (flag.isCreative()) { ArrayList effectInstances = new ArrayList(); for (Entry effect : this.effects) { effectInstances.add(effect.createEffectInstance()); } PotionContents.addPotionTooltip(effectInstances, consumer, 1.0f, context.tickRate()); } } public record Entry(Holder effect, int duration) { public static final Codec CODEC = RecordCodecBuilder.create(i -> i.group((App)MobEffect.CODEC.fieldOf("id").forGetter(Entry::effect), (App)Codec.INT.lenientOptionalFieldOf("duration", (Object)160).forGetter(Entry::duration)).apply((Applicative)i, Entry::new)); public static final StreamCodec STREAM_CODEC = StreamCodec.composite(MobEffect.STREAM_CODEC, Entry::effect, ByteBufCodecs.VAR_INT, Entry::duration, Entry::new); public MobEffectInstance createEffectInstance() { return new MobEffectInstance(this.effect, this.duration); } } }