#KubeJS Create Automation Examples

21 messages · Page 1 of 1 (latest)

polar bolt
#

https://www.curseforge.com/minecraft/mc-mods/kubejs-create-automation
KJSCAuto allows KubeJS scripts to modify key automation behaviors in Create.

  • Deployer item/tool usage
  • Basin recipe operations
  • Block breaking by drills and saws

These hooks were selected to address several common automation control issues I often see discussed in the KubeJS community. If you feel there are other Create behaviors that would benefit from script hooks, feel free to suggest them in the discussion forum.

Example Script:

Deploying tool without consuming durability.

KJSCAutoEvents.deployerUse(event => {
    var {block, outputs, heldItem} = event
    if(heldItem != "create:sand_paper") return //only works for sand paper
    if(!block.offset(0, -3, 0).blockState.is(Blocks.DIAMOND_BLOCK)) return; //only works when the belt/deposit (y = -2) has a diamond block below.
    event.setDamage(0) //set the durability usage to 0
    while(outputs.length > 0) outputs.remove(0) //remove all original outputs
    outputs.add(0, Item.of("diamond")) //add diamond
})

Mixing wool and red dye while not consuming the dye

This is to enable some "catalyst" like behavior.

KJSCAutoEvents.basinOperation(event => {
    var {basin, block, fluidOutputs, heatLevel, outputs, recipe} = event;
    if(recipe.getId().toString() == "minecraft:dye_red_wool"){
        event.addInput("red_dye")
    }
})

Protective Ground for Contraptions

Blocks placed on soul soil cannot be broken by contraption machines.

ContraptionEvents.beforeBlockDestroy(event => {
    const { level, targetPos } = event
    const below = level.getBlockState(targetPos.below())

    if (!below.is("minecraft:soul_soil")) return

    event.cancel() // prevent the contraption from breaking the block
})

1.21.1 has several changes so the script also needs some adjustment. Here's the example for 1.21.1 neoforge.
https://github.com/vomiter-scp-zh/KubeJS_Create_Automation/wiki/1.21-example

#

Conditional Silk Touch for Drills

Drills can gain a Silk Touch-like effect when a certain condition is met.
If an amethyst block is placed beneath the ore, the drill will drop the ore block itself instead of the normal drops.

//This works for stationary drill.
KJSCAutoEvents.blockDestroy(event => {
    const { level, targetPos, targetBlock } = event
    const below = level.getBlockState(targetPos.below())
    if (!below.is("minecraft:amethyst_block")) return
    if (!(targetBlock.blockState.is("minecraft:diamond_ore") || targetBlock.blockState.is("minecraft:emerald_ore")))return
    targetBlock.popItem(targetBlock.blockState.block.asItem())
    level.destroyBlock(targetPos, false)
    event.cancel()
})

//This works for drill on contraption.
ContraptionEvents.afterBlockDestroy(event => {
    const { level, targetPos, targetBlock, drops } = event
    const below = level.getBlockState(targetPos.below())
    if (!below.is("minecraft:amethyst_block")) return
    if (!(targetBlock.blockState.is("minecraft:diamond_ore") || targetBlock.blockState.is("minecraft:emerald_ore")))return
    while(drops.length > 0) { drops.remove(0) }
    drops.add(Item.of(targetBlock.blockState.block.asItem()))

})
zinc rivet
#

Interesting. Does this work for 1.21.1?

polar bolt
cyan forum
#

The before block destroy event is pretty cool, but isn't there already a block tag in create 6 that prevents contraptions from destroying certain blocks?

polar bolt
polar bolt
cyan forum
#

I like

#

Oh btw if you do cancel the block destroy event, what happens to the contraption?

polar bolt
polar bolt
#

But actually I couldn't test all types of contraption, so if you encounter any inconsistency, please report it as an issue.

cyan forum
polar bolt
cyan forum
polar bolt
#

I see. I'll look into the thing and check if there's some hook I can make.

polar bolt
polar bolt
#

@cyan forum

#

A new feature on 0.6.0