package net.minecraft.world.level.levelgen.feature.configurations;

import java.util.function.Function;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import java.util.function.IntFunction;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import com.mojang.datafixers.Dynamic;
import com.mojang.datafixers.types.DynamicOps;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.levelgen.feature.SpikeFeature;
import java.util.List;

public class SpikeConfiguration implements FeatureConfiguration {
    private final boolean crystalInvulnerable;
    private final List<SpikeFeature.EndSpike> spikes;
    @Nullable
    private final BlockPos crystalBeamTarget;
    
    public SpikeConfiguration(final boolean boolean1, final List<SpikeFeature.EndSpike> list, @Nullable final BlockPos fk) {
        this.crystalInvulnerable = boolean1;
        this.spikes = list;
        this.crystalBeamTarget = fk;
    }
    
    @Override
    public <T> Dynamic<T> serialize(final DynamicOps<T> dynamicOps) {
        return (Dynamic<T>)new Dynamic((DynamicOps)dynamicOps, dynamicOps.createMap((Map)ImmutableMap.of(dynamicOps.createString("crystalInvulnerable"), dynamicOps.createBoolean(this.crystalInvulnerable), dynamicOps.createString("spikes"), dynamicOps.createList((Stream)this.spikes.stream().map(a -> a.<T>serialize(dynamicOps).getValue())), dynamicOps.createString("crystalBeamTarget"), (this.crystalBeamTarget == null) ? dynamicOps.createList((Stream)Stream.empty()) : dynamicOps.createList((Stream)IntStream.of(this.crystalBeamTarget.getX(), this.crystalBeamTarget.getY(), this.crystalBeamTarget.getZ()).mapToObj(dynamicOps::createInt)))));
    }
    
    public static <T> SpikeConfiguration deserialize(final Dynamic<T> dynamic) {
        final List<SpikeFeature.EndSpike> list2 = (List<SpikeFeature.EndSpike>)dynamic.get("spikes").asList((Function)SpikeFeature.EndSpike::deserialize);
        final List<Integer> list3 = (List<Integer>)dynamic.get("crystalBeamTarget").asList(dynamic -> dynamic.asInt(0));
        BlockPos fk4;
        if (list3.size() == 3) {
            fk4 = new BlockPos(list3.get(0), list3.get(1), list3.get(2));
        }
        else {
            fk4 = null;
        }
        return new SpikeConfiguration(dynamic.get("crystalInvulnerable").asBoolean(false), list2, fk4);
    }
    
    public boolean isCrystalInvulnerable() {
        return this.crystalInvulnerable;
    }
    
    public List<SpikeFeature.EndSpike> getSpikes() {
        return this.spikes;
    }
    
    @Nullable
    public BlockPos getCrystalBeamTarget() {
        return this.crystalBeamTarget;
    }
}
