When registering a custom spell, where do you create the in-game reference of the spells variable data? For example, I'd like to display my spell's radius for the player to see (i.e display finalRadius)
event.create('taunt')
.setCastTime(0)
.setCooldownSeconds(5)
.setManaCostPerLevel(20)
.setCastType('instant')
.setSchool('irons_spellbooks:evocation')
.setMinRarity('common')
.setMaxLevel(1)
.setStartSound('minecraft:entity.ravager.roar')
.setAllowLooting(true)
.canBeCraftedBy(player => true)
.needsLearning(false)
.onCast(ctx => {
const player = ctx.entity;
const level = ctx.level;
if (!player || !player.getAttributeValue) {
console.log("Taunt spell cast by non-player or undefined entity.");
return;
}
const exemptEntities = [
"minecraft:item",
"labels:label",
"simplehats:hatdisplay",
"minecraft:armor_stand",
"minecraft:item_frame",
"minecraft:glow_item_frame",
"corpse:corpse",
"irons_spellbooks:spectral_steed",
"irons_spellbooks:summoned_polar_bear",
"irons_spellbooks:summoned_skeleton",
"irons_spellbooks:summoned_zombie",
"irons_spellbooks:summoned_vex",
"irons_spellbooks:summoned_claymore",
"irons_spellbooks:summoned_rapier",
"irons_spellbooks:summoned_sword",
"irons_spellbooks:spectral_hammer"
];
const baseRadius = 6;
const spellPower = player.getAttributeValue("irons_spellbooks:spell_power") || 1;
const evocationSpellPower = player.getAttributeValue("irons_spellbooks:evocation_spell_power") || 1;
const finalRadius = Math.round(baseRadius * spellPower * evocationSpellPower * 10) / 10;
const aabb = AABB.of(
player.x - finalRadius, player.y - finalRadius, player.z - finalRadius,
player.x + finalRadius, player.y + finalRadius, player.z + finalRadius
);
level.getEntitiesWithin(aabb).forEach(entity => {
if (exemptEntities.includes(entity.getType().toString())) return;
if (!entity.nbt.contains("Owner") && !entity.nbt.contains("Trusted") && entity.getType().toString() !== "minecraft:player") {
try {
entity.setTarget(player);
level.spawnParticles('minecraft:angry_villager', true, entity.x, entity.y + entity.eyeHeight + 0.25, entity.z, 0.15, 0.15, 0.15, 3, 0);
} catch (error) {
console.log(`Error changing target of ${entity.getName()}: ${error}`);
}
}
});
});
});