#Advise for adding custom blocks in batch
31 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
StartupEvents.registry('block', event => {
function createBlocks(event, blocks) {
blocks.forEach((block) => {
const block_event = event
.create(block.name)
.displayName(block.display_name)
.material(block.material)
.hardness(block.hardness)
.resistance(block.resistance)
.requiresTool(block.requires_tool)
if (block.mineable_tool) {
block_event.tagBlock(`minecraft:mineable/${block.mineable_tool}`);
}
if (block.mining_level) {
block_event.tagBlock(`minecraft:needs_${block.mining_level}_tool`);
}
if (block.requires_model) {
block_event.model(`kubejs:block/${block.name}`);
} else {
block_event.textureAll(`kubejs:block/${block.name}`);
}
if (block.variants) {
block.variants.forEach((variant) => {
let variant_event = event.create(block.name + "_" + variant, variant)
.material(block.material)
.hardness(block.hardness)
.resistance(block.resistance)
.requiresTool(block.requires_tool)
.tagBlock(`minecraft:mineable/${block.mineable_tool}`);
if (block.mining_level) {
variant_event.tagBlock(`minecraft:needs_${block.mining_level}_tool`);
}
variant_event.model(`kubejs:block/${block.name}` + "_" + variant);
});
}
});
}
createBlocks(event, blocksToAdd);
})
Discord cut me off, but this would be an example of the input:
let values = [{
name: "charcoal_block",
display_name: "Charcoal Block",
material: "stone",
hardness: 5,
resistance: 6,
requires_tool: true,
mineable_tool: "pickaxe",
item_properties: {
burn_time: 16000
}
},
{
name: "netherrack_bricks",
display_name: "Netherrack Bricks",
material: "mud_bricks",
hardness: 1.5,
resistance: 3,
requires_tool: true,
mineable_tool: "pickaxe",
variants: ["slab", "stairs", "wall"]
},
{
name: "false_diamond_block",
display_name: "False Diamond Block",
material: "copper",
hardness: 3,
resistance: 6,
requires_tool: true,
mineable_tool: "pickaxe",
mining_level: "stone",
variants: ["slab", "stairs"]
}
]
Ok so, what exactly do i want? first: is there a way to add well, "item properties" to a block at the moment of its creation? It'd be useful for things like make wooden items act like fuel
Second, is there an ergonomic way to make "stair" and "slab" type blocks just take a simple texture and apply it all over the block by default? Making model files can be a bit cumberstone, and not all blocks need them that much
This is how i am doing it right now, placing model files on these locations
> find . -type f -iname "netherrack*"
./kubejs/models/block/netherrack_bricks_slab.json
./kubejs/models/block/netherrack_bricks_slab_top.json
./kubejs/models/block/netherrack_bricks_stairs.json
./kubejs/models/block/netherrack_bricks_stairs_inner.json
./kubejs/models/block/netherrack_bricks_stairs_outer.json
./kubejs/models/block/netherrack_bricks_wall.json
./kubejs/models/block/netherrack_bricks_wall_post.json
./kubejs/models/block/netherrack_bricks_wall_side.json
./kubejs/models/block/netherrack_bricks_wall_side_tall.json
./kubejs/textures/block/netherrack_bricks.png
Third, i know this function is probably ugly, i don't really know Javascript, what's a good way to improve it, make it less atrocious to read?
for 2 use the slab/wall/stair type
event.create(id, 'slab'), or 'wall' for wall
all types are available on the wiki
??kjswiki
You can make custom blocks with KubeJS, and the wiki has a page on them!
by default kubejs creates a display name from from the id. For all of the examples you posted have the provided display name the same as the one that would be auto generated
Hi, seems like you're right, this is based on an old 1.16ish script i'm using as reference, i'll have get rid of those fields eventually
Hi, sorry i didn't reply oportunely, but i already did that in the script i posted (that's what the variant variable does), my doubt was if there was a simpler way to apply textures to one of these special blocks, other than using the model() method, because is a bit cumberstone
it uses the texture you pass in to .texture()
or if you dont pass one it uses one constructed from the id
Hi, sorry for not closing this, i've been busy, but just to end it all for now, is there a way to do this specifically? Or do i have to create the block then use the Item event to modify it separately?
You can make custom blocks with KubeJS, and the wiki has a page on them!
.item(item => item.texture('foo:bar'))
Oh, i get this one, what i am looking for is adding properties that would be reserved for items within the same StartupEvent i use to create the blocks themselves instead of having to make another, I.e. i have a bunch of wood based block and want them all to act as furnace fuel at the same rate vanilla planks do (so smelt 1.5 items per plank) but also have some blocks that would like to stack up to 16 only on their item form for the sake of consistency (like vanilla signs) doing all of that on a single loop, the same i am using to create them
The KubeJS legacy documentation mentions the existence of an Item() function available when you create new blocks, but i am too dumb to use it in this context 
thats what i just told you to use
the item variable is exactly the same as an item builder from the item registry event
texture() is just an example of a method you could call on it
Touche, i am blind
thanks, and sorry
Farewell random thread
/ticket close