/*
 *  Copyright 2025-2026 R3944Realms
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package top.r3944realms.eroticdungeongame.datagen.provider;

import net.minecraft.core.HolderLookup;
import net.minecraft.data.PackOutput;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.common.data.BlockTagsProvider;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import top.r3944realms.eroticdungeongame.EroticDungeon;
import top.r3944realms.eroticdungeongame.content.block.AbstractSeatBlock;
import top.r3944realms.eroticdungeongame.core.register.EDGBlocks;
import top.r3944realms.eroticdungeongame.core.register.tag.EDGBlockTags;

import java.util.concurrent.CompletableFuture;

public class EDGBlockTagsProvider extends BlockTagsProvider {
    public static final TagKey<Block> CARRYON_BLACKLIST =
            TagKey.create(ForgeRegistries.BLOCKS.getRegistryKey(),
                    EroticDungeon.rl("carryon", "block_blacklist"));

    public EDGBlockTagsProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> lookupProvider,
                                @Nullable ExistingFileHelper existingFileHelper) {
        super(output, lookupProvider,
                EroticDungeon.MOD_ID, existingFileHelper);
    }

    @Override
    protected void addTags(HolderLookup.@NotNull Provider provider) {
        // 遍历所有注册的方块，找出座位方块
        for (RegistryObject<Block> blockObject : EDGBlocks.BLOCKS.getEntries()) {
            Block block = blockObject.get();

            // 检查是否是座位方块（根据你的类层次结构）
            if (block instanceof AbstractSeatBlock) {

                // 添加到 CarryOn 黑名单
                tag(CARRYON_BLACKLIST)
                        .add(block)
                        .replace(false);

            }
        }
        tag(EDGBlockTags.SEAT).add(EDGBlocks.SEAT_BLOCKS.stream().map(RegistryObject::get).map(Block.class::cast).toArray(Block[]::new));
        tag(EDGBlockTags.CUFF_BED).add(EDGBlocks.getCuffedBlocks());
        tag(EDGBlockTags.RACK).add(EDGBlocks.getRackBlocks());
        tag(EDGBlockTags.X_CROSS).add(EDGBlocks.getXCrossBlocks());
        tag(EDGBlockTags.PETRINE_CROSS).add(EDGBlocks.getPetrineCrossBlocks());
        tag(EDGBlockTags.CRUX).add(EDGBlocks.getCruxBlocks());
        tag(EDGBlockTags.SPANISH_DONKEY).add(EDGBlocks.getSpanishDonkeyBlocks());
        tag(EDGBlockTags.PILLORY).add(EDGBlocks.getPilloryBlocks());
        tag(EDGBlockTags.WALL_RACK).add(EDGBlocks.getWallRackBlocks());
        tag(EDGBlockTags.CUFF_POLE).add(EDGBlocks.getCuffPoleBlocks());
        tag(EDGBlockTags.PRONE_BENCH).add(EDGBlocks.getProneBenchBlocks());
        tag(EDGBlockTags.HANGING_POST).add(EDGBlocks.getHangingPostBlocks());
    }
}
