Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Change of multiblock structure

vfyjxf edited this page Feb 12, 2023 · 2 revisions

You may want to change the structure of the multi-block when the recipe is completed, for example by giving the multi-block a chance of being contaminated resulting in a loss of efficiency or something. Here's an example of modifying the multiblock structure when the recipe is complete (of course, you can also use other kubejs events to modify the multiblock when it's not running)

onEvent("mbd.recipe_finish.post.tester.updatable", event => {
    let gold = Block.getBlock('minecraft:gold_block')
    let diamond = Block.getBlock('minecraft:diamond_block')
    let netherite = Block.getBlock('minecraft:netherite_block')
    let controller = event.getRecipeLogic().controller
    let iron = Block.getBlock('minecraft:iron_block')
    let level = event.getRecipeLogic().controller.self().getLevel()

    let poses = controller.getMultiblockState().getCache()
    for (const pos of poses) {
        var find = false
        var block = level.getBlockState(pos).getBlock()
        if (diamond.equals(block)) {
            level.setBlock(pos, gold.defaultBlockState(), 3)
            break;
        }
        if (netherite.equals(block)) {
            level.setBlock(pos, diamond.defaultBlockState(), 3)
            break;
        }

    }
})