Custom Blocks
This is a startup script, meaning that you will need to restart your game each time you want to make changes to it.
You can register many types of custom blocks in KubeJS. Here's the simplest way:
StartupEvents.registry("block", (event) => {
event.create("example_block") // Create a new block with ID "kubejs:example_block"
})
That's it! Launch the game, and assuming you've left KubeJS's auto-generated resources alone, there should be a fully-textured block in the Creative menu under KubeJS (purple dye). KubeJS will also generate the name "Example Block" for you.
To make modifications to this block, we use the block builder returned by the event.create() call. The block builder allows us to chain together multiple modifications. Let's try making some of the more common modifications:
StartupEvents.registry("block", (event) => {
event.create("example_block") // Create a new block
.displayName("My Custom Block") // Set a custom name
.material("wood") // Set a material (affects the sounds and some properties)
.hardness(1.0) // Set hardness (affects mining time)
.resistance(1.0) // Set resistance (to explosions, etc)
.tagBlock("my_custom_tag") // Tag the block with `#minecraft:my_custom_tag` (can have multiple tags)
.requiresTool(true) // Requires a tool or it won't drop (see tags below)
.tagBlock("my_namespace:my_other_tag") // Tag the block with `#my_namespace:my_other_tag`
.tagBlock("mineable/axe") //can be mined faster with an axe
.tagBlock("mineable/pickaxe") // or a pickaxe
.tagBlock('minecraft:needs_iron_tool') // the tool tier must be at least iron
})
All Block Builder Methods
In case it wasn't covered above, here's list of each method you can use when building a block.
displayName('name')
material('material')
Materials List
air
amethyst
bamboo
bamboo_sapling
barrier
bubble_column
buildable_glass
cactus
cake
clay
cloth_decoration
decoration
dirt
egg
explosive
fire
froglight
frogspawn
glass
grass
heavy_metal
ice
ice_solid
lava
leaves
metal
moss
nether_wood
piston
plant
portal
powder_snow
replaceable_fireproof_plant
replaceable_plant
replaceable_water_plant
sand
sculk
shulker_shell
snow
sponge
stone
structural_air
top_snow
vegetable
water
water_plant
web
wood
wool
Properties List
Boolean Properties (true/false):
attached,
berries,
bloom,
bottom,
can_summon,
conditional,
disarmed,
down,
drag,
east,
enabled,
extended,
eye,
falling,
hanging,
has_book,
has_bottle_0,
has_bottle_1,
has_bottle_2,
has_record,
inverted,
in_wall,
lit,
locked,
north,
occupied,
open,
persistent,
powered,
short,
shrieking,
signal_fire,
snowy,
south,
triggered,
unstable,
up,
vine_end,
waterlogged,
west
Integer properties:
age_1,
age_2,
age_3,
age_4,
age_5,
age_7,
age_15,
age_25,
bites,
candles,
delay,
distance,
eggs,
hatch,
layers,
level,
level_cauldron,
level_composter,
level_flowing,
level_honey,
moisture,
note,
pickles,
power,
respawn_anchor_charges,
rotation_16,
stability_distance,
stage
Directional Properties:
facing,
facing_hopper,
horizontal_facing,
vertical_direction
Other (enum) Properties:
attach_face,
axis,
bamboo_leaves,
bed_part,
bell_attachment,
chest_type,
door_hinge,
double_block_half,
dripstone_thickness,
east_redstone,
east_wall,
half,
horizontal_axis,
mode_comparator,
north_redstone,
north_wall,
noteblock_instrument,
orientation,
piston_type,
rail_shape,
rail_shape_straight,
sculk_sensor_phase,
slab_type,
south_redstone,
south_wall,
stairs_shape,
structureblock_mode,
tilt,
west_redstone,
west_wall
tagBlock('namespace:tag_name')
tagItem('namespace:tag_name')
tagBoth('namespace:tag_name')
hardness(float)resistance(float)unbreakable()
lightLevel(number)
Passing a float (0.0-1.0) will multiply that number by 15, then set the block's light level to the nearest integer
opaque(boolean)
fullBlock(boolean)
.box() to make a custom hitbox, please set this to false.
requiresTool(boolean)
true, the block will use certain block tags to determine whether it should drop an item when mined. For example, a block tagged with #minecraft:mineable/axe, #minecraft:mineable/pickaxe, and #minecraft:needs_iron_tool would drop nothing unless it was mined with an axe or pickaxe that was at least iron level.
renderType('solid'|'cutout'|'translucent')
cutout is required for blocks with texture like glass, where pixels are either transparent or nottranslucent is required for blocks like stained glass, where pixels can be semitransparentotherwise, use
solid if all pixels in your block are opaque.
color(tintindex, color)
textureAll('texturepath')
kubejs:block/texture_name (which would be included under kubejs/assets/kubejs/textures/block/texture_name.png).
Defaults to kubejs:block/<block_name>
texture('side', 'texturepath')up, down, north, south, east, and west.
model('modelpath')
kubejs:block/texture_name (which would be included under kubejs/assets/kubejs/models/block/texture_name.png).
Defaults to kubejs:block/<block_name>.
noItem()
box(x0, y0, z0, x1, y1, z1, boolean)
Each box is a rectangular prism with corners at (x0,y0,z0) and (x1,y1,z1) You will probably want to set up a custom block model that matches the shape you define here. The final boolean determines the coordinate scale of the box. Passing in
true will use the numbers 0-15, while passing in false will use coordinates ranging from 0.0 to 1.0
noCollision()
notSolid()
waterlogged()
noDrops()
slipperiness(float)
speedFactor(float)
jumpFactor(float)
randomTick(consumer<randomTickEvent>)
item(consumer<itemBuilder>)
setLootTableJson(json)
setBlockstateJson(json)
setModelJson(json)
noValidSpawns(boolean)
true, the block is not counted as a valid spawnpoint for entities
suffocating(boolean)
viewBlocking(boolean)
redstoneConductor(boolean)
transparent(boolean)
defaultCutout()
defaultTranslucent()