Created
February 26, 2023 14:36
-
-
Save screret/e4b95c65da3960d9740f95cde6406f08 to your computer and use it in GitHub Desktop.
beJS multiblock example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
StartupEvents.registry('block', event => { | |
let CAP_PREDICATE = be => { | |
return be != null && (be.getCapability(ForgeCapabilities.ITEM_HANDLER).present || be.getCapability(ForgeCapabilities.FLUID_HANDLER).present || be.getCapability(ForgeCapabilities.ENERGY).present) | |
} | |
event.create('multi_block', 'multiblock').material('wood').hardness(1.0).displayName('Multiblock') | |
.entity(builder => { // adds a BlockEntity onto this block | |
builder.ticker((level, pos, state, be) => { // a tick method, called on block entity tick | |
if(!level.clientSide) { // ALWAYS check side, the tick method is called on both CLIENT and SERVER | |
if(level.levelData.gameTime % 20 == 0) { | |
let offset = pos.offset(state.getValue(BlockProperties.HORIZONTAL_FACING).normal) | |
if(level.getBlockState(offset) === Blocks.AIR.defaultBlockState()) { | |
level.setBlock(offset, Blocks.GLASS.defaultBlockState(), 3) | |
} else { | |
level.setBlock(offset, Blocks.AIR.defaultBlockState(), 3) | |
} | |
} | |
} | |
}) | |
.pattern(builder => { | |
builder | |
.aisle( 'BBB', | |
'ACA', | |
'AAA') | |
.aisle( 'BBB', | |
'AAA', | |
'AAA') | |
.aisle( 'BBB', | |
'AAA', | |
'AAA') | |
.where('A', BlockInWorld.or(BlockInWorld.hasState(BlockPredicate.forBlock('minecraft:iron_block')), BlockInWorld.hasBlockEntity(CAP_PREDICATE))) | |
.where('C', BlockInWorld.hasState(BlockPredicate.forBlock('kubejs:multi_block'))) | |
.where('B', BlockInWorld.hasState(BlockPredicate.forBlock('minecraft:copper_block'))) | |
}) | |
}) | |
.property(BlockProperties.HORIZONTAL_FACING) | |
.defaultState(state => { | |
state.setValue(BlockProperties.HORIZONTAL_FACING, Direction.NORTH) | |
}) | |
.placementState(state => { | |
state.setValue(BlockProperties.HORIZONTAL_FACING, state.horizontalDirection.opposite) | |
}) | |
}) | |
StartupEvents.registry('recipe_type', event => { | |
event.create('multi_block') | |
.assembler((recipe, container) => { | |
let results = recipe.results | |
for (let i = 0; i < results.size(); ++i) { | |
container.setItem(i, results.get(i)) | |
} | |
}) | |
.maxInputs(2) | |
.maxOutputs(4) | |
.toastSymbol('kubejs:multi_block') | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// priority: 0 | |
ServerEvents.recipes(event => { | |
// type is: event.recipes.kubejs.<recipetype> | |
// syntax is: [outputs], [inputs], etc | |
event.recipes.kubejs.multi_block( | |
['3x minecraft:dirt', '1x minecraft:grass', '5x kubejs:example_block', '2x minecraft:cobblestone'], | |
['1x minecraft:stone']) | |
.energy(1000) | |
.time(100) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment