package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.AbstractStateHolder;
import java.util.stream.Collector;
import net.minecraft.Util;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.phys.shapes.Shapes;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import net.minecraft.world.level.block.state.BlockState;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.core.Direction;
import java.util.Map;
import net.minecraft.world.level.block.state.properties.BooleanProperty;

public class CrossCollisionBlock extends Block implements SimpleWaterloggedBlock {
    public static final BooleanProperty NORTH;
    public static final BooleanProperty EAST;
    public static final BooleanProperty SOUTH;
    public static final BooleanProperty WEST;
    public static final BooleanProperty WATERLOGGED;
    protected static final Map<Direction, BooleanProperty> PROPERTY_BY_DIRECTION;
    protected final VoxelShape[] collisionShapeByIndex;
    protected final VoxelShape[] shapeByIndex;
    private final Object2IntMap<BlockState> stateToIndex;
    
    protected CrossCollisionBlock(final float float1, final float float2, final float float3, final float float4, final float float5, final Properties c) {
        super(c);
        this.stateToIndex = (Object2IntMap<BlockState>)new Object2IntOpenHashMap();
        this.collisionShapeByIndex = this.makeShapes(float1, float2, float5, 0.0f, float5);
        this.shapeByIndex = this.makeShapes(float1, float2, float3, 0.0f, float4);
    }
    
    protected VoxelShape[] makeShapes(final float float1, final float float2, final float float3, final float float4, final float float5) {
        final float float6 = 8.0f - float1;
        final float float7 = 8.0f + float1;
        final float float8 = 8.0f - float2;
        final float float9 = 8.0f + float2;
        final VoxelShape cwf11 = Block.box(float6, 0.0, float6, float7, float3, float7);
        final VoxelShape cwf12 = Block.box(float8, float4, 0.0, float9, float5, float9);
        final VoxelShape cwf13 = Block.box(float8, float4, float8, float9, float5, 16.0);
        final VoxelShape cwf14 = Block.box(0.0, float4, float8, float9, float5, float9);
        final VoxelShape cwf15 = Block.box(float8, float4, float8, 16.0, float5, float9);
        final VoxelShape cwf16 = Shapes.or(cwf12, cwf15);
        final VoxelShape cwf17 = Shapes.or(cwf13, cwf14);
        final VoxelShape[] arr18 = { Shapes.empty(), cwf13, cwf14, cwf17, cwf12, Shapes.or(cwf13, cwf12), Shapes.or(cwf14, cwf12), Shapes.or(cwf17, cwf12), cwf15, Shapes.or(cwf13, cwf15), Shapes.or(cwf14, cwf15), Shapes.or(cwf17, cwf15), cwf16, Shapes.or(cwf13, cwf16), Shapes.or(cwf14, cwf16), Shapes.or(cwf17, cwf16) };
        for (int integer19 = 0; integer19 < 16; ++integer19) {
            arr18[integer19] = Shapes.or(cwf11, arr18[integer19]);
        }
        return arr18;
    }
    
    @Override
    public boolean propagatesSkylightDown(final BlockState byj, final BlockGetter bjg, final BlockPos fk) {
        return !byj.<Boolean>getValue((Property<Boolean>)CrossCollisionBlock.WATERLOGGED);
    }
    
    @Override
    public VoxelShape getShape(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final CollisionContext cvq) {
        return this.shapeByIndex[this.getAABBIndex(byj)];
    }
    
    @Override
    public VoxelShape getCollisionShape(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final CollisionContext cvq) {
        return this.collisionShapeByIndex[this.getAABBIndex(byj)];
    }
    
    private static int indexFor(final Direction fp) {
        return 1 << fp.get2DDataValue();
    }
    
    protected int getAABBIndex(final BlockState byj) {
        int integer2;
        return this.stateToIndex.computeIntIfAbsent(byj, byj -> {
            integer2 = 0;
            if (byj.<Boolean>getValue((Property<Boolean>)CrossCollisionBlock.NORTH)) {
                integer2 |= indexFor(Direction.NORTH);
            }
            if (byj.<Boolean>getValue((Property<Boolean>)CrossCollisionBlock.EAST)) {
                integer2 |= indexFor(Direction.EAST);
            }
            if (byj.<Boolean>getValue((Property<Boolean>)CrossCollisionBlock.SOUTH)) {
                integer2 |= indexFor(Direction.SOUTH);
            }
            if (byj.<Boolean>getValue((Property<Boolean>)CrossCollisionBlock.WEST)) {
                integer2 |= indexFor(Direction.WEST);
            }
            return integer2;
        });
    }
    
