Repository navigation
KubeJS Tutorial
This example lets a player use an amethyst shard to convert 5 raw magic into 5,000 survey aether. The player can then use a spyglass to spend 1,000 aether on a minute of Crackle Ley Vision. Both actions use the nearest eligible nexus at the player’s position.
Use the NeoForge 1.21.1 stack. The scripting bridge was tested with KubeJS 2101.7.2-build.381 and Rhino 2101.2.7-build.85. Use the matching dependencies listed by the KubeJS file. Put the scripts on the dedicated server or in the local pack instance. KubeJS file and dependencies · Rhino build 85
Save this as kubejs/startup_scripts/ley_currency.js.
StartupEvents.init(() => {
LeyLines.registerCurrency('kubejs:survey_aether', '1000')
})Restart the Minecraft client for single-player or the entire dedicated server for multiplayer. Startup registration runs before the currency catalogue freezes. Run /skysleylines rates as an operator and look for kubejs:survey_aether with a saved rate of 1,000 per raw and installed=true.
Save this as kubejs/server_scripts/ley_survey.js.
ItemEvents.rightClicked('minecraft:amethyst_shard', event => {
if (event.hand.name() !== 'MAIN_HAND') return
const player = event.player
const pos = player.blockPosition()
const result = LeyLines.convertAt(player.serverLevel(), pos.x, pos.y, pos.z,
'kubejs:survey_aether', '5', 'kubejs:survey_converter', player)
player.tell('Ley conversion: ' + result.get('status'))
})
ItemEvents.rightClicked('minecraft:spyglass', event => {
if (event.hand.name() !== 'MAIN_HAND') return
const player = event.player
const pos = player.blockPosition()
const result = LeyLines.spendAt(player.serverLevel(), pos.x, pos.y, pos.z,
'kubejs:survey_aether', '1000', 'kubejs:survey_vision', player)
if (result.get('succeeded')) {
LeyLines.grantVision(player, 'kubejs:survey_vision', 20 * 60, 'skysleylines:crackle')
event.cancel()
} else {
player.tell('Ley payment: ' + result.get('status'))
}
})Use /reload after editing this server script. The hand check keeps the example tied to the main-hand action. The example uses the items as reusable triggers, so every qualifying right-click can attempt another payment. A pack that needs a cooldown should check it before spending.
- In the Overworld, run
/skysleylines locate nexusas an operator. Move to a crossing, then use/skysleylines accountto check that you are within reach. Use the same spot for both interactions. - With an empty survey balance, aim into the air and right-click with the spyglass. You should see
INSUFFICIENT_CURRENCY. - Aim into the air and right-click once with the amethyst shard in your main hand. Expect
SUCCESSand 5,000 survey aether in the account at the default rate. - Use the spyglass once. Expect Crackle vision and a 4,000 aether balance. The effect lasts 1,200 server ticks. At 20 ticks per second this is one minute.
- Leave the nexus and repeat the attempt. Expect
NO_NEXUS. If testing with an operator account, run/skysleylines vision offfirst so the operator toggle does not keep the overlay visible after the script grant expires.
For a machine interaction, pass the machine’s actual block coordinates instead of the player’s feet. Pass the player as the actor when a player initiated the action. A timer or automated machine can omit the actor. Check the result before granting an item, starting a machine, or casting a spell. KubeJS Reference
Keep kubejs:survey_aether stable across updates. Editing '1000' in the startup file and restarting changes the configured rate. Existing worlds keep their saved rate until an operator previews and applies a migration. Removing the startup definition retains the balance as inactive. Restoring the same ID reactivates it at its saved rate. Configuration and Save Data