/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.serialization.Codec * com.mojang.serialization.DataResult * com.mojang.serialization.MapCodec */ package net.minecraft.world.timeline; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; import com.mojang.serialization.MapCodec; import java.util.Optional; import java.util.function.LongSupplier; import net.minecraft.util.KeyframeTrack; import net.minecraft.util.Util; import net.minecraft.world.attribute.EnvironmentAttribute; import net.minecraft.world.attribute.modifier.AttributeModifier; import net.minecraft.world.timeline.AttributeTrackSampler; public record AttributeTrack(AttributeModifier modifier, KeyframeTrack argumentTrack) { public static Codec> createCodec(EnvironmentAttribute attribute) { MapCodec modifierCodec = attribute.type().modifierCodec().optionalFieldOf("modifier", AttributeModifier.override()); return modifierCodec.dispatch(AttributeTrack::modifier, Util.memoize(modifier -> AttributeTrack.createCodecWithModifier(attribute, modifier))); } private static MapCodec> createCodecWithModifier(EnvironmentAttribute attribute, AttributeModifier modifier) { return KeyframeTrack.mapCodec(modifier.argumentCodec(attribute)).xmap(track -> new AttributeTrack(modifier, track), AttributeTrack::argumentTrack); } public AttributeTrackSampler bakeSampler(EnvironmentAttribute attribute, Optional periodTicks, LongSupplier dayTimeGetter) { return new AttributeTrackSampler(periodTicks, this.modifier, this.argumentTrack, this.modifier.argumentKeyframeLerp(attribute), dayTimeGetter); } public static DataResult> validatePeriod(AttributeTrack track, int periodTicks) { return KeyframeTrack.validatePeriod(track.argumentTrack(), periodTicks).map(ignored -> track); } }