package ovh.glitchlabs.ornamentum.blocks.custom;

import com.google.common.collect.ImmutableMap;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;

public class babyTurtleBlock extends HorizontalDirectionalBlock {
    public static final MapCodec<babyTurtleBlock> CODEC = simpleCodec(babyTurtleBlock::new);
    private final ImmutableMap<BlockState, VoxelShape> shapes = this.makeShapes();

    public babyTurtleBlock(Properties properties) {
        super(properties);
    }

    private ImmutableMap<BlockState, VoxelShape> makeShapes() {
        return this.getShapeForEachState(state -> {
            return switch (state.getValue(FACING)) {
                case NORTH -> Shapes.or(box(6.5, 0.1, 4, 9.5, 3.1, 7), box(6, 0.1, 7, 10, 2.1, 11));
                case EAST -> Shapes.or(box(9, 0.1, 6.5, 12, 3.1, 9.5), box(5, 0.1, 6, 9, 2.1, 10));
                case WEST -> Shapes.or(box(4, 0.1, 6.5, 7, 3.1, 9.5), box(7, 0.1, 6, 11, 2.1, 10));
                default -> Shapes.or(box(6.5, 0.1, 9, 9.5, 3.1, 12), box(6, 0.1, 5, 10, 2.1, 9));
            };
        });
    }


    @Override
    public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
        return shapes.get(state);
    }

    @Override
    protected MapCodec<? extends HorizontalDirectionalBlock> codec() {
        return CODEC;
    }

    @Nullable
    @Override
    public BlockState getStateForPlacement(BlockPlaceContext context) {
        return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
    }

    @Override
    protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
        builder.add(FACING);
    }
}