KubeJS Iron's Spells

KubeJS Iron's Spells

651k Downloads

Crash w/ Example Code

Joziah2 opened this issue ยท 2 comments

commented

I attempted to use the mod to create items with Irons Spells factors, but the example code provided on the wiki causes the game to crash on startup.

Crash Log:
crash-2024-12-03_23.05.21-client.txt
Latest Log:
latest.log
Script File:
example.js.txt

Crash does not occur if the script is not in the kubejs folder. Code copied from https://kubejs.com/wiki/addons/irons-spells from the section "Custom Spell Books, Staves, and Magic Swords"

commented

Alright so on further investigation, the crash is caused by not initializing the custom kubejs attribute provided earlier in the example code. This should probably still be adjusted to provide a warning/KubeJS error rather than crashing to desktop, to avoid people being confused.

If you're a user not interested in the additional schools/attributes and want a copy paste test to build from, here's my code altered to just use base mod attributes:

StartupEvents.registry("item", event => {
	// Other item methods also work on these builders. It is recommended to give the spell books the proper Curios item tag for them to work properly.
	// (that being "curios:spellbook")

	//This just creates a basic spell book with nothing special to it. It is given 3 spell slots as defined.
    	event.create("test_spellbook", "irons_spells_js:spellbook")
        	.setMaxSpellSlots(3)

	// You can add attributes to the spell book, including custom attributes.
	// This spell book is given 8 total spell slots and two attributes.
    	event.create("test_attribute_spellbook", "irons_spells_js:spellbook")
        	.setMaxSpellSlots(8)
        	.addDefaultAttribute("irons_spellbooks:fire_spell_power", "Fire Spell Power", 2.0, "multiply_total")
        	.addDefaultAttribute("minecraft:generic.movement_speed", "Test Movement Speed", 1.2, "multiply_total")

	// If you give a spell book default spells, it is converted to a Unique spell book. 
	// This spell book has been given two extra attributes and a single default spell, being Firebolt at level 1.
    	event.create("test_unique_spellbook", "irons_spells_js:spellbook")
        	.setMaxSpellSlots(4)
        	.addDefaultAttribute("irons_spellbooks:fire_spell_power", "Fire Spell Power", 2.0, "multiply_total")
        	.addDefaultAttribute("minecraft:generic.movement_speed", "Test Movement Speed", 1.2, "multiply_total")
        	.addDefaultSpell(SpellRegistry.FIREBOLT_SPELL, 1)

	// You can create custom staves too, and give them additional custom attributes.
	// This staff deals 50 base damage and gives the user 200% more spell power for the school Test, shown in a previous example.
    	event.create("test_staff", "irons_spells_js:staff")
        	.addAdditionalAttribute("irons_spellbooks:fire_spell_power", "Fire Spell Power", 2.0, "multiply_total")
        	.attackDamageBaseline(50)
        	.speedBaseline(-2.4)

	// Along with custom staves, you can also create custom magic swords that come with default spells.
	// This sword deals 100 damage, has 3 attack speed, and has two pre-inscribed spells, being Firebolt and Blood Slash.
    	event.create("test_magic_sword", "irons_spells_js:magic_sword")
        	.addAdditionalAttribute("irons_spellbooks:fire_spell_power", "Fire Spell Power", 2.0, "multiply_total")
        	.attackDamageBaseline(100)
        	.speedBaseline(3)
        	.addDefaultSpell(SpellRegistry.FIREBOLT_SPELL, 1)
        	.addDefaultSpell(SpellRegistry.BLOOD_SLASH_SPELL, 2)

	// Also, you don't need to use a registry object for spells. You can input a string as the spell ID and it works just fine as well. 
    	event.create("test_magic_sword_2", "irons_spells_js:magic_sword")
        	.addAdditionalAttribute("irons_spellbooks:fire_spell_power", "Fire Spell Power", 2.0, "multiply_total")
        	.attackDamageBaseline(100)
        	.speedBaseline(3)
        	.addDefaultSpell("irons_spellbooks:starfall", 1)
        	.addDefaultSpell("irons_spellbooks:planar_sight", 2)
})