package net.minecraft.world.level.block;

import net.minecraft.Util;
import com.google.common.collect.Maps;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import java.util.EnumMap;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.phys.shapes.VoxelShape;
import java.util.Map;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.core.Direction;

public class PipeBlock extends Block {
    private static final Direction[] DIRECTIONS;
    public static final BooleanProperty NORTH;
    public static final BooleanProperty EAST;
    public static final BooleanProperty SOUTH;
    public static final BooleanProperty WEST;
    public static final BooleanProperty UP;
    public static final BooleanProperty DOWN;
    public static final Map<Direction, BooleanProperty> PROPERTY_BY_DIRECTION;
    protected final VoxelShape[] shapeByIndex;
    
    protected PipeBlock(final float float1, final Properties c) {
        super(c);
        this.shapeByIndex = this.makeShapes(float1);
    }
    
    private VoxelShape[] makeShapes(final float float1) {
        final float float2 = 0.5f - float1;
        final float float3 = 0.5f + float1;
        final VoxelShape dfg5 = Block.box(float2 * 16.0f, float2 * 16.0f, float2 * 16.0f, float3 * 16.0f, float3 * 16.0f, float3 * 16.0f);
        final VoxelShape[] arr6 = new VoxelShape[PipeBlock.DIRECTIONS.length];
        for (int integer7 = 0; integer7 < PipeBlock.DIRECTIONS.length; ++integer7) {
            final Direction fz8 = PipeBlock.DIRECTIONS[integer7];
            arr6[integer7] = Shapes.box(0.5 + Math.min(-float1, fz8.getStepX() * 0.5), 0.5 + Math.min(-float1, fz8.getStepY() * 0.5), 0.5 + Math.min(-float1, fz8.getStepZ() * 0.5), 0.5 + Math.max(float1, fz8.getStepX() * 0.5), 0.5 + Math.max(float1, fz8.getStepY() * 0.5), 0.5 + Math.max(float1, fz8.getStepZ() * 0.5));
        }
        final VoxelShape[] arr7 = new VoxelShape[64];
        for (int integer8 = 0; integer8 < 64; ++integer8) {
            VoxelShape dfg6 = dfg5;
            for (int integer9 = 0; integer9 < PipeBlock.DIRECTIONS.length; ++integer9) {
                if ((integer8 & 1 << integer9) != 0x0) {
                    dfg6 = Shapes.or(dfg6, arr6[integer9]);
                }
            }
            arr7[integer8] = dfg6;
        }
        return arr7;
    }
    
    @Override
    public boolean propagatesSkylightDown(final BlockState cfj, final BlockGetter bpg, final BlockPos fu) {
        return false;
    }
    
    @Override
    public VoxelShape getShape(final BlockState cfj, final BlockGetter bpg, final BlockPos fu, final CollisionContext der) {
        return this.shapeByIndex[this.getAABBIndex(cfj)];
    }
    
    protected int getAABBIndex(final BlockState cfj) {
        int integer3 = 0;
        for (int integer4 = 0; integer4 < PipeBlock.DIRECTIONS.length; ++integer4) {
            if (cfj.<Boolean>getValue((Property<Boolean>)PipeBlock.PROPERTY_BY_DIRECTION.get(PipeBlock.DIRECTIONS[integer4]))) {
                integer3 |= 1 << integer4;
            }
        }
        return integer3;
    }
    
    static {
        DIRECTIONS = Direction.values();
        NORTH = BlockStateProperties.NORTH;
        EAST = BlockStateProperties.EAST;
        SOUTH = BlockStateProperties.SOUTH;
        WEST = BlockStateProperties.WEST;
        UP = BlockStateProperties.UP;
        DOWN = BlockStateProperties.DOWN;
        PROPERTY_BY_DIRECTION = Util.<Map<Direction, BooleanProperty>>make(Maps.newEnumMap(Direction.class), enumMap -> {
            enumMap.put(Direction.NORTH, PipeBlock.NORTH);
            enumMap.put(Direction.EAST, PipeBlock.EAST);
            enumMap.put(Direction.SOUTH, PipeBlock.SOUTH);
            enumMap.put(Direction.WEST, PipeBlock.WEST);
            enumMap.put(Direction.UP, PipeBlock.UP);
            enumMap.put(Direction.DOWN, PipeBlock.DOWN);
        });
    }
}
