package sh.grimmer.bettershulkers.util;

import it.unimi.dsi.fastutil.HashCommon;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.item.ItemStackRenderState;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

import org.jetbrains.annotations.Nullable;

public final class ItemRenderHelper {

    private ItemRenderHelper() {
    }

    @Nullable
    public static ItemStackRenderState createRenderState(Level level, @Nullable BlockPos pos, @Nullable ItemStack stack) {
        if (stack == null) {
            return null;
        }
        ItemStackRenderState state = new ItemStackRenderState();
        int seed = pos == null ? 0 : HashCommon.long2int(pos.asLong());
        Minecraft.getInstance().getItemModelResolver().updateForTopItem(state, stack, ItemDisplayContext.FIXED, level, null, seed);
        return state;
    }
}
