#Jade Tooltips with KubeJS Addition

36 messages · Page 1 of 1 (latest)

crystal remnant
#

The script that I have works for Integers but the one I'm trying to get to is wrapped in a component (specifically auto-serial: {recipeProgress})

How do I modify the script so that it works with components? Thanks in advance!

startup:

let $BlockEntity = Java.loadClass('net.minecraft.world.level.block.entity.BlockEntity')

JadeEvents.onCommonRegistration((event) => {
    const manaNbtKeys = ["recipeProgress"];
    event.blockDataProvider("kubejs:recipe_progress", $BlockEntity).setCallback((tag, accessor) => {
        const { blockEntity } = accessor;

        manaNbtKeys.forEach((key) => {
            if (blockEntity[key] != null) {
                tag.putInt(key, blockEntity[key]);
            }
        });
    });
});```

client:
```js
let $Block = Java.loadClass('net.minecraft.world.level.block.Block')

JadeEvents.onClientRegistration((event) => {
    event.block('kubejs:recipe_progress', $Block).tooltip((tooltip, accessor) => {
        const { serverData } = accessor
        if (!serverData) return

        let recipeProgress = serverData.get('recipeProgress')

        if (recipeProgress) {
            tooltip.add(`§bRecipe Progress: ${recipeProgress}`)
        }
    })
})```
plucky cometBOT
#

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

crystal remnant
crystal remnant
#

bump

crystal remnant
#

I wonder

#

@opaque lintel can you help with code stuff?

opaque lintelBOT
#

Gnome cannot help with code stuff directly. If you need help with KubeJS, please go to #1254790121807548437 and #1047320998199955458 and open a ticket

crystal remnant
#

Bleg

south hazel
#

no idea about how any of this works, but just to be sure, you do have the KubeJS additions mod right?

crystal remnant
#

Yes

#

I literally said it works in the post

#

My problem is pulling from nested tags

dense cairn
#

@bold vigil

#

are you the kubejs additions dev?

bold vigil
#

Yes I am, what's up?

#

Ah, give me a sec to pull up which class it is using for this

#

Which side of the NBT is the auto-serialize coming from?

#

Is it on the startup side?
Because you can do tag.getCompound("auto-serial").getInt("recipeProgress").
But if it is on the client side...

#
let $Block = Java.loadClass('net.minecraft.world.level.block.Block')

JadeEvents.onClientRegistration((event) => {
    event.block('kubejs:recipe_progress', $Block).tooltip((tooltip, accessor) => {
        const { serverData } = accessor
        if (!serverData) return

        if (!serverData.contains("auto-serial"))
            return;
        
        let serialData = serverData.getCompound("auto-serial");
        if (!serialData.contains("recipeProgress"))
            return;
        let recipeProgress = serialData.get('recipeProgress')

        if (recipeProgress) {
            tooltip.add(`§bRecipe Progress: ${recipeProgress}`)
        }
    })
})
#

The getCompound method lets you access nested compound tags

crystal remnant
# bold vigil ```js let $Block = Java.loadClass('net.minecraft.world.level.block.Block') Jade...

Client

let $Block = Java.loadClass('net.minecraft.world.level.block.Block')

JadeEvents.onClientRegistration((event) => {
    event.block('kubejs:recipe_progress', $Block).tooltip((tooltip, accessor) => {
        const { serverData } = accessor
        if (!serverData) return

        if (!serverData.contains("auto-serial"))
            return;
        
        let serialData = serverData.getCompound("auto-serial");
        if (!serialData.contains("recipeProgress"))
            return;
        let recipeProgress = serialData.get('recipeProgress')

        if (recipeProgress) {
            tooltip.add(`§bRecipe Progress: ${recipeProgress}`)
        }
    })
})```

Startup
```js
let $BlockEntity = Java.loadClass('net.minecraft.world.level.block.entity.BlockEntity')

