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

import java.util.Map;
import com.google.common.collect.ImmutableMap;
import com.mojang.datafixers.Dynamic;
import com.mojang.datafixers.types.DynamicOps;
import net.minecraft.core.BlockPos;
import java.util.Optional;

public class EndGatewayConfiguration implements FeatureConfiguration {
    private final Optional<BlockPos> exit;
    private final boolean exact;
    
    private EndGatewayConfiguration(final Optional<BlockPos> optional, final boolean boolean2) {
        this.exit = optional;
        this.exact = boolean2;
    }
    
    public static EndGatewayConfiguration knownExit(final BlockPos fk, final boolean boolean2) {
        return new EndGatewayConfiguration(Optional.<BlockPos>of(fk), boolean2);
    }
    
    public static EndGatewayConfiguration delayedExitSearch() {
        return new EndGatewayConfiguration(Optional.<BlockPos>empty(), false);
    }
    
    public Optional<BlockPos> getExit() {
        return this.exit;
    }
    
    public boolean isExitExact() {
        return this.exact;
    }
    
    @Override
    public <T> Dynamic<T> serialize(final DynamicOps<T> dynamicOps) {
        return (Dynamic<T>)new Dynamic((DynamicOps)dynamicOps, this.exit.map(fk -> dynamicOps.createMap((Map)ImmutableMap.of(dynamicOps.createString("exit_x"), dynamicOps.createInt(fk.getX()), dynamicOps.createString("exit_y"), dynamicOps.createInt(fk.getY()), dynamicOps.createString("exit_z"), dynamicOps.createInt(fk.getZ()), dynamicOps.createString("exact"), dynamicOps.createBoolean(this.exact)))).orElse(dynamicOps.emptyMap()));
    }
    
    public static <T> EndGatewayConfiguration deserialize(final Dynamic<T> dynamic) {
        final Optional<BlockPos> optional2 = dynamic.get("exit_x").asNumber().<BlockPos>flatMap(number -> dynamic.get("exit_y").asNumber().flatMap(number3 -> dynamic.get("exit_z").asNumber().map(number3 -> new BlockPos(number.intValue(), number3.intValue(), number3.intValue()))));
        final boolean boolean3 = dynamic.get("exact").asBoolean(false);
        return new EndGatewayConfiguration(optional2, boolean3);
    }
}