    @Override
    public FluidState getFluidState(final BlockState byj) {
        if (byj.<Boolean>getValue((Property<Boolean>)CrossCollisionBlock.WATERLOGGED)) {
            return Fluids.WATER.getSource(false);
        }
        return super.getFluidState(byj);
    }
    
    @Override
    public boolean isPathfindable(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final PathComputationType cqr) {
        return false;
    }
    
    @Override
    public BlockState rotate(final BlockState byj, final Rotation btu) {
        switch (btu) {
            case CLOCKWISE_180: {
                return (((((AbstractStateHolder<O, BlockState>)byj).setValue((Property<Comparable>)CrossCollisionBlock.NORTH, (Comparable)byj.<V>getValue((Property<V>)CrossCollisionBlock.SOUTH))).setValue((Property<Comparable>)CrossCollisionBlock.EAST, (Comparable)byj.<V>getValue((Property<V>)CrossCollisionBlock.WEST))).setValue((Property<Comparable>)CrossCollisionBlock.SOUTH, (Comparable)byj.<V>getValue((Property<V>)CrossCollisionBlock.NORTH))).<Comparable, Comparable>setValue((Property<Comparable>)CrossCollisionBlock.WEST, (Comparable)byj.<V>getValue((Property<V>)CrossCollisionBlock.EAST));
            }
            case COUNTERCLOCKWISE_90: {
                return (((((AbstractStateHolder<O, BlockState>)byj).setValue((Property<Comparable>)CrossCollisionBlock.NORTH, (Comparable)byj.<V>getValue((Property<V>)CrossCollisionBlock.EAST))).setValue((Property<Comparable>)CrossCollisionBlock.EAST, (Comparable)byj.<V>getValue((Property<V>)CrossCollisionBlock.SOUTH))).setValue((Property<Comparable>)CrossCollisionBlock.SOUTH, (Comparable)byj.<V>getValue((Property<V>)CrossCollisionBlock.WEST))).<Comparable, Comparable>setValue((Property<Comparable>)CrossCollisionBlock.WEST, (Comparable)byj.<V>getValue((Property<V>)CrossCollisionBlock.NORTH));
            }
            case CLOCKWISE_90: {
                return (((((AbstractStateHolder<O, BlockState>)byj).setValue((Property<Comparable>)CrossCollisionBlock.NORTH, (Comparable)byj.<V>getValue((Property<V>)CrossCollisionBlock.WEST))).setValue((Property<Comparable>)CrossCollisionBlock.EAST, (Comparable)byj.<V>getValue((Property<V>)CrossCollisionBlock.NORTH))).setValue((Property<Comparable>)CrossCollisionBlock.SOUTH, (Comparable)byj.<V>getValue((Property<V>)CrossCollisionBlock.EAST))).<Comparable, Comparable>setValue((Property<Comparable>)CrossCollisionBlock.WEST, (Comparable)byj.<V>getValue((Property<V>)CrossCollisionBlock.SOUTH));
            }
            default: {
                return byj;
            }
        }
    }
    
    @Override
    public BlockState mirror(final BlockState byj, final Mirror bsu) {
        switch (bsu) {
            case LEFT_RIGHT: {
                return (((AbstractStateHolder<O, BlockState>)byj).setValue((Property<Comparable>)CrossCollisionBlock.NORTH, (Comparable)byj.<V>getValue((Property<V>)CrossCollisionBlock.SOUTH))).<Comparable, Comparable>setValue((Property<Comparable>)CrossCollisionBlock.SOUTH, (Comparable)byj.<V>getValue((Property<V>)CrossCollisionBlock.NORTH));
            }
            case FRONT_BACK: {
                return (((AbstractStateHolder<O, BlockState>)byj).setValue((Property<Comparable>)CrossCollisionBlock.EAST, (Comparable)byj.<V>getValue((Property<V>)CrossCollisionBlock.WEST))).<Comparable, Comparable>setValue((Property<Comparable>)CrossCollisionBlock.WEST, (Comparable)byj.<V>getValue((Property<V>)CrossCollisionBlock.EAST));
            }
            default: {
                return super.mirror(byj, bsu);
            }
        }
    }
    
    static {
        NORTH = PipeBlock.NORTH;
        EAST = PipeBlock.EAST;
        SOUTH = PipeBlock.SOUTH;
        WEST = PipeBlock.WEST;
        WATERLOGGED = BlockStateProperties.WATERLOGGED;
        PROPERTY_BY_DIRECTION = PipeBlock.PROPERTY_BY_DIRECTION.entrySet().stream().filter(entry -> entry.getKey().getAxis().isHorizontal()).collect(Util.<Direction, BooleanProperty>toMap());
    }
}
