Skip to main content

Custom Blocks


This is a startup script.

onEvent('block.registry', event => {
  event.create('test_block')
  	   .material('glass')
       .hardness(0.5)
       .displayName('Test Block') // No longer required in 1.18.2+
       .tagBlock('minecraft:mineable/shovel') // Make it mine faster using a shovel in 1.18.2+
  	   .tagBlock('minecraft:requires_iron_tool'needs_iron_tool') // Make it require an iron or higher level tool on 1.18.2+
  	   .requiresTool(true) // Make it require a tool to drop ay loot
  
  // Block with custom type (see below for list of types)
  event.create('test_block_slab', 'slab').material('glass').hardness(0.5)
})


The texture for this block has to be placed in kubejs/assets/kubejs/textures/block/test_block.png.
If you want a custom block model, you can create one in Blockbench and put it in kubejs/assets/kubejs/models/block/test_block.json.


List of available materials - to change break/walk sounds and to change some properties.

Materials (1.18.2)
air
wood
stone
metal
grass

dirt

water
lava
leaves
plant
sponge
wool
sand
glass
explosive
ice
snow
clay
vegetable
dragon_egg
portal
cake
web
slime
honey
berry_bush
lantern


Other methods block builder supports: 

  • displayName('name')
    • Not required for 1.18.2+
  • material('material')
    • See list above
  • type('basic')
    • See available types below.
    • Do not use for 1.18.2, use the syntax in the second example above
  • hardness(float)
    • >= 0.0
  • resistance(float)
    • >= 0.0
  • unbreakable() 
    • Sets the resistance to MAX_VALUE and hardness to -1, like bedrock
  • lightLevel(int) 
    • 0.0 - 1.0
  • harvestTool('tool', level) 
    • Available tools: pickaxe, axe, hoe, shovel
    • level >= 0
    • Not used in 1.18.2+, see tag in example above
  • opaque(boolean)
  • fullBlock(boolean)
  • requiresTool(boolean)
  • renderType('type')
    • Available types: solid, cutout, translucent
    • cutout required for blocks with texture like glass
    • translucent required for blocks like stained glass
  • color(tintindex, color)
  • textureAll('texturepath')
  • texture('side', 'texturepath')
  • model('modelpath')
  • noItem()
  • box(x0, y0, z0, x1, y1, z1, true) 
    • 0.0 - 16.0
    • default is (0,0,0,16,16,16, true)
  • box(x0, y0, z0, x1, y1, z1, false)
    • Same as above, but in 0.0 - 1.0 scale
    • default is (0,0,0,1,1,1, false)
  • noCollision()
  • notSolid()
  • waterlogged()
  • noDrops()
  • slipperiness(float)
  • speedFactor(float)
  • jumpFactor(float)
  • randomTick(randomTickEvent => {})
    • see below
  • item(itemBuilder => {})
  • setLootTableJson(json)
  • setBlockstateJson(json)
  • setModelJson(json)
  • noValidSpawns(boolean)
  • suffocating(boolean)
  • viewBlocking(boolean)
  • redstoneConductor(boolean)
  • transparent(boolean)
  • defaultCutout()
    • batches a bunch of methods to make blocks such as glass
  • defaultTranslucent()
    • similar to defaultCutout() but using translucent layer instead
  • tagBlock('forge:something')
    • adds a block tag
  • tagItem('forge:something_better')
    • adds an item tag
  • tagBoth('forge:something')
    • adds both block and item tag
Event callbacks:

RandomTickEvent:

  • BlockContainerJS block
  • Random random
  • LevelJS getLevel()
  • ServerJS getServer()
Types
  • basic
  • detector 
  • slab
  • stairs
  • fence
  • fence_gate
  • wall
  • wooden_pressure_plate
  • stone_pressure_plate
  • wooden_button
  • stone_button
  • falling
  • crop

Detector Block Types:

The detector block type can be used to run code when the block is powered with redstone signal.

Startup script code:

onEvent('block.registry', event => {
  event.create('test_block','detector').detectorId('myDetector')
}

Server script code:

onEvent('block.detector.myDetector.unpowered', event => { // you can also use powered and changed instead of upowered
        event.block.set('tnt')
}