#Custom KubeJS "has_origin" condition isn't working

7 messages · Page 1 of 1 (latest)

hard gate
#

I'm trying to make a custom condition for the Palladium mod that will let me detect whatever Origin (from the Origins Mod) a player has but It's not working. There's no errors or anything on the logs and even the debug message isn't working, I'm not great at JavaScript or this mod so I'm hoping that someone knows what the issue is:

Script (lives in addon/origins/kubejs_scripts):

const $OriginLayer = Java.loadClass('io.github.apace100.origins.origin.OriginLayer');
const $OriginLayers = Java.loadClass('io.github.apace100.origins.origin.OriginLayers');
const $ModComponents = Java.loadClass('io.github.apace100.origins.registry.ModComponents');
const $Origin = Java.loadClass('io.github.apace100.origins.origin.Origin');

/**
 * @param {Internal.Entity} entity
 * @param {string} originLayerString
 */
function getOrigin(entity, originLayerString) {
    let originLayer = $OriginLayers.getLayer(originLayerString ?? 'origins:origin');
    let origin = $ModComponents.ORIGIN.get(entity).getOrigin(originLayer);

    return origin.getIdentifier();
}

StartupEvents.registry('palladium:condition_serializer', (event) => {
    event.create('origins:has_origin')
        .test((entity, json) => {
            if (!entity.isPlayer()) return false;
            let requiredOrigin = json.origin;
            let originLayer = json.layer ?? 'origins:origin';
            return getOrigin(entity, originLayer).toString() === requiredOrigin;
        });
});
chrome crestBOT
#

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

hard gate
#

JSON For Testing (lives in data/origins/palladium/powers/test.json):

{
    "name": "Origin Test Power",
    "background": "minecraft:textures/block/red_wool.png",
    "icon": "minecraft:apple",
    "abilities": {
      "origin_check": {
        "type": "palladium:dummy",
        "icon": "minecraft:blaze_rod",
        "title": "Origin Checker",
        "bar_color": "light_gray",
        "hidden": false,
        "hidden_in_bar": false,
        "list_index": -1,
        "gui_position": "null",
        "description": "Checks if the player has a specific Origin.",
        "conditions": {
          "unlocking": [
            {
              "type": "origins:has_origin",
              "origin": "origins:human",
              "layer": "origins:origin"
            }
          ]
        }
      }
    }
}
#

Script With Debug Message (also not working):

const $OriginLayer = Java.loadClass('io.github.apace100.origins.origin.OriginLayer');
const $OriginLayers = Java.loadClass('io.github.apace100.origins.origin.OriginLayers');
const $ModComponents = Java.loadClass('io.github.apace100.origins.registry.ModComponents');

/**
 * @param {Internal.Entity} entity
 * @param {string} originLayerString
 */
function getOrigin(entity, originLayerString) {
    if (!entity || !entity.isPlayer()) {
        console.log("[KubeJS] Entity is not a player.");
        return null;
    }

    let originLayer = $OriginLayers.getLayer(originLayerString ?? 'origins:origin');
    let origin = $ModComponents.ORIGIN.get(entity).getOrigin(originLayer);
    
    console.log(`[KubeJS] Player ${entity.getName()} has origin: ${origin.getIdentifier()}`);

    return origin.getIdentifier();
}

StartupEvents.registry('palladium:condition_serializer', (event) => {
    console.log("[KubeJS] Registering condition origins:has_origin");
    
    event.create('origins:has_origin')
        .test((entity, json) => {
            if (!entity.isPlayer()) {
                console.log("[KubeJS] Condition failed: Entity is not a player.");
                return false;
            }

            let requiredOrigin = json.origin;
            let originLayer = json.layer ?? 'origins:origin';
            let playerOrigin = getOrigin(entity, originLayer);

            let result = playerOrigin ? playerOrigin.toString() === requiredOrigin : false;
            console.log(`[KubeJS] Condition check: Required=${requiredOrigin}, Found=${playerOrigin}, Result=${result}`);
            
            return result;
        });
});
hard gate
#

This is what I followed

hard gate