Class CastItemUtils

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

public final class CastItemUtils 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 canceled (cast should be blocked)
    • applyCooldownForfeit

      public static void applyCooldownForfeit(net.minecraft.world.entity.player.Player caster, int cooldownTicks)
      Applies cooldown when a cast is canceled/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
    • calculateModifiers

      public static SpellModifiers calculateModifiers(net.minecraft.world.item.ItemStack stack, net.minecraft.world.entity.player.Player player, Spell spell)
      Calculates the spell modifiers provided by the stack for the given spell and player.
      Parameters:
      stack - The ItemStack.
      player - The player casting the spell.
      spell - The spell being cast.
      Returns:
      The calculated spell modifiers.
    • getAccumulatedCastCost

      public static int getAccumulatedCastCost(Spell spell, int castingTick, int totalCost)
      Calculates the accumulated mana cost for a continuous spell based on the casting ticks.
      Parameters:
      spell - The spell being cast
      castingTick - The number of ticks the spell has been cast for
      totalCost - The total mana cost of the spell
      Returns:
      The accumulated mana cost for the given casting ticks
    • getDistributedCastCost

      public static int getDistributedCastCost(int cost, int castingTick)
      Calculates the distributed cost of a spell being cast over multiple ticks. The cost is halved at 10 ticks and again at 20 ticks, with any remainder added to the first half.
      Parameters:
      cost - The total cost of the spell.
      castingTick - The current tick of casting.
      Returns:
      The distributed cost for the current tick.
    • calcCastProgression

      public static int calcCastProgression(Spell spell, SpellModifiers modifiers)
      Calculates the progression of a spell based on its base cost and the given spell modifiers.
      Parameters:
      spell - The spell being cast
      modifiers - The spell modifiers affecting the cast
      Returns:
      The calculated progression
    • calcCastCooldown

      public static int calcCastCooldown(Spell spell, SpellModifiers modifiers)
      Calculates the cooldown of a spell based on its base cooldown and the given spell modifiers.
      Parameters:
      spell - The spell being cast
      modifiers - The spell modifiers affecting the cast
      Returns:
      The calculated cooldown
    • calcCastCost

      public static int calcCastCost(Spell spell, SpellModifiers modifiers)
      Calculates the mana cost of a spell based on its base cost and the given spell modifiers.
      Parameters:
      spell - The spell being cast
      modifiers - The spell modifiers affecting the cast
      Returns:
      The calculated mana cost
    • calcCharge

      public static int calcCharge(Spell spell, SpellModifiers modifiers)
      Calculates the charge time required for a spell based on the spell's base charge and the given spell modifiers.
      Parameters:
      spell - The spell being cast
      modifiers - The spell modifiers affecting the cast
      Returns:
      The calculated charge time