inventory

package
v0.0.0-...-e726f2f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SlotSize 单槽位边长(正方形)
	SlotSize = 32
	// SlotPitch 相邻槽位起点间距(含槽间距 4px)
	SlotPitch = 36
)

Variables

This section is empty.

Functions

func ApplyGlint

func ApplyGlint(version string, item image.Image) image.Image

ApplyGlint 在物品图像上叠加附魔光泽

实现:把紫色的 glint 覆盖层,以物品的 alpha 通道为遮罩(只覆盖非透明像素),
按 glintAlpha 半透明叠加到物品图像上。

若加载 glint 纹理失败,返回原图并记录 warning(不阻断请求)。

func DebugSlots

func DebugSlots(t ContainerType) []image.Point

DebugSlots 返回指定容器的所有槽位坐标(用于坐标校准测试) 未注册容器返回 nil

func MissingTexture

func MissingTexture(targetW, targetH int) image.Image

MissingTexture 生成 targetW × targetH 的紫黑棋盘缺省贴图(Minecraft 经典 missing texture) 采用 2×2 棋盘:左上 & 右下 紫色(248,0,248),右上 & 左下 黑色

func Render

func Render(version string, ct ContainerType, items []*Item, options *Options, manager texture.AssetsManager) (image.Image, error)

Render 渲染整个容器

version:  Minecraft 版本,如 "1.21.1"
ct:       容器类型
items:    物品列表,slot=-1 按顺序自动放置
options:  预留
manager:  资源管理器(提供 UI 底图访问)

func ResolveItem

func ResolveItem(version, itemName string, targetW, targetH int) image.Image

ResolveItem 根据物品名定位并加载贴图,返回图像尺寸恒等于 targetW × targetH

策略:
  1. 读 models/item/<name>.json
  2. 若含 textures.layer0     → 2D 物品,加载 textures/<layer0>.png 后缩放到目标尺寸
  3. 若 parent 以 "block/" 开头且无 layer0 → 3D 方块,调用 blockrender.GetBlockImageWithSize
  4. 任何一步失败 → 返回目标尺寸的紫黑棋盘缺省贴图

Types

type ContainerType

type ContainerType string

ContainerType 容器类型枚举

const (
	// ContainerChest 大箱子 9x6=54 槽(对应 generic_54.png)
	ContainerChest ContainerType = "chest"
	// ContainerPlayerInventory 玩家背包 41 槽(主背包+快捷栏+护甲+副手)
	ContainerPlayerInventory ContainerType = "player_inventory"
)

type Item

type Item struct {
	// Slot 槽位索引;-1 表示按 Items 顺序自动放置
	Slot int
	// Name 物品名(无 minecraft: 前缀),如 "diamond_sword"
	Name string
	// Count 堆叠数量,>1 时在右下角绘制数字
	Count int
	// Enchanted 是否附魔(叠加光泽)
	Enchanted bool
}

Item 一个待绘制的物品条目

type Options

type Options struct{}

Options 渲染选项(预留)

type SlotLayout

type SlotLayout struct {
	// UITexturePath 该容器的 ICDA 高清 UI 纹理 minecraft 路径
	// e.g. "minecraft:interactivechatdiscordsrvaddon/gui/generic_54"
	UITexturePath string
	// UIWidth 输出图片宽度(ICDA 像素坐标系,未再缩放)
	UIWidth int
	// UIHeight 输出图片高度
	UIHeight int
	// SlotWidth 单个槽位的物品目标宽度
	SlotWidth int
	// SlotHeight 单个槽位的物品目标高度
	SlotHeight int
	// Slots 每个槽位左上角坐标(按 slot 索引顺序)
	Slots []image.Point
}

SlotLayout 单个容器的槽位布局定义

func GetLayout

func GetLayout(t ContainerType) (*SlotLayout, error)

GetLayout 获取指定容器的布局定义 若容器不支持返回 error

func (*SlotLayout) SlotCount

func (l *SlotLayout) SlotCount() int

SlotCount 该容器的槽位总数

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL