Skip to main content

beJS

Download: CurseForge

The custom BlockEntity event is a startup event.

Custom BlockEntities are created in a startup script. They cannot be reloaded without restarting the game. The event is not cancellable.

all valid methods:

    //addValidBlock('block_id') Listen to Block registry event StartupEvents.registry('block', event => { //registering with block builder event.create('example_block', 'entity' /*has to be here for the BE builder to work*/).material('wood').hardness(1.0).displayName('Example Block') .entity(builder => { // adds a BlockEntity onto this block builder.ticker((level, pos, state, be)blockEntity) => {...)
    //loadCallback((level, apos, tickblockEntity, method, called on block entity tick if(!level.isClientSide) { // ALWAYS check side, the tick method is called on both CLIENT and SERVER if(level.levelData.gameTime % 20tag) ==> 0)...) { if(level.getBlockState(pos.above()) == Blocks.AIR.defaultBlockState()) { level.setBlock(pos.above(),Blocks.GLASS.defaultBlockState(), 3) } else { level.setBlock(pos.above(), Blocks.AIR.defaultBlockState(), 3) } } } }).saveCallback((level, pos, be,blockEntity, tag) => {...) //hasGui() calledonly onworks BlockEntityif save,ScreenJS don'tis seeinstalled! why you would ever need these tbf, but they're here tag.putInt("tagValueAa", be.getPersistentData().getInt('progress')) }).loadCallback((level, pos, be, tag) => { // called on BlockEntity load, same as above be.getPersistentData().putInt("progress", tag.getInt("tagValueAa")) }).defaultValues(tag => tag...) =itemHandler(capacity) {energyHandler(capacity, progress:maxReceive, 0,maxExtract) example_value_for_extra_saved_data:fluidHandler(capacity, '0mG this iz Crazyyy'}) // adds a 'default' saved value, added on block entity creation (place etc) // [1st param: CompoundTag consumer] .addValidBlock('example_block') // adds a valid block this can attach to, useless in normal circumstances (except if you want to attach to multible blocks (or if you initialize the blockEntity separate from the block)) .hasGui() // if ScreenJS is installed, marks this blockentity as having a GUI, doesn't do anything otherwise .itemHandler(27) // adds a basic item handler to this block entity, use something like PowerfulJS for more advanced functionality // [1st param: slot count] .energyHandler(10000, 1000, 1000) // adds a basic FE handler, same as above // [1st param: max energy, 2nd param: max input, 3rd param: max output] .fluidHandler(1000, stackfluidStack => true)isValid) // adds a basic fluid handler // [1st param: max amount, 2nd param: fluid filter] }) })


     

    currently nonfunctional

    alternatively, you can create the BlockEntity separately and attach it with EntityBlockJS.Builder#entity('kubejs:be_id')

    StartupEvents.registry('block_entity_type', event => {
    	event.create('example_block')
    	.ticker((level, pos, state, be) => { // a tick method, called on block entity tick
           if(!level.isClientSide) { // ALWAYS check side, the tick method is called on both CLIENT and SERVER
               if(level.getGameTime() % 20 === 0) {
                   if(level.getBlockState(pos.above()) === Blocks.AIR.defaultBlockState()) {
                       level.setBlock(pos.above(),Blocks.GLASS.defaultBlockState(), 3)
                   } else {
                       level.setBlock(pos.above(), Blocks.AIR.defaultBlockState(), 3)
                   }
               }
               BE_LOGGER.info('aaa aaa') // Send a line into the beJS logger, don't see a need for this tbf
           }
        }).saveCallback((level, pos, be, tag) => { // called on BlockEntity save, don't see why you would ever need these tbf, but they're here
            tag.putInt("tagValueAa", be.getPersistentData().getInt('progress'))
        }).loadCallback((level, pos, be, tag) => { // called on BlockEntity load, same as above
              be.getPersistentData().putInt("progress", tag.getInt("tagValueAa"))
        }).defaultValues(tag => tag = { progress: 0, example_value_for_extra_saved_data: '0mG this iz Crazyyy'}) // adds a 'default' saved value, added on block entity creation (place etc)
                                                                                                                  // [1st param: CompoundTag consumer]
        .addValidBlock('example_block') // adds a valid block this can attach to, useless in normal circumstances (except if you want to attach to multible blocks)
        .hasGui() // if ScreenJS is installed, marks this blockentity as having a GUI, doesn't do anything otherwise
        .itemHandler(27) // adds a basic item handler to this block entity, use something like PowerfulJS for more advanced functionality
                         // [1st param: slot count]
        .energyHandler(10000, 1000, 1000) // adds a basic FE handler, same as above
                                          // [1st param: max energy, 2nd param: max input, 3rd param: max output]
        .fluidHandler(1000, stack => true) // adds a basic fluid handler
                              	            // [1st param: max amount, 2nd param: fluid filter]
    })