/*
 * 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.client.render.block;

import com.remains_cave.block.TombDoorCoreBlock;
import com.remains_cave.block.entity.TombDoorBlockEntity;
import com.remains_cave.RemainsCaveMod;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import org.jetbrains.annotations.NotNull;
import software.bernie.geckolib.model.GeoModel;
import software.bernie.geckolib.renderer.GeoBlockRenderer;

public class TombDoorRenderer extends GeoBlockRenderer<TombDoorBlockEntity> {
    public TombDoorRenderer() {
        super(new GeoModel<>() {
            @Override
            public ResourceLocation getModelResource(TombDoorBlockEntity animatable) {
                return ResourceLocation.fromNamespaceAndPath(RemainsCaveMod.MODID, "geo/block/tomb_door.geo.json");
            }

            @Override
            public ResourceLocation getTextureResource(TombDoorBlockEntity animatable) {
                BlockState state = animatable.getBlockState();
                if (state.getValue(TombDoorCoreBlock.ROOM_CONTROLLED)) {
                    if (state.getValue(TombDoorCoreBlock.ONE_WAY)) {
                        // 房间控制单向门纹理
                        return ResourceLocation.fromNamespaceAndPath(RemainsCaveMod.MODID, "textures/block/tomb_door_room_controlled_one_way.png");
                    } else {
                        // 普通房间控制门纹理
                        return ResourceLocation.fromNamespaceAndPath(RemainsCaveMod.MODID, "textures/block/tomb_door_room_controlled.png");
                    }
                } else if (state.getValue(TombDoorCoreBlock.ONE_WAY)) {
                    // 普通单向门纹理
                    return ResourceLocation.fromNamespaceAndPath(RemainsCaveMod.MODID, "textures/block/tomb_door_one_way.png");
                } else {
                    // 普通门纹理
                    return ResourceLocation.fromNamespaceAndPath(RemainsCaveMod.MODID, "textures/block/tomb_door.png");
                }
            }

            @Override
            public ResourceLocation getAnimationResource(TombDoorBlockEntity animatable) {
                return ResourceLocation.fromNamespaceAndPath(RemainsCaveMod.MODID, "animations/block/tomb_door.animation.json");
            }
        });
    }

    @Override
    public boolean shouldRenderOffScreen(@NotNull TombDoorBlockEntity blockEntity) {
        return true; // 强制渲染，不受视锥剔除影响
    }

    @Override
    public @NotNull AABB getRenderBoundingBox(TombDoorBlockEntity blockEntity) {
        BlockPos pos = blockEntity.getBlockPos();
        // 返回覆盖整个门结构的边界框（宽3格、高4格、深度适当扩展）
        return new AABB(pos.getX() - 2, pos.getY(), pos.getZ() - 2,
                pos.getX() + 3, pos.getY() + 4, pos.getZ() + 3);
    }
}