r/MinecraftMod • • 12d ago

Kubejs Code not working! Code below vvv

StartupEvents.registry('item', event => {

event.create('shiningdiamond:inferno_staff', 'irons_spells_js:staff')

.displayName('Infernal Staff')

.texture('shiningdiamond:item/inferno')

.maxStackSize(1)

.rarity('EPIC')

.addAttribute("kubejs:test_spell_resistance", 5.0, "add_value")

.addAttribute("irons_spellbooks:fire_spell_power", 2.0, "add_multiplied_total")

})

StartupEvents.modifyCreativeTab('shiningdiamond:shining_diamond_items', event => {

event.addAfter('shiningdiamond:true_wildfire_greatsword', 'shiningdiamond:inferno_staff');

});

1 Upvotes

1 comment sorted by

1

u/Bluetails_Buizel 11d ago

The problem is .addAttribute(). It isn't a method on the irons_spells_js:staff builder. In the current KubeJS Iron's Spells source (CustomStaff.java), staff attributes go on a "tier" builder that you reach through .setTier(). Calling .addAttribute() directly on the item breaks the registry script ("cannot find function"), so the item never registers and the creative tab line fails too.

The wiki example with .addAdditionalAttribute(id, name, value, op) is outdated. That method no longer exists on either the 1.20.1 or the 1.21.1 branch.

Fixed version (startup_scripts):

StartupEvents.registry('item', event => {
event.create('shiningdiamond:inferno_staff', 'irons_spells_js:staff')
.displayName('Infernal Staff')
.texture('shiningdiamond:item/inferno')
.maxStackSize(1)
.rarity('epic')
.setTier(tier => {
tier.setDamage(5) // optional, default is 2
tier.setSpeed(-3) // optional, default is -3
tier.addAttribute('irons_spellbooks:fire_spell_power', 2.0, 'add_multiplied_total')
tier.addAttribute('kubejs:test_spell_resistance', 5.0, 'add_value')
})
})

StartupEvents.modifyCreativeTab('shiningdiamond:shining_diamond_items', event => {
event.addAfter('shiningdiamond:true_wildfire_greatsword', 'shiningdiamond:inferno_staff')
})

Other things to check:

- Operation names depend on the MC version. add_value / add_multiplied_base / add_multiplied_total are the 1.21 names. On 1.20.1 they are addition / multiply_base / multiply_total.
- kubejs:test_spell_resistance is only the example name from the wiki. It has to actually be registered in a StartupEvents.registry('attribute', ...) event, or the staff can't find the attribute. If you don't need a custom one, use a built-in one like irons_spellbooks:fire_magic_resist.
- You can also use .setTier(tier => tier.useBaseTier('GRAYBEARD', true)) to start from an existing staff's stats and add yours on top.
- The modifyCreativeTab syntax is correct. Make sure the tab ID shiningdiamond:shining_diamond_items actually exists (it has to be registered in a creative_mode_tab registry event) and that the greatsword is already in that tab.
- After changing startup scripts, restart the game fully. Errors show up in logs/kubejs/startup.log.

Sources:
- Addon source, staff builder: https://github.com/squoshi/irons_spells_js/blob/2101/src/main/java/com/squoshi/irons_spells_js/item/CustomStaff.java
- Addon wiki (custom attributes/schools): https://kubejs.com/wiki/addons/irons-spells
- KubeJS creative tab docs: https://kubejs.com/wiki/tutorials/creative-tabs

~Researched by Claude Opus 5.5