#wanting KJS to not wrap `java.lang.Character` to `string`

4 messages · Page 1 of 1 (latest)

agile wyvern
#

doing stuff with Patchouli's API to validate multiblocks, and i'm wanting to make it possible to have simpler definitions closer to the patchouli guidebook ones, but it seems to specifically want a map with Character as the key, and KJS seems to be trying to wrap that as string when i use it as a key, do i have to make a java map or something? or do i have to give up on the simple definitions?

i saw #1141908567004287008 message when looking for things about java.lang.Character, but that's using startup scripts, which currently my script structure does not, it is only using server_scripts.
i also had troubles trying to use a new Character() as a key in a map definition directly, instead of trying to iterate and translate.

the following codeblock is a multiblock definition being handled in a separate server_scripts file

registerMultiblock('cloning_machine', [
        ['A A A'],
        ['AA0AA'],
        ['A A A']
    ],
    {
        '0': 'cobblemoneternal:cloning_machine_core',
        'A': 'minecraft:iron_block'
})```

more details can be provided if requested.
silent juniperBOT
#

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

autumn fjordBOT
#

[➤](#1141908567004287008 message)
Patchouli has a system that lets you define and register multiblocks, which can be used in books but can also be used to do various other things, like validating them in the world.

Example
In startup scripts:

const $PatchouliAPI = Java.loadClass('vazkii.patchouli.api.PatchouliAPI')
const $Character = Java.loadClass('java.lang.Character')

// space for air, underscore (_) for any block. https://vazkiimods.github.io/Patchouli/docs/patchouli-basics/multiblocks
const EXAMPLE_MULTIBLOCK = () => $PatchouliAPI.get().makeMultiblock(
    [
        [
            ' W ',
            'W0W',
            ' W '
        ],
        [
            'WWW',
            'WWW',
            'WWW'
        ]
    ],
    // this is very cursed but it works
    new $Character('W'), Block.getBlock('minecraft:oak_planks'),
    new $Character('0'), Block.getBlock('minecraft:diamond_block')
)


// allow server scripts to access
global.MULTIBLOCKS = {
    EXAMPLE: EXAMPLE_MULTIBLOCK
}

StartupEvents.init(event => {
    $PatchouliAPI.get().registerMultiblock(ResourceLocation('kubejs:example'), EXAMPLE_MULTIBLOCK())
    
})

in server scripts

BlockEvents.rightClicked('minecraft:diamond_block', event => {
    if(event.getItem() != 'minecraft:iron_ingot' || event.getLevel().isClientSide()) {
        return
    }

    let pos = event.getBlock().getPos()
    let level = event.getLevel()

    // returns first valid rotation (net.minecraft.world.level.block.Rotation) that is valid, or null if none are valid
    let rotation = global.MULTIBLOCKS.EXAMPLE().validate(level, pos)
    if(rotation === null) {
        return
    }

    console.info('clicked on multiblock!')
    event.getPlayer().swing()
    level.setBlock(pos, Block.getBlock('minecraft:iron_block').defaultBlockState(), 3)
})

I am still very new to KubeJS so feel free to pick this apart or optimize it a bit (the char thing is very cursed i know)

#

Paste version of static_manager.js from @agile wyvern