package net.minecraft.core;

import java.util.Optional;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import com.mojang.datafixers.types.DynamicOps;
import java.util.Objects;
import java.util.function.Function;
import com.mojang.datafixers.Dynamic;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.util.Serializable;

public final class GlobalPos implements Serializable {
    private final DimensionType dimension;
    private final BlockPos pos;
    
    private GlobalPos(final DimensionType cbi, final BlockPos fk) {
        this.dimension = cbi;
        this.pos = fk;
    }
    
    public static GlobalPos of(final DimensionType cbi, final BlockPos fk) {
        return new GlobalPos(cbi, fk);
    }
    
    public static GlobalPos of(final Dynamic<?> dynamic) {
        return dynamic.get("dimension").map((Function)DimensionType::of).<GlobalPos>flatMap(cbi -> dynamic.get("pos").map((Function)BlockPos::deserialize).map(fk -> new GlobalPos(cbi, fk))).<Throwable>orElseThrow(() -> new IllegalArgumentException("Could not parse GlobalPos"));
    }
    
    public DimensionType dimension() {
        return this.dimension;
    }
    
    public BlockPos pos() {
        return this.pos;
    }
    
    @Override
    public boolean equals(final Object object) {
        if (this == object) {
            return true;
        }
        if (object == null || this.getClass() != object.getClass()) {
            return false;
        }
        final GlobalPos fr3 = (GlobalPos)object;
        return Objects.equals(this.dimension, fr3.dimension) && Objects.equals(this.pos, fr3.pos);
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.dimension, this.pos);
    }
    
    @Override
    public <T> T serialize(final DynamicOps<T> dynamicOps) {
        return (T)dynamicOps.createMap((Map)ImmutableMap.of(dynamicOps.createString("dimension"), this.dimension.<V>serialize((com.mojang.datafixers.types.DynamicOps<V>)dynamicOps), dynamicOps.createString("pos"), this.pos.<V>serialize((com.mojang.datafixers.types.DynamicOps<V>)dynamicOps)));
    }
    
    @Override
    public String toString() {
        return this.dimension.toString() + " " + this.pos;
    }
}
