#Advise for adding custom blocks in batch

31 messages · Page 1 of 1 (latest)

ivory swift
#

Hi, sorry for bothering, i've been trying to make a function that automates adding a long list of custom blocks in a single go. I think it'd get some improvements. It'll be easier to explain if i show off the script first then i elaborate:

mighty adderBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

ivory swift
#
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?

glad violet
#

for 2 use the slab/wall/stair type
event.create(id, 'slab'), or 'wall' for wall
all types are available on the wiki

#

??kjswiki

atomic ginkgoBOT
glad violet
#

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

ivory swift
#

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

ivory swift
glad violet
#

it uses the texture you pass in to .texture()

#

or if you dont pass one it uses one constructed from the id

ivory swift
glad violet
#

there is

#

??kjswiki

atomic ginkgoBOT
glad violet
#

.item(item => item.texture('foo:bar'))

ivory swift
#

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 SadFingerguns

glad violet
#

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

ivory swift
#

Farewell random thread

#

/ticket close