/*
 * 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.item;

import com.remains_cave.RemainsCaveMod;
import com.remains_cave.item.component.QuiverContent;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.core.registries.Registries;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;

public class ModDataComponents {
    public static final DeferredRegister<DataComponentType<?>> DATA_COMPONENT_TYPES =
            DeferredRegister.create(Registries.DATA_COMPONENT_TYPE, RemainsCaveMod.MODID);

    // 定义一个 DataComponentType，它将持有我们的 QuiverContent
    public static final DeferredHolder<DataComponentType<?>, DataComponentType<QuiverContent>> QUIVER_CONTENT =
            DATA_COMPONENT_TYPES.register("quiver_content",
                    () -> DataComponentType.<QuiverContent>builder()
                            // 持久化：存盘时需要
                            .persistent(QuiverContent.CODEC)
                            // 网络同步：当物品在玩家间同步时需要（例如丢出、放入箱子等）
                            .networkSynchronized(QuiverContent.STREAM_CODEC)
                            // 缓存编码器，可选但推荐
                            .cacheEncoding()
                            .build()
            );

    public static void register(IEventBus eventBus) {
        DATA_COMPONENT_TYPES.register(eventBus);
    }
}