CC: Bundles

模组

· 作者 OdiumTrues

允许 CC: Tweaked 的机器人装备和使用原版 Minecraft 的包裹。

0 本站下载 0 关注 更新于 3 个月前

最新 1.0 · 26.2 · Fabric

一键开服(送7天)

CC:Bundles

CC:Bundles 允许 CC:Tweaked 的挖掘者装备并使用原版 Minecraft 的 Bundle(收纳袋)作为库存外围设备。

  • 普通收纳袋 + 全部 16 种染色变体
  • 装备/卸下时保留收纳袋的颜色和内容物
  • 采用 CC:Tweaked 风格的库存 API
  • 收纳袋容量工具函数
  • bundleCost 物品信息
  • 直接访问挖掘者的库存
  • 将收纳袋内容物倾倒到世界中

API

方法 描述
size() 唯一物品变体的数量
list() 列出收纳袋内容物
getItemDetail(slot) 详细的物品信息,包括 bundleCost
getItemLimit(slot) 虚拟槽位的物品上限
pushItems(toName, fromSlot [, limit [, toSlot]]) 将物品移出收纳袋
pullItems(fromName, fromSlot [, limit [, toSlot]]) 将物品移入收纳袋
slotsFull() 已使用的容量(总共 64)
slotsFree() 剩余容量(总共 64)
dump() 将全部内容物倾倒出来

库存方法遵循 CC:Tweaked 的通用库存外围设备的约定。

使用收纳袋

装备后,将收纳袋包装为外围设备:

local bundle = peripheral.wrap("left")

或:

local bundle = peripheral.wrap("right")

虚拟槽位

收纳袋没有固定的库存槽位。

每个存储的唯一物品变体都作为一个虚拟槽位暴露:

{
    [1] = {
        name = "minecraft:oak_planks",
        count = 12
    },

    [2] = {
        name = "minecraft:diamond",
        count = 3
    }
}

具有不同组件或存储数据的物品是独立的变体。

当内容物改变时,虚拟槽位编号可能会发生变化。

size() 返回当前虚拟槽位的数量,而不是固定的库存大小。

bundleCost

getItemDetail(slot) 包含:

bundleCost

单个物品占用的容量:

64堆叠物品   = 1
16堆叠物品   = 4
不可堆叠物品 = 64

示例:

local item = bundle.getItemDetail(1)

print(item.name)
print(item.count)
print(item.bundleCost)

CC:Bundles 还将 bundleCost 添加到:

turtle.getItemDetail(slot, true)

第二个参数必须为 true。

local item = turtle.getItemDetail(4, true)

if item then
    print(item.bundleCost)
end

这可以与 slotsFree() 配合使用,以确定能容纳多少物品:

local item = turtle.getItemDetail(4, true)

if item then
    local maxFit = math.floor(bundle.slotsFree() / item.bundleCost)

    bundle.pullItems(
        "turtle",
        4,
        math.min(item.count, maxFit)
    )
end

移动物品

pullItems() 将物品移入收纳袋:

bundle.pullItems(fromName, fromSlot [, limit [, toSlot]])

pushItems() 将物品移出收纳袋:

bundle.pushItems(toName, fromSlot [, limit [, toSlot]])

两者均返回移动的物品的数量。

挖掘者库存

挖掘者槽位 4 → 收纳袋:

bundle.pullItems("turtle", 4)

最多 8 个物品:

bundle.pullItems("turtle", 4, 8)

收纳袋槽位 1 → 挖掘者:

bundle.pushItems("turtle", 1)

进入挖掘者槽位 6:

bundle.pushItems("turtle", 1, 8, 6)

其他库存使用其正常的外围设备名称。

收纳袋容量

bundle.slotsFull()
bundle.slotsFree()

两者均使用 Minecraft 的实际收纳袋容量规则。

bundle.slotsFull() + bundle.slotsFree()

始终等于:

64

倾倒内容物

local count = bundle.dump()

dump():

  • 将收纳袋的全部内容物倾倒到挖掘者前方

示例:查找物品

for slot, item in pairs(bundle.list()) do
    if item.name == "minecraft:diamond" then
        print(slot, item.count)
    end
end

文档

你是这个资源的作者?登录后可认领此资源。

评论 0

0.0
暂无评分
5 星
0
4 星
0
3 星
0
2 星
0
1 星
0
我的评分

登录后参与评分

还没有评论,来抢沙发吧

评论配图

相似资源