#[ISS / KubeJS] Displaying Variable Data for Custom Spell

9 messages · Page 1 of 1 (latest)

pseudo fern
#

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}`);
          }
        }
      });
    });
});
gentle blazeBOT
#

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

quick harbor
#

Looks like you may need to do a java load class.

quick harbor
#

oh take a look at this video
https://www.youtube.com/watch?v=w0RBoqCtjA0

sry for the video being messy!

in this video I go over on how to change attributes and display data on item within 1.20.1 KubeJS 6.5 on serverside. I show off how to create, set up, and make crafting recipes for custom weapons and items without putting it in Startup or ItemEvents.modification. This is useful for adding custom items to servers

...

▶ Play video
spring temple
#

@shell flicker another ISS ticket for ya

shell flicker
thin geyserBOT
#

[➤](#1258601167550812302 message)

.setUniqueInfo((level, caster) => {
            let spellStrength = caster.getPlayerMagicData().getCastingSpell().getSpell().getSpellPower(level + 1, caster)
            return [Component.of(`Damage: ${spellStrength * 20}`), Component.of(`AoE Damage: ${level}`)]
        })

should have this functional now, now I truely understand why level and caster exist, since you can't get the player in the spell registry

shell flicker
#

should work on 1.21

pseudo fern
#

You are all amazing. This did it. I really appreciate the help!