package top.r3944realms.lib39.base.datagen.provider;

import net.minecraft.core.Direction;
import net.minecraft.data.PackOutput;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraftforge.client.model.generators.BlockStateProvider;
import net.minecraftforge.client.model.generators.ConfiguredModel;
import net.minecraftforge.client.model.generators.ModelFile;
import net.minecraftforge.common.data.ExistingFileHelper;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import top.r3944realms.lib39.Lib39;
import top.r3944realms.lib39.content.register.Lib39Blocks;

/**
 * The type Lib 39 block states provider.
 */
public class Lib39BlockStatesProvider extends BlockStateProvider {
    /**
     * Instantiates a new Lib 39 block states provider.
     *
     * @param output       the output
     * @param exFileHelper the ex file helper
     */
    public Lib39BlockStatesProvider(PackOutput output, ExistingFileHelper exFileHelper) {
        super(output, Lib39.MOD_ID, exFileHelper);
    }
    @Override
    protected void registerStatesAndModels() {
        generateDollBlockStatesSimple();
    }
    private void generateDollBlockStatesSimple() {
        Block doll = Lib39Blocks.DOLL.get();

        // 创建GeckoLib模型引用
        ModelFile modelFile = new ModelFile.ExistingModelFile(
                Lib39.rl( "block/base_doll"),
                models().existingFileHelper
        );

        getVariantBuilder(doll).forAllStates(state -> {
            Direction direction = state.getValue(BlockStateProperties.HORIZONTAL_FACING);
            int rotationY = getMainNorthRotationY(direction);

            return ConfiguredModel.builder()
                    .modelFile(modelFile)
                    .rotationY(rotationY)
                    .build();
        });
    }

    @Contract(pure = true)
    private int getMainWestRotationY(@NotNull Direction direction) {
        return switch (direction) {
            case WEST -> 0;    // 西 - 基准方向，0度
            case NORTH -> 90;  // 北 - 相对于西旋转90度
            case EAST -> 180;  // 东 - 相对于西旋转180度
            case SOUTH -> 270; // 南 - 相对于西旋转270度
            default -> 0;
        };
    }

    @Contract(pure = true)
    private int getMainNorthRotationY(@NotNull Direction direction) {
        return switch (direction) {
            case WEST -> 270;    // 西 - 基准方向，270度
            case NORTH -> 0;  // 北 - 相对于西旋转0度
            case EAST -> 90;  // 东 - 相对于西旋转90度
            case SOUTH -> 180; // 南 - 相对于西旋转180度
            default -> 0;
        };
    }
}
