Class CastUtils

java.lang.Object
com.binaris.wizardry.api.content.util.CastUtils

public final class CastUtils extends Object
A utility class for handling various aspects of spell casting, including event firing, cooldown application, spell tracking, and network packet sending. This class is created from WandItem and ScrollItem shared casting logic to avoid code duplication.
  • Method Details

    • fireSpellCastEvent

      public static boolean fireSpellCastEvent(SpellCastEvent.Source source, Spell spell, PlayerCastContext ctx)
      Fires the appropriate spell cast event based on casting ticks.
      Parameters:
      source - The source of the spell cast
      spell - The spell being cast
      ctx - The casting context
      Returns:
      true if the event was cancelled (cast should be blocked)
    • applyCooldownForfeit

      public static void applyCooldownForfeit(net.minecraft.world.entity.player.Player caster, int cooldownTicks)
      Applies cooldown when a cast is cancelled/forfeited.
      Parameters:
      caster - The player casting the spell
      cooldownTicks - The cooldown duration in ticks
    • trackSpellUsage

      public static void trackSpellUsage(net.minecraft.world.entity.player.Player caster, Spell spell)
      Tracks the spell in wizard data for recent spell tracking.
      Parameters:
      caster - The player casting the spell
      spell - The spell being cast
    • executeSpellCast

      public static boolean executeSpellCast(SpellCastEvent.Source source, Spell spell, PlayerCastContext ctx)
      Executes the spell cast and fires post-cast event.
      Parameters:
      source - The source of the spell cast
      spell - The spell being cast
      ctx - The casting context
      Returns:
      true if the spell was successfully cast
    • sendSpellCastPacket

      public static void sendSpellCastPacket(net.minecraft.world.entity.player.Player caster, Spell spell, PlayerCastContext ctx)
      Sends spell cast packet to other clients if needed (for non-instant spells).
      Parameters:
      caster - The player casting the spell
      spell - The spell being cast
      ctx - The casting context