/*
 * Copyright (c) 2026 盐灯水母
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

package com.remains_cave.block;

import com.remains_cave.RemainsCaveMod;
import com.remains_cave.block.entity.*;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.MapColor;
import net.neoforged.neoforge.registries.DeferredBlock;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ModBlocks {
    private static final Logger LOGGER = LoggerFactory.getLogger(ModBlocks.class);

    public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(RemainsCaveMod.MODID);
    public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES =
            DeferredRegister.create(Registries.BLOCK_ENTITY_TYPE, RemainsCaveMod.MODID);

    // 战利品方块
    public static final DeferredBlock<Block> SKELETON_ARCHER_TROPHY = BLOCKS.register("skeleton_archer_trophy",
            () -> new TrophyBlock(BlockBehaviour.Properties.of().mapColor(MapColor.STONE).strength(1.0f).noOcclusion()));
    public static final DeferredBlock<Block> SKELETON_KING_TROPHY = BLOCKS.register("skeleton_king_trophy",
            () -> new TrophyBlock(BlockBehaviour.Properties.of().mapColor(MapColor.STONE).strength(1.0f).noOcclusion()));
    public static final DeferredBlock<Block> SKELETON_WARLOCK_TROPHY = BLOCKS.register("skeleton_warlock_trophy",
            () -> new TrophyBlock(BlockBehaviour.Properties.of().mapColor(MapColor.STONE).strength(1.0f).noOcclusion()));
    public static final DeferredBlock<Block> SKELETON_WARRIOR_TROPHY = BLOCKS.register("skeleton_warrior_trophy",
            () -> new TrophyBlock(BlockBehaviour.Properties.of().mapColor(MapColor.STONE).strength(1.0f).noOcclusion()));

    // 战利品方块实体
    public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<TrophyBlockEntity>> TROPHY_BLOCK_ENTITY =
            BLOCK_ENTITIES.register("trophy",
                    () -> BlockEntityType.Builder.of(TrophyBlockEntity::new,
                            SKELETON_ARCHER_TROPHY.get(),
                            SKELETON_KING_TROPHY.get(),
                            SKELETON_WARLOCK_TROPHY.get(),
                            SKELETON_WARRIOR_TROPHY.get()
                    ).build(null));

    // ========== 宝库方块 ==========
    public static final DeferredBlock<Block> ROOM_VAULT = BLOCKS.register("room_vault",
            () -> new TrialVaultBlock(TrialVaultType.ROOM));
    public static final DeferredBlock<Block> BOSS_VAULT = BLOCKS.register("boss_vault",
            () -> new TrialVaultBlock(TrialVaultType.BOSS));

    // 宝库方块实体
    public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<TrialVaultBlockEntity>> TRIAL_VAULT_BLOCK_ENTITY =
            BLOCK_ENTITIES.register("trial_vault",
                    () -> BlockEntityType.Builder.of(TrialVaultBlockEntity::new,
                            ROOM_VAULT.get(),
                            BOSS_VAULT.get()
                    ).build(null));

    public static final DeferredBlock<Block> TOMB_DOOR_CORE = BLOCKS.register("tomb_door_core",
            TombDoorCoreBlock::new);
    public static final DeferredBlock<Block> TOMB_DOOR_PART = BLOCKS.register("tomb_door_part",
            TombDoorPartBlock::new);

    // 方块实体注册（只绑定核心方块）
    public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<TombDoorBlockEntity>> TOMB_DOOR_BLOCK_ENTITY =
            BLOCK_ENTITIES.register("tomb_door",
                    () -> BlockEntityType.Builder.of(TombDoorBlockEntity::new,
                            TOMB_DOOR_CORE.get()
                    ).build(null));


    public static final DeferredBlock<Block> SKELETON_KING_SUMMON = BLOCKS.register("skeleton_king_summon",
            SkeletonKingSummonBlock::new);

    public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<SkeletonKingSummonBlockEntity>> SKELETON_KING_SUMMON_BLOCK_ENTITY =
            BLOCK_ENTITIES.register("skeleton_king_summon",
                    () -> BlockEntityType.Builder.of(SkeletonKingSummonBlockEntity::new,
                            SKELETON_KING_SUMMON.get()
                    ).build(null));


    public static final DeferredBlock<Block> SKELETON_KING_REMAINS = BLOCKS.register("skeleton_king_remains",
            SkeletonKingRemainsBlock::new);

    public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<SkeletonKingRemainsBlockEntity>> SKELETON_KING_REMAINS_BLOCK_ENTITY =
            BLOCK_ENTITIES.register("skeleton_king_remains",
                    () -> BlockEntityType.Builder.of(SkeletonKingRemainsBlockEntity::new,
                            SKELETON_KING_REMAINS.get()
                    ).build(null));


    public static final DeferredBlock<Block> CHALLENGE_ALTAR = BLOCKS.register("challenge_altar",
            () -> new ChallengeAltarBlock(BlockBehaviour.Properties.of().mapColor(MapColor.STONE).strength(3.0f).noOcclusion()));
    public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<ChallengeAltarBlockEntity>> CHALLENGE_ALTAR_BE =
            BLOCK_ENTITIES.register("challenge_altar",
                    () -> BlockEntityType.Builder.of(ChallengeAltarBlockEntity::new, CHALLENGE_ALTAR.get()).build(null));

    public static final DeferredBlock<Block> CHALLENGE_CAGE = BLOCKS.register("challenge_cage",
            () -> new ChallengeCageBlock(BlockBehaviour.Properties.of()
                    .strength(-1.0f, 3600000.0f)
                    .noLootTable()
                    .noOcclusion()
                    .isViewBlocking((s, l, p) -> false)
            ));
    public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<ChallengeCageBlockEntity>> CHALLENGE_CAGE_BE =
            BLOCK_ENTITIES.register("challenge_cage",
                    () -> BlockEntityType.Builder.of(ChallengeCageBlockEntity::new, CHALLENGE_CAGE.get()).build(null));

    public static final DeferredBlock<Block> EMBLEM_BLOCK = BLOCKS.register("emblem", EmblemBlock::new);
    public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<EmblemBlockEntity>> EMBLEM_BLOCK_ENTITY =
            BLOCK_ENTITIES.register("emblem_block_entity",
                    () -> BlockEntityType.Builder.of(EmblemBlockEntity::new, EMBLEM_BLOCK.get()).build(null));
}