本篇教程由作者设定使用 CC BY-NC 协议。

版本1.16.5

首先创建机器

{
    "name": "block.custommachinery.digital_agonizer",
    "appearance": {
        "block": "hostilenetworks:loot_fabricator",
        "light": 1,
        "hardness": 4,
        "resistance": 3000,
        "mining_level": 0
    },
    "components": [
        {
            "id": "data_model",
            "type": "custommachinery:item",
            "filter": ["hostilenetworks:data_model"],
            "whitelist": true
        },
        {
            "type": "custommachinery:energy",
            "capacity": 1000000
        },
        {
            "id": "life_essence_fluid",
            "type": "custommachinery:fluid",
            "capacity": 10000,
            "filter": ["bloodmagic:life_essence_fluid"],
            "whitelist": true
        }
    ],
    "gui": [
        {
            "type": "custommachinery:slot",
            "x": 191,
            "y": 49,
            "id": "data_model"
        },
        {
            "type": "custommachinery:texture",
            "x": 40,
            "y": 35,
            "texture": "bloodmagic:textures/gui/masterroutingnode.png"
        },
        {
            "type": "custommachinery:texture",
            "x": 191,
            "y": 49,
            "width": 18,
            "height": 18,
            "texture": "hostilenetworks:textures/gui/slot.png"
        },
        {
            "type": "custommachinery:texture",
            "x": 23,
            "y": 35,
            "texture": "hostilenetworks:textures/gui/digital_agonizer.png"
        },
        {
            "type": "custommachinery:energy",
            "x": 27,
            "y": 45,
            "width": 7,
            "height": 100,
            "emptytexture": "hostilenetworks:textures/gui/energy_empty.png",
            "filledtexture": "hostilenetworks:textures/gui/energy_filled.png"
        },
        {
            "type": "custommachinery:fluid",
            "x": 119,
            "y": 49,
            "height": 18,
            "texture": "custommachinery:textures/gui/base_slot.png",
            "id": "life_essence_fluid"
        },
        {
            "type": "custommachinery:player_inventory",
            "x": 47,
            "y": 73
        },
        {
            "type": "custommachinery:text",
            "x": 48,
            "y": 40,
            "text": "block.custommachinery.digital_agonizer"
        },
        {
            "type": "custommachinery:text",
            "x": 48,
            "y": 62,
            "text": "container.inventory"
        }
    ],
    "jei": [
        {
            "type": "custommachinery:slot",
            "x": 119,
            "y": 49,
            "id": "data_model"
        }
    ]
}

以下是材质

使用CM与KJS创建复杂NBT配方实例-数字化苦难之井(伪)-第1张图片

slot.png

使用CM与KJS创建复杂NBT配方实例-数字化苦难之井(伪)-第2张图片

energy_filled.png

使用CM与KJS创建复杂NBT配方实例-数字化苦难之井(伪)-第3张图片

energy_empty.png

使用CM与KJS创建复杂NBT配方实例-数字化苦难之井(伪)-第4张图片

digital_agonizer.png

然后添加配方

if(Platform.getMods().containsKey('custommachinery') & 
    Platform.getMods().containsKey('hostilenetworks') & 
    Platform.getMods().containsKey('bloodmagic')){
    const valueMap = new Map([['hostilenetworks:slime', 15]]);
    onEvent('recipes', event => {
        event.shaped(Item.of('custommachinery:custom_machine_item', '{machine:"hostilenetworks:digital_agonizer"}'),[
            ' N ',
            'WOW',
            'GCG'
        ], {
            N:'#forge:ingots/netherite',
            W:'bloodmagic:weakbloodorb',
            O:'#forge:obsidian',
            G:'#forge:ingots/gold',
            C:'minecraft:comparator'
        });
        event.recipes.custommachinery.custom_machine('hostilenetworks:digital_agonizer', -1)
            .requireEnergyPerTick(128)
            .requireFunctionEachTick(ctx => {
                let machine = ctx.machine;
                let nbt = machine.getItemStored('data_model').nbt;
                if(nbt != null){
                    let v = 10;
                    if(valueMap.has(`${nbt['data_model']['id']}`)){
                        v = valueMap.get(`${nbt['data_model']['id']}`)
                    }
                    let data = nbt['data_model']['data'];
                    if(data >= 1254){v += 300}
                    else if(data >= 354){v += 150}
                    else if(data >= 54){v += 75}
                    else if(data >= 6){v += 50}
                    machine.addFluid(Fluid.of('bloodmagic:life_essence_fluid', v), false);
                    return Result.success();
                }else{
                    return Result.error("Can't find data model");
                }
            })
    })
}

17行将配方时间设为负数, 使得配方无限执行

19-37行这里使用了requireFunctionEachTick()方法, 必须返回Result

24-25行检索valueMap的元素, 如果包含指定NBT, 将LP初始值设为对应值

经测试, 必须使用模版字符串, toString()或直接传入都无法正常判断

28-31行判断数据模型等级, 根据不同等级增加LP

32行添加生命源质液到流体槽位

实际效果

使用CM与KJS创建复杂NBT配方实例-数字化苦难之井(伪)-第5张图片已知问题: 机器的选择框描边会变成透明, 造成边框透视效果

临时解决方案: 开光影, 修改选择框颜色