JadeEvents.onCommonRegistration((event) => {
    const blockNbtKeys = ["auto-serial"];
    event.blockDataProvider("kubejs:recipe_progress", $BlockEntity).setCallback((tag, accessor) => {
        const { blockEntity } = accessor;

        blockNbtKeys.forEach((key) => {
            if (blockEntity[key] != null) {
                tag.putInt(key, blockEntity[key]);
            }
        });
    });
});```
#

I do believe i messed something up here

#

ig this instance doesn't need to be a forEach so let me try the startup one

crystal remnant
#

Negatory

#

I switched to using the example script on the wiki because that made more sense to me, but nope

#
// The following would go inside the startup scripts folder.

const $BLOCK_ENTITY = Java.loadClass('net.minecraft.world.level.block.entity.BlockEntity');

// Store a global function so that if we need to reload the function,
// we do not need to reload the game. Instead we can run /kubejs reload startup_scripts
global["JadeRecipeProgressCallback"] = (tag, accessor) => {
    // Refer to the Jade API for more information on what accessors are.
    // This specific accessor is a BlockAccessor.
    const blockEntity = accessor.getBlockEntity();
    // Return in case there is no block entity
    if (!blockEntity) return;
    // Return in case the Brushable Block entity does not have an item.
    if (!blockEntity.getCompound("auto-serial").getInt("recipeProgress")) return;
    // Return in case the Brushable Block entity has an empty item.
    // Store the item's name in the ServerData tag under the name "brushing_result".
    // Because we only need to conver the Item's name, we can convert the DisplayName componet
    // to a JSON object and store the string version of that in the tag.
    tag.putString("recipe_progress", blockEntity.getCompound("auto-serial").getInt("recipeProgress").toJson());
};

// This is the hook that will be called when the "IWailaPlugin" common registration event is fired.
// Refer to WailaCommonRegistrationEventJS for more information about the event.
JadeEvents.onCommonRegistration((event) => {
    // Register a new block data provider for the Brushable Block entity.
    event.blockDataProvider('kubejs:recipe_progress', $BLOCK_ENTITY)
            // Our data provider is useless without a callback function.
            .setCallback((tag, accessor) => {
                // Fire the global function we defined earlier.
                global["JadeRecipeProgressCallback"](tag, accessor);
            });
});```
#
// The following would go in the client scripts folder.
// This is a simple example on how to retrieve the data we registered in the startup scripts.

// Load the Block Class that you will be providing data for.
const $BLOCK_C = Java.loadClass('net.minecraft.world.level.block.Block');

// Store a global function so that if we need to reload the function,
// we do not need to reload the game. Instead we can run /kubejs reload client_scripts
global["JadeRecipeProgressClientCallback"] = (tooltip, accessor, pluginConfig) => {
    // Refer to the Jade API for more information on what accessors are.
    // Get the server data from the accessor.
    const {serverData} = accessor;
    // Return in case there is no server data.
    if (!serverData) return;
    // Return in case the server data does not contain the key "brushing_result".
    if (!serverData.contains("recipe_progress")) return;
    // Get the display name tag from the server data.
    // This should result in a StringTag being returned.
    const displayNameTag = serverData.get("recipe_progress");
    // Have the TextWrapper binding convert the StringTag into a TextComponent.
    const displayName = Text.of(displayNameTag);
    // If the display name is null, return.
    if (!displayName) return;
    // Add the display name to the tooltip.
    tooltip.add(Text.of(["Blabla: ", Text.of(displayName)]));
};

// This is the hook that will be called when the "IWailaPlugin" client registration event is fired.
// Refer to WailaClientRegistrationEventJS for more information about the event.
JadeEvents.onClientRegistration((event) => {
    // Register a new block component provider for the Brushable Block.
    event.block('kubejs:recipe_progress', $BLOCK_C)
            .tooltip((tooltip, accessor, pluginConfig) => {
                // Fire the global function we defined earlier.
                global["JadeRecipeProgressClientCallback"](tooltip, accessor, pluginConfig);
            });
});```
#

First one in client, second one is in startup

#

Normal logs aren't showing anything, but I can send the kjs logs if it need be

crystal remnant
#

I have been closing and reopening the game as opposed to doing /kjs reload startup_scripts

#

But I don't think that would be the problem

bold vigil
#

If you add some console.log messages before each return, you can trace where the code stops and figure out what is going wrong a lot easier

#

At a glance, it's difficult to say where the failure could be occuring

#

And when you are using the global function version, you can simple run /kjs reload startup_scripts and it should allow you to reload the event live instead of restarting